Removing ModelBehavior::dispatchMethod(), replacing with call_user_func_array() as its faster and the php4 workaround is no longer needed.

This commit is contained in:
mark_story 2010-07-04 01:23:45 -04:00
parent 409b12954b
commit c44c276fa3
2 changed files with 8 additions and 34 deletions

View file

@ -219,7 +219,10 @@ class BehaviorCollection extends ObjectCollection {
}
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');
}
@ -242,8 +245,10 @@ class BehaviorCollection extends ObjectCollection {
$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)))

View file

@ -147,37 +147,6 @@ class ModelBehavior extends Object {
*/
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