mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Removing BehaviorCollection::trigger() so it uses the parent method.
Updating model to use the new behaviorcollection trigger method signature.
This commit is contained in:
parent
81e009b816
commit
a05baaa76e
2 changed files with 20 additions and 50 deletions
|
@ -230,43 +230,6 @@ class BehaviorCollection extends ObjectCollection {
|
|||
return array('unhandled');
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatches a behavior callback on all attached behavior objects
|
||||
*
|
||||
* @param model $model
|
||||
* @param string $callback
|
||||
* @param array $params
|
||||
* @param array $options
|
||||
* @return mixed
|
||||
*/
|
||||
public function trigger(&$model, $callback, $params = array(), $options = array()) {
|
||||
if (empty($this->_enabled)) {
|
||||
return true;
|
||||
}
|
||||
$options = array_merge(
|
||||
array('break' => false, 'breakOn' => array(null, false), 'modParams' => false),
|
||||
$options
|
||||
);
|
||||
foreach ($this->_enabled as $name) {
|
||||
$result = call_user_func_array(
|
||||
array(&$this->_loaded[$name], $callback),
|
||||
array_merge(array(&$model), $params)
|
||||
);
|
||||
if (
|
||||
$options['break'] && ($result === $options['breakOn'] ||
|
||||
(is_array($options['breakOn']) && in_array($result, $options['breakOn'], true)))
|
||||
) {
|
||||
return $result;
|
||||
} elseif ($options['modParams'] && is_array($result)) {
|
||||
$params[0] = $result;
|
||||
}
|
||||
}
|
||||
if ($options['modParams'] && isset($params[0])) {
|
||||
return $params[0];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the method list for attached behaviors, i.e. all public, non-callback methods
|
||||
*
|
||||
|
|
|
@ -1315,7 +1315,7 @@ class Model extends Object {
|
|||
}
|
||||
|
||||
if ($options['callbacks'] === true || $options['callbacks'] === 'before') {
|
||||
$result = $this->Behaviors->trigger($this, 'beforeSave', array($options), array(
|
||||
$result = $this->Behaviors->trigger('beforeSave', array(&$this, $options), array(
|
||||
'break' => true, 'breakOn' => false
|
||||
));
|
||||
if (!$result || !$this->beforeSave($options)) {
|
||||
|
@ -1399,7 +1399,7 @@ class Model extends Object {
|
|||
$success = $this->data;
|
||||
}
|
||||
if ($options['callbacks'] === true || $options['callbacks'] === 'after') {
|
||||
$this->Behaviors->trigger($this, 'afterSave', array($created, $options));
|
||||
$this->Behaviors->trigger('afterSave', array(&$this, $created, $options));
|
||||
$this->afterSave($created);
|
||||
}
|
||||
if (!empty($this->data)) {
|
||||
|
@ -1845,13 +1845,15 @@ class Model extends Object {
|
|||
$id = $this->id;
|
||||
|
||||
if ($this->beforeDelete($cascade)) {
|
||||
$filters = $this->Behaviors->trigger($this, 'beforeDelete', array($cascade), array(
|
||||
'break' => true, 'breakOn' => false
|
||||
));
|
||||
$filters = $this->Behaviors->trigger(
|
||||
'beforeDelete',
|
||||
array(&$this, $cascade),
|
||||
array('break' => true, 'breakOn' => false)
|
||||
);
|
||||
if (!$filters || !$this->exists()) {
|
||||
return false;
|
||||
}
|
||||
$db =& ConnectionManager::getDataSource($this->useDbConfig);
|
||||
$db = ConnectionManager::getDataSource($this->useDbConfig);
|
||||
|
||||
$this->_deleteDependent($id, $cascade);
|
||||
$this->_deleteLinks($id);
|
||||
|
@ -2132,9 +2134,11 @@ class Model extends Object {
|
|||
$query['order'] = array($query['order']);
|
||||
|
||||
if ($query['callbacks'] === true || $query['callbacks'] === 'before') {
|
||||
$return = $this->Behaviors->trigger($this, 'beforeFind', array($query), array(
|
||||
'break' => true, 'breakOn' => false, 'modParams' => true
|
||||
));
|
||||
$return = $this->Behaviors->trigger(
|
||||
'beforeFind',
|
||||
array(&$this, $query),
|
||||
array('break' => true, 'breakOn' => false, 'modParams' => 1)
|
||||
);
|
||||
$query = (is_array($return)) ? $return : $query;
|
||||
|
||||
if ($return === false) {
|
||||
|
@ -2397,7 +2401,11 @@ class Model extends Object {
|
|||
* @access private
|
||||
*/
|
||||
function __filterResults($results, $primary = true) {
|
||||
$return = $this->Behaviors->trigger($this, 'afterFind', array($results, $primary), array('modParams' => true));
|
||||
$return = $this->Behaviors->trigger(
|
||||
'afterFind',
|
||||
array(&$this, $results, $primary),
|
||||
array('modParams' => 1)
|
||||
);
|
||||
if ($return !== true) {
|
||||
$results = $return;
|
||||
}
|
||||
|
@ -2522,9 +2530,8 @@ class Model extends Object {
|
|||
function invalidFields($options = array()) {
|
||||
if (
|
||||
!$this->Behaviors->trigger(
|
||||
$this,
|
||||
'beforeValidate',
|
||||
array($options),
|
||||
array(&$this, $options),
|
||||
array('break' => true, 'breakOn' => false)
|
||||
) ||
|
||||
$this->beforeValidate($options) === false
|
||||
|
|
Loading…
Reference in a new issue