Browse files

Refactored Entity::__call and some code cleanup.

  • Loading branch information...
1 parent b3b5696 commit a8d8e04fcc831b292505ffb35f7067dac824ec1d Tobias Sandelius committed Jan 6, 2012
Showing with 7 additions and 8 deletions.
  1. +5 −7 data/Entity.php
  2. +2 −1 data/Model.php
View
12 data/Entity.php
@@ -190,17 +190,15 @@ public function __isset($name) {
*/
public function __call($method, $params) {
if ($model = $this->_model) {
- $callback = false;
$methods = $model::instanceMethods();
+ array_unshift($params, $this);
+
if (method_exists($model, $method)) {
$class = $model::invokeMethod('_object');
- $callback = array(&$class, $method);
- } elseif (isset($methods[$method]) && is_callable($methods[$method])) {
- $callback = $methods[$method];
+ return call_user_func_array(array(&$class, $method), $params);
}
- if ($callback) {
- array_unshift($params, $this);
- return call_user_func_array($callback, $params);
+ if (isset($methods[$method]) && is_callable($methods[$method])) {
+ return call_user_func_array($methods[$method], $params);
}
}
$message = "No model bound or unhandled method call `{$method}`.";
View
3 data/Model.php
@@ -697,7 +697,8 @@ public static function create(array $data = array(), array $options = array()) {
* {{{
* Model::instanceMethods(array(
* 'method_name' => array('Class', 'method'),
- * 'another_method' => array($object, 'method')
+ * 'another_method' => array($object, 'method'),
+ * 'closure_callback' => function($entity) {}
* ));
* }}}
*

0 comments on commit a8d8e04

Please sign in to comment.