本文整理汇总了PHP中Cake\ORM\Table::dispatchEvent方法的典型用法代码示例。如果您正苦于以下问题:PHP Table::dispatchEvent方法的具体用法?PHP Table::dispatchEvent怎么用?PHP Table::dispatchEvent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\ORM\Table
的用法示例。
在下文中一共展示了Table::dispatchEvent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _prepareDataAndOptions
/**
* Returns data and options prepared to validate and marshall.
*
* @param array $data The data to prepare.
* @param array $options The options passed to this marshaller.
* @return array An array containing prepared data and options.
*/
protected function _prepareDataAndOptions($data, $options)
{
$options += ['validate' => true];
$tableName = $this->_table->alias();
if (isset($data[$tableName])) {
$data = $data[$tableName];
}
$data = new \ArrayObject($data);
$options = new \ArrayObject($options);
$this->_table->dispatchEvent('Model.beforeMarshal', compact('data', 'options'));
return [(array) $data, (array) $options];
}
示例2: _processValidation
/**
* Validates the $entity if the 'validate' key is not set to false in $options
* If not empty it will construct a default validation object or get one with
* the name passed in the key
*
* @param \Cake\ORM\Entity $entity The entity to validate
* @param \ArrayObject $options The option for processing validation
* @return bool true if the entity is valid, false otherwise
*/
protected function _processValidation($entity, $options)
{
$type = is_string($options['validate']) ? $options['validate'] : 'default';
$validator = $this->_table->validator($type);
$pass = compact('entity', 'options', 'validator');
$event = $this->_table->dispatchEvent('Model.beforeValidate', $pass);
if ($event->isStopped()) {
return (bool) $event->result;
}
if (!count($validator)) {
return true;
}
$success = !$entity->validate($validator);
$event = $this->_table->dispatchEvent('Model.afterValidate', $pass);
if ($event->isStopped()) {
$success = (bool) $event->result;
}
return $success;
}
示例3: dispatchEvent
/**
* {@inheritDoc}
*/
public function dispatchEvent($name, $data = null, $subject = null)
{
$data['table'] = $this;
return parent::dispatchEvent($name, $data, $subject);
}