当前位置: 首页>>代码示例>>PHP>>正文


PHP Doctrine_Event::set方法代码示例

本文整理汇总了PHP中Doctrine_Event::set方法的典型用法代码示例。如果您正苦于以下问题:PHP Doctrine_Event::set方法的具体用法?PHP Doctrine_Event::set怎么用?PHP Doctrine_Event::set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine_Event的用法示例。


在下文中一共展示了Doctrine_Event::set方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: hydrateResultSet

 /**
  * hydrateResultSet
  * parses the data returned by statement object
  *
  * This is method defines the core of Doctrine's object population algorithm
  * hence this method strives to be as fast as possible
  *
  * The key idea is the loop over the rowset only once doing all the needed operations
  * within this massive loop.
  *
  * @todo: Detailed documentation. Refactor (too long & nesting level).
  *
  * @param mixed $stmt
  * @param array $tableAliases  Array that maps table aliases (SQL alias => DQL alias)
  * @param array $aliasMap  Array that maps DQL aliases to their components
  *                         (DQL alias => array(
  *                              'table' => Table object,
  *                              'parent' => Parent DQL alias (if any),
  *                              'relation' => Relation object (if any),
  *                              'map' => Custom index to use as the key in the result (if any)
  *                              )
  *                         )
  * @return array
  */
 public function hydrateResultSet($stmt, $tableAliases)
 {
     $hydrationMode = $this->_hydrationMode;
     $this->_tableAliases = $tableAliases;
     if ($hydrationMode == Doctrine::HYDRATE_NONE) {
         return $stmt->fetchAll(PDO::FETCH_NUM);
     }
     if ($hydrationMode == Doctrine::HYDRATE_ARRAY) {
         $driver = new Doctrine_Hydrator_ArrayDriver();
     } else {
         $driver = new Doctrine_Hydrator_RecordDriver();
     }
     // Used variables during hydration
     reset($this->_queryComponents);
     $rootAlias = key($this->_queryComponents);
     $this->_rootAlias = $rootAlias;
     $rootComponentName = $this->_queryComponents[$rootAlias]['table']->getComponentName();
     // if only one component is involved we can make our lives easier
     $isSimpleQuery = count($this->_queryComponents) <= 1;
     // Holds the resulting hydrated data structure
     $result = array();
     // Holds hydration listeners that get called during hydration
     $listeners = array();
     // Lookup map to quickly discover/lookup existing records in the result
     $identifierMap = array();
     // Holds for each component the last previously seen element in the result set
     $prev = array();
     // holds the values of the identifier/primary key fields of components,
     // separated by a pipe '|' and grouped by component alias (r, u, i, ... whatever)
     // the $idTemplate is a prepared template. $id is set to a fresh template when
     // starting to process a row.
     $id = array();
     $idTemplate = array();
     $result = $driver->getElementCollection($rootComponentName);
     if ($stmt === false || $stmt === 0) {
         return $result;
     }
     // Initialize
     foreach ($this->_queryComponents as $dqlAlias => $data) {
         $componentName = $data['table']->getComponentName();
         $listeners[$componentName] = $data['table']->getRecordListener();
         $identifierMap[$dqlAlias] = array();
         $prev[$dqlAlias] = null;
         $idTemplate[$dqlAlias] = '';
     }
     $event = new Doctrine_Event(null, Doctrine_Event::HYDRATE, null);
     // Process result set
     $cache = array();
     while ($data = $stmt->fetch(Doctrine::FETCH_ASSOC)) {
         $id = $idTemplate;
         // initialize the id-memory
         $nonemptyComponents = array();
         $rowData = $this->_gatherRowData($data, $cache, $id, $nonemptyComponents);
         //
         // hydrate the data of the root component from the current row
         //
         $table = $this->_queryComponents[$rootAlias]['table'];
         $componentName = $table->getComponentName();
         // Ticket #1115 (getInvoker() should return the component that has addEventListener)
         $event->setInvoker($table);
         $event->set('data', $rowData[$rootAlias]);
         $listeners[$componentName]->preHydrate($event);
         $index = false;
         // Check for an existing element
         if ($isSimpleQuery || !isset($identifierMap[$rootAlias][$id[$rootAlias]])) {
             $element = $driver->getElement($rowData[$rootAlias], $componentName);
             $event->set('data', $element);
             $listeners[$componentName]->postHydrate($event);
             // do we need to index by a custom field?
             if ($field = $this->_getCustomIndexField($rootAlias)) {
                 if (isset($result[$field])) {
                     throw new Doctrine_Hydrator_Exception("Couldn't hydrate. Found non-unique key mapping named '{$field}'.");
                 } else {
                     if (!isset($element[$field])) {
                         throw new Doctrine_Hydrator_Exception("Couldn't hydrate. Found a non-existent key named '{$field}'.");
                     }
//.........这里部分代码省略.........
开发者ID:googlecode-mirror,项目名称:orso,代码行数:101,代码来源:Hydrator.php

示例2: hydrateResultSet

 /**
  * hydrateResultSet
  * parses the data returned by statement object
  *
  * This is method defines the core of Doctrine's object population algorithm
  * hence this method strives to be as fast as possible
  *
  * The key idea is the loop over the rowset only once doing all the needed operations
  * within this massive loop.
  *
  * @todo: Detailed documentation. Refactor (too long & nesting level).
  *
  * @param mixed $stmt
  * @param array $tableAliases  Array that maps table aliases (SQL alias => DQL alias)
  * @param array $aliasMap  Array that maps DQL aliases to their components
  *                         (DQL alias => array(
  *                              'table' => Table object,
  *                              'parent' => Parent DQL alias (if any),
  *                              'relation' => Relation object (if any),
  *                              'map' => Custom index to use as the key in the result (if any)
  *                              )
  *                         )
  * @return array
  */
 public function hydrateResultSet($stmt, $tableAliases, $hydrationMode = null)
 {
     //$s = microtime(true);
     $this->_tableAliases = $tableAliases;
     if ($hydrationMode == Doctrine::HYDRATE_NONE) {
         return $stmt->fetchAll(PDO::FETCH_NUM);
     }
     if ($hydrationMode === null) {
         $hydrationMode = $this->_hydrationMode;
     }
     if ($hydrationMode === Doctrine::HYDRATE_ARRAY) {
         $driver = new Doctrine_Hydrator_ArrayDriver();
     } else {
         $driver = new Doctrine_Hydrator_RecordDriver();
     }
     $event = new Doctrine_Event(null, Doctrine_Event::HYDRATE, null);
     // Used variables during hydration
     reset($this->_queryComponents);
     $rootAlias = key($this->_queryComponents);
     $rootComponentName = $this->_queryComponents[$rootAlias]['table']->getComponentName();
     // if only one component is involved we can make our lives easier
     $isSimpleQuery = count($this->_queryComponents) <= 1;
     // Holds the resulting hydrated data structure
     $result = array();
     // Holds hydration listeners that get called during hydration
     $listeners = array();
     // Lookup map to quickly discover/lookup existing records in the result
     $identifierMap = array();
     // Holds for each component the last previously seen element in the result set
     $prev = array();
     // holds the values of the identifier/primary key fields of components,
     // separated by a pipe '|' and grouped by component alias (r, u, i, ... whatever)
     $id = array();
     $result = $driver->getElementCollection($rootComponentName);
     if ($stmt === false || $stmt === 0) {
         return $result;
     }
     // Initialize
     foreach ($this->_queryComponents as $dqlAlias => $data) {
         $componentName = $data['table']->getComponentName();
         $listeners[$componentName] = $data['table']->getRecordListener();
         $identifierMap[$dqlAlias] = array();
         $prev[$dqlAlias] = array();
         $id[$dqlAlias] = '';
     }
     // Process result set
     $cache = array();
     while ($data = $stmt->fetch(Doctrine::FETCH_ASSOC)) {
         $nonemptyComponents = array();
         $rowData = $this->_gatherRowData($data, $cache, $id, $nonemptyComponents);
         //
         // hydrate the data of the root component from the current row
         //
         $table = $this->_queryComponents[$rootAlias]['table'];
         $componentName = $table->getComponentName();
         $event->set('data', $rowData[$rootAlias]);
         $listeners[$componentName]->preHydrate($event);
         $element = $driver->getElement($rowData[$rootAlias], $componentName);
         $index = false;
         // Check for an existing element
         if ($isSimpleQuery || !isset($identifierMap[$rootAlias][$id[$rootAlias]])) {
             $event->set('data', $element);
             $listeners[$componentName]->postHydrate($event);
             // do we need to index by a custom field?
             if ($field = $this->_getCustomIndexField($rootAlias)) {
                 if (isset($result[$field])) {
                     throw new Doctrine_Hydrator_Exception("Couldn't hydrate. Found non-unique key mapping.");
                 } else {
                     if (!isset($element[$field])) {
                         throw new Doctrine_Hydrator_Exception("Couldn't hydrate. Found a non-existent key.");
                     }
                 }
                 $result[$element[$field]] = $element;
             } else {
                 $result[] = $element;
             }
//.........这里部分代码省略.........
开发者ID:kirvin,项目名称:the-nerdery,代码行数:101,代码来源:Hydrator.php


注:本文中的Doctrine_Event::set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。