Skip to content
Permalink
Browse files

Adding magic __call() methods in order to call finders directly and

stack them
  • Loading branch information...
lorenzo committed Aug 20, 2013
1 parent 1ae0413 commit 16020a462fc49b38990539e1f1b450ff997999d1
@@ -776,4 +776,17 @@ protected function _addDefaultFields() {
$this->select($aliased, true);
}
/**
* Magic method to be able to call scoped finders in the default table
*
* @param string $method name of the method to be invoked
* @param array $args List of arguments passed to the function
* @return mixed
* @throws \BadMethodCallException
*/
public function __call($method, $args) {
array_unshift($args, $this);
return $this->repository()->__call($method, $args);
}
}
@@ -660,4 +660,26 @@ public function deleteAll($conditions) {
return $statement->rowCount() > 0;
}
/**
* Magic method to be able to call scoped finders without the
* find prefix
*
* @param string $method name of the method to be invoked
* @param array $args List of arguments passed to the function
* @return mixed
* @throws \BadMethodCallException
*/
public function __call($method, $args) {
if (method_exists($this, 'find' . ucfirst($method))) {
if (current($args) instanceof Query) {
$query = array_shift($args);
$options = current($args) ?: [];
return $this->{'find' . ucfirst($method)}($query, $options);
}
$options = current($args) ?: [];
return $this->find($method, $options);
}
throw new \BadMethodCallException('Unknown table method ' . $method);
}
}
@@ -1003,4 +1003,5 @@ function($k, $v, $mr) { $mr->emit($v[0] + 1); }
$this->assertEquals([2, 3], iterator_to_array($query->execute()));
}
}
Oops, something went wrong.

0 comments on commit 16020a4

Please sign in to comment.
You can’t perform that action at this time.