/** * Returns the total number of rows in the result set. * * @return int */ public function count() { if (!$this->totalCount) { $this->totalCount = $this->handle->countTotal(); } return $this->totalCount; }
/** * Prepara uma query a partir de um arquivo .sql que deve ficar na pasta * Model/SqlResources/ que é relativa ao caminho do gateway. * * @param string $filename * @param array $params * @return Handle */ public function fileQuery($filename, array $params = array()) { // Primeiro descobrir onde estao os arquivos SQL // Reflexiona a entidade para pegar os arquivos SQL relativos a este diretorio $ref = new ReflectionClass(get_class($this)); $entityDirname = dirname($ref->getFileName()); // Prefixo do arquivo sql $parts = explode("\\", get_class($this->entity)); $prefixFile = strtolower(array_pop($parts)); // Caminho para os arquivos Sql $filepath = preg_replace("/\\/Gateway/", "", $entityDirname) . "/SqlResources/"; // Define e valida arquivo $file = $filepath . $prefixFile . DIRECTORY_SEPARATOR . $filename . '.sql'; if (!file_exists($file)) { throw new \Exception("Arquivo (" . $file . ") com a query não existe"); } /** * O arquivo vai ser procurado sempre em "Model/SqlResources/{nome minusculo da entidade}/$filename" */ $file = file_get_contents($file); $handle = new SqlFileHandle($file); $handle->setParams($params); $handle->setArrayObjectPrototype($this->entity); // Retorna instancia de manipulador de query return $handle; }