Doctrine\ORM\EntityManager::newHydrator PHP Method

newHydrator() public method

Create a new instance for the given hydration mode.
public newHydrator ( integer $hydrationMode ) : Doctrine\ORM\Internal\Hydration\AbstractHydrator
$hydrationMode integer
return Doctrine\ORM\Internal\Hydration\AbstractHydrator
    public function newHydrator($hydrationMode)
    {
        switch ($hydrationMode) {
            case Query::HYDRATE_OBJECT:
                $hydrator = new Internal\Hydration\ObjectHydrator($this);
                break;
            case Query::HYDRATE_ARRAY:
                $hydrator = new Internal\Hydration\ArrayHydrator($this);
                break;
            case Query::HYDRATE_SCALAR:
                $hydrator = new Internal\Hydration\ScalarHydrator($this);
                break;
            case Query::HYDRATE_SINGLE_SCALAR:
                $hydrator = new Internal\Hydration\SingleScalarHydrator($this);
                break;
            default:
                if ($class = $this->config->getCustomHydrationMode($hydrationMode)) {
                    $hydrator = new $class($this);
                    break;
                }
                throw ORMException::invalidHydrationMode($hydrationMode);
        }

        return $hydrator;
    }

Usage Example

コード例 #1
0
ファイル: AbstractQuery.php プロジェクト: Dren-x/mobit
 /**
  * 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->newHydrator($this->_hydrationMode)->hydrateAll($stmt, $this->_resultSetMapping, $this->_hints);
     $setCacheEntry($data);
     return $data;
 }
All Usage Examples Of Doctrine\ORM\EntityManager::newHydrator