mapper() public method

Get current adapter object
public mapper ( ) : Mapper
return Mapper
Beispiel #1
0
 /**
  * {@inheritDoc}
  */
 public function read(Query $query)
 {
     $builder = $query->builder();
     $queryHash = md5($builder->getSql() . '_' . serialize($builder->getParameters()));
     if ($this->mapper instanceof MapperCacheInterface) {
         if ($builder->getType() == 0) {
             $collection = $this->mapper->getQueryFromCache($queryHash);
             if ($collection) {
                 return $collection;
             }
         } else {
             $this->mapper->clearQueryCache();
         }
     }
     /*
     if ($query->builder()->getType() == 0) {
         $clonedQuery = clone $query->builder();
     
         $res = $clonedQuery->getConnection()->executeQuery('EXPLAIN ' . $clonedQuery->getSQL(), $clonedQuery->getParameters(), $clonedQuery->getParameterTypes());
         $res->setFetchMode(\PDO::FETCH_ASSOC);
     
         echo '<pre>';
         var_dump($queryHash);
         var_dump($clonedQuery->getSQL());
         var_dump($clonedQuery->getParameters());
         var_dump($res->fetchAll());
         echo '</pre>';
     }
     */
     $stmt = $builder->execute();
     $stmt->setFetchMode(\PDO::FETCH_ASSOC);
     $collection = $query->mapper()->collection($stmt, $query->with());
     $stmt->closeCursor();
     if ($this->mapper instanceof MapperCacheInterface && $builder->getType() == 0) {
         $this->mapper->addQueryToCache($queryHash, $collection);
     }
     return $collection;
 }
Beispiel #2
0
 /**
  * Return result set for current query
  */
 public function toCollection(\Spot\Query $query, $stmt)
 {
     $mapper = $query->mapper();
     $entityClass = $query->entityName();
     if ($stmt instanceof \PDOStatement) {
         // Set PDO fetch mode
         $stmt->setFetchMode(\PDO::FETCH_ASSOC);
         $collection = $mapper->collection($entityClass, $stmt, $query->with());
         // Ensure statement is closed
         $stmt->closeCursor();
         return $collection;
     } else {
         $mapper->addError(__METHOD__ . " - Unable to execute query " . implode(' | ', $this->connection()->errorInfo()));
         return array();
     }
 }
Beispiel #3
0
 /**
  * Find records with custom SQL query
  *
  * @param \Spot\Query $query SQL query to execute
  * @return \Spot\Entity\Collection
  * @throws \Spot\Exception
  */
 public function read(Query $query)
 {
     $stmt = $query->builder()->execute();
     // Set PDO fetch mode
     $stmt->setFetchMode(\PDO::FETCH_ASSOC);
     $collection = $query->mapper()->collection($stmt, $query->with());
     // Ensure statement is closed
     $stmt->closeCursor();
     return $collection;
 }
Beispiel #4
0
 /**
  * Return result set for current query
  */
 public function toCollection(\Spot\Query $query, \MongoCursor $cursor)
 {
     $mapper = $query->mapper();
     $entityClass = $query->entityName();
     if ($cursor instanceof MongoCursor) {
         // Set timeout
         if (isset($this->options['cursor']['timeout']) && is_int($this->options['cursor']['timeout'])) {
             $cursor->timeout($this->options['cursor']['timeout']);
         }
         return $mapper->collection($entityClass, $cursor);
     } else {
         $mapper->addError(__METHOD__ . " - Unable to execute query - not a valid MongoCursor");
         return array();
     }
 }