lithium\data\Model::_finders()

protected static method

Returns an array with the default finders.

Returns

array

Source

	protected static function _finders() {
		$self = static::object();

		return [
			'all' => function($params, $next) {
				return $next($params);
			},
			'first' => function($params, $next) {
				$options =& $params['options'];
				$options['limit'] = 1;

				$data = $next($params);

				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($params, $next) use ($self) {
				$result = [];
				$meta = $self::meta();
				$name = $meta['key'];

				foreach ($next($params) as $entity) {
					$key = $entity->{$name};
					$result[is_scalar($key) ? $key : (string) $key] = $entity->title();
				}
				return $result;
			},
			'count' => function($params, $next) use ($self) {
				$options = array_diff_key($params['options'], $self->_query);

				if ($options && !isset($params['options']['conditions'])) {
					$options = ['conditions' => $options];
				} else {
					$options = $params['options'];
				}
				$options += ['type' => 'read', 'model' => $self];
				$query = Libraries::instance(null, 'query', $options, $self->_classes);
				return $self::connection()->calculation('count', $query, $options);
			}
		];
	}