lithium\data\Model::_finders PHP Method

_finders() protected static method

Returns an array with the default finders.
See also: lithium\data\Model::_initialize()
protected static _finders ( ) : array
return array
    protected static function _finders()
    {
        $_query = static::_object()->_query;
        return array('all' => function ($self, $params, $chain) {
            return $chain->next($self, $params, $chain);
        }, 'first' => function ($self, $params, $chain) {
            $options =& $params['options'];
            $options['limit'] = 1;
            $data = $chain->next($self, $params, $chain);
            if (isset($options['return']) && $options['return'] === 'array') {
                $data = is_array($data) ? reset($data) : $data;
            } else {
                $data = is_object($data) ? $data->rewind() : $data;
            }
            return $data ?: null;
        }, 'list' => function ($self, $params, $chain) {
            $result = array();
            $meta = $self::meta();
            $name = $meta['key'];
            foreach ($chain->next($self, $params, $chain) as $entity) {
                $key = $entity->{$name};
                $result[is_scalar($key) ? $key : (string) $key] = $entity->title();
            }
            return $result;
        }, 'count' => function ($self, $params, $chain) use($_query) {
            $options = array_diff_key($params['options'], $_query);
            if ($options && !isset($params['options']['conditions'])) {
                $options = array('conditions' => $options);
            } else {
                $options = $params['options'];
            }
            $options += array('type' => 'read', 'model' => $self);
            $query = $self::invokeMethod('_instance', array('query', $options));
            return $self::connection()->calculation('count', $query, $options);
        });
    }