Skip to content

Commit

Permalink
Removing BehaviorCollection::trigger() so it uses the parent method.
Browse files Browse the repository at this point in the history
Updating model to use the new behaviorcollection trigger method signature.
  • Loading branch information
markstory committed Dec 12, 2010
1 parent 81e009b commit a05baaa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 50 deletions.
39 changes: 1 addition & 38 deletions cake/libs/model/behavior_collection.php
Expand Up @@ -230,43 +230,6 @@ public function dispatchMethod(&$model, $method, $params = array(), $strict = fa
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
*
Expand All @@ -276,4 +239,4 @@ public function methods() {
return $this->__methods;
}

}
}
31 changes: 19 additions & 12 deletions cake/libs/model/model.php
Expand Up @@ -1315,7 +1315,7 @@ function save($data = null, $validate = true, $fieldList = array()) {
}

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)) {
Expand Down Expand Up @@ -1399,7 +1399,7 @@ function save($data = null, $validate = true, $fieldList = array()) {
$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)) {
Expand Down Expand Up @@ -1845,13 +1845,15 @@ function delete($id = null, $cascade = true) {
$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);
Expand Down Expand Up @@ -2132,9 +2134,11 @@ function find($conditions = null, $fields = array(), $order = null, $recursive =
$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) {
Expand Down Expand Up @@ -2397,7 +2401,11 @@ protected function _findThreaded($state, $query, $results = array()) {
* @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;
}
Expand Down Expand Up @@ -2522,9 +2530,8 @@ function validates($options = array()) {
function invalidFields($options = array()) {
if (
!$this->Behaviors->trigger(
$this,
'beforeValidate',
array($options),
array(&$this, $options),
array('break' => true, 'breakOn' => false)
) ||
$this->beforeValidate($options) === false
Expand Down

0 comments on commit a05baaa

Please sign in to comment.