public function dispatch($method, $params)
{
// find() and all() are aliases
if ($method == 'find' && empty($params) || $method == 'all') {
return $this->find();
} else {
if (($method == 'find' || $method == 'one') && is_string($params[0])) {
$rs = $this->find(new Criteria(array_shift($params), $params));
return $method == 'one' ? $rs->one() : $rs;
} else {
if (preg_match('/^(findBy|oneBy)/', $method)) {
$rs = $this->find(new Criteria($this->_sqlFromMethod($method), $params));
return preg_match('/^(oneBy)/', $method) ? $rs->one() : $rs;
} else {
if ($method == 'byId') {
return $this->_findById($params);
} else {
if (isset($params[0]) && $params[0] instanceof Criteria) {
return $this->find($params[0]);
} else {
throw new \BadMethodCallException("Unable to dispatch '{$method}' to finder");
}
}
}
}
}
}