lithium\data\Model::__callStatic PHP Method

__callStatic() public static method

Retrieves post with id 23 using the 'first' finder. Posts::first(array('conditions' => array('id' => 23))); Posts::findById(23); Posts::findById(23); All posts that have a trueish is_published field. Posts::all(array('conditions' => array('is_published' => true))); Posts::findAll(array('conditions' => array('is_published' => true))); Posts::findAllByIsPublshed(true) Counts all posts. Posts::count()
See also: lithium\data\Model::find()
See also: lithium\data\Model::$_meta
public static __callStatic ( string $method, array $params ) : mixed
$method string Method name caught by `__callStatic()`.
$params array Arguments given to the above `$method` call.
return mixed Results of dispatched `Model::find()` call.
    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);
    }

Usage Example

 /**
  * Catches all context method calls and, if it's proper to call,
  * starts the API request process. Otherwise invokes the method.
  *
  * @access public
  * @param string $method
  * @param array $params
  * @return mixed
  */
 public static function __callStatic($method, $params)
 {
     switch ($method) {
         case 'authenticate':
         case 'ping':
         case 'send':
         case 'query':
         case 'startbatch':
         case 'senditem':
         case 'quicksend':
         case 'endbatch':
         case 'send_bulk':
             $self = static::_object();
             $conn = $self::connection();
             return $conn->invokeMethod($method, $params);
             // forward
             break;
     }
     return parent::__callStatic($method, $params);
     // ignore
 }