Doctrine\ORM\EntityManager::getHydrator PHP Method

getHydrator() public method

This method caches the hydrator instances which is used for all queries that don't selectively iterate over the result.
public getHydrator ( integer $hydrationMode ) : Doctrine\ORM\Internal\Hydration\AbstractHydrator
$hydrationMode integer
return Doctrine\ORM\Internal\Hydration\AbstractHydrator
    public function getHydrator($hydrationMode)
    {
        if ( ! isset($this->hydrators[$hydrationMode])) {
            $this->hydrators[$hydrationMode] = $this->newHydrator($hydrationMode);
        }

        return $this->hydrators[$hydrationMode];
    }

Usage Example

コード例 #1
0
ファイル: AbstractQuery.php プロジェクト: nemekzg/doctrine2
 /**
  * Executes the query.
  *
  * @param ArrayCollection|array|null $parameters Query parameters.
  * @param integer|null               $hydrationMode Processing mode to be used during the hydration process.
  *
  * @return mixed
  */
 public function execute($parameters = null, $hydrationMode = null)
 {
     if ($hydrationMode !== null) {
         $this->setHydrationMode($hydrationMode);
     }
     if (!empty($parameters)) {
         $this->setParameters($parameters);
     }
     $setCacheEntry = function () {
     };
     if ($this->_hydrationCacheProfile !== null) {
         list($cacheKey, $realCacheKey) = $this->getHydrationCacheId();
         $queryCacheProfile = $this->getHydrationCacheProfile();
         $cache = $queryCacheProfile->getResultCacheDriver();
         $result = $cache->fetch($cacheKey);
         if (isset($result[$realCacheKey])) {
             return $result[$realCacheKey];
         }
         if (!$result) {
             $result = array();
         }
         $setCacheEntry = function ($data) use($cache, $result, $cacheKey, $realCacheKey, $queryCacheProfile) {
             $result[$realCacheKey] = $data;
             $cache->save($cacheKey, $result, $queryCacheProfile->getLifetime());
         };
     }
     $stmt = $this->_doExecute();
     if (is_numeric($stmt)) {
         $setCacheEntry($stmt);
         return $stmt;
     }
     $data = $this->_em->getHydrator($this->_hydrationMode)->hydrateAll($stmt, $this->_resultSetMapping, $this->_hints);
     $setCacheEntry($data);
     return $data;
 }
All Usage Examples Of Doctrine\ORM\EntityManager::getHydrator