Skip to content

Commit

Permalink
Removing ModelBehavior::dispatchMethod(), replacing with call_user_fu…
Browse files Browse the repository at this point in the history
…nc_array() as its faster and the php4 workaround is no longer needed.
  • Loading branch information
markstory committed Aug 11, 2010
1 parent 409b129 commit c44c276
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 34 deletions.
11 changes: 8 additions & 3 deletions cake/libs/model/behavior_collection.php
Expand Up @@ -219,7 +219,10 @@ public function dispatchMethod(&$model, $method, $params = array(), $strict = fa
}

if (!empty($call)) {
return $this->_loaded[$call[1]]->dispatchMethod($model, $call[0], $params);
return call_user_func_array(
array(&$this->_loaded[$call[1]], $call[0]),
array_merge(array(&$model), $params)
);
}
return array('unhandled');
}
Expand All @@ -242,8 +245,10 @@ public function trigger(&$model, $callback, $params = array(), $options = array(
$options
);
foreach ($this->_enabled as $name) {
$result = $this->_loaded[$name]->dispatchMethod($model, $callback, $params);

$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)))
Expand Down
31 changes: 0 additions & 31 deletions cake/libs/model/model_behavior.php
Expand Up @@ -147,37 +147,6 @@ public function afterDelete(&$model) { }
*/
public function onError(&$model, $error) { }

/**
* Overrides Object::dispatchMethod to account for PHP4's broken reference support
*
* @see Object::dispatchMethod
* @access public
* @return mixed
*/
function dispatchMethod(&$model, $method, $params = array()) {
if (empty($params)) {
return $this->{$method}($model);
}
$params = array_values($params);

switch (count($params)) {
case 1:
return $this->{$method}($model, $params[0]);
case 2:
return $this->{$method}($model, $params[0], $params[1]);
case 3:
return $this->{$method}($model, $params[0], $params[1], $params[2]);
case 4:
return $this->{$method}($model, $params[0], $params[1], $params[2], $params[3]);
case 5:
return $this->{$method}($model, $params[0], $params[1], $params[2], $params[3], $params[4]);
default:
$params = array_merge(array(&$model), $params);
return call_user_func_array(array(&$this, $method), $params);
break;
}
}

/**
* If $model's whitelist property is non-empty, $field will be added to it.
* Note: this method should *only* be used in beforeValidate or beforeSave to ensure
Expand Down

0 comments on commit c44c276

Please sign in to comment.