本文整理汇总了PHP中Doctrine_Event::setInvoker方法的典型用法代码示例。如果您正苦于以下问题:PHP Doctrine_Event::setInvoker方法的具体用法?PHP Doctrine_Event::setInvoker怎么用?PHP Doctrine_Event::setInvoker使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine_Event
的用法示例。
在下文中一共展示了Doctrine_Event::setInvoker方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: preSave
public function preSave(Doctrine_Event $event)
{
$this->logger->debug('In preSave');
$data = $event->getInvoker();
if (isset($data[$this->fieldName])) {
$val = $data[$this->fieldName];
$this->logger->debug($this->fieldName . ' (Before) : ' . $val);
$enc = $this->encrypt($val, $this->key);
$data[$this->fieldName] = $enc;
$event->setInvoker($data);
$this->logger->debug('After: ' . $data[$this->fieldName]);
}
$this->logger->debug('End of preSave');
}
示例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 = $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}'.");
}
//.........这里部分代码省略.........