private function generateFinder(Finder $finder, Entity $entity) { $orderByClause = $finder->hasOrder() ? $finder->getOrderByClause() : $entity->getOrderByClause(); $result = "\tpublic function {$finder->getMethodSignature()} {\n" . "\t\t\$limitStr = (\$from == -1 && \$limit == -1) ? \"\" : \" LIMIT \$from,\$limit\";\n" . "\t\t\$whereClause = \"" . implode(" AND ", $finder->getWhereClauses()) . $orderByClause . "\".\$limitStr;\n"; if ($finder->isCacheable()) { $result .= "\t\tif(parent::\$dbCache->hasFinder('{$entity->getName()}', \$whereClause)) {\n" . "\t\t\treturn parent::\$dbCache->getFinder('{$entity->getName()}', \$whereClause);\n" . "\t\t}\n"; } $result .= "\t\t\$result = \$this->db->selectQuery(\"SELECT * FROM \".self::TABLE.\" WHERE \$whereClause\");\n"; if ($finder->isUnique()) { $result .= "\t\tif(\$result->isEmpty()) {\n" . "\t\t\tthrow new NoSuch{$entity->getName()}Exception();\n" . "\t\t}\n" . "\t\t\$result = \$this->getAsObject(\$result->getSingleRow());\n"; } else { $result .= "\t\t\$result = \$this->getAsObjects(\$result->getResult());\n"; } if ($finder->isCacheable()) { $result .= "\t\tparent::\$dbCache->setFinder('{$entity->getName()}', \$whereClause, \$result);\n"; } return $result . "\t\treturn \$result;\n\t}\n\n"; }