public static function __callStatic($method, $params)
{
$self = static::_object();
if (isset($self->_finders[$method])) {
if (count($params) === 2 && is_array($params[1])) {
$params = array($params[1] + array($method => $params[0]));
}
if ($params && !is_array($params[0])) {
$params[0] = array('conditions' => static::key($params[0]));
}
return $self::find($method, $params ? $params[0] : array());
}
preg_match('/^findBy(?P<field>\\w+)$|^find(?P<type>\\w+)By(?P<fields>\\w+)$/', $method, $args);
if (!$args) {
$message = "Method `%s` not defined or handled in class `%s`.";
throw new BadMethodCallException(sprintf($message, $method, get_class($self)));
}
$field = Inflector::underscore($args['field'] ? $args['field'] : $args['fields']);
$type = isset($args['type']) ? $args['type'] : 'first';
$type[0] = strtolower($type[0]);
$conditions = array($field => array_shift($params));
$params = isset($params[0]) && count($params) === 1 ? $params[0] : $params;
return $self::find($type, compact('conditions') + $params);
}