PHP Класс lithium\data\Collection

Наследование: extends lithium\util\Collection
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$_autoConfig array Holds an array of values that should be processed on initialization.
$_exists boolean Indicates whether this array was part of a document loaded from a data source, or is part of a new document, or is in newly-added field of an existing document.
$_handlers array Hold the "data export" handlers where the keys are fully-namespaced class names, and the values are closures that take an instance of the class as a parameter, and return an array or scalar value that the instance represents.
$_model string The fully-namespaced class name of the model object to which this entity set is bound. This is usually the model that executed the query which created this object.
$_parent object A reference to this object's parent Document object.
$_pathKey string If this Collection instance has a parent document (see $_parent), this value indicates the key name of the parent document that contains it.
$_query object A reference to the query object that originated this entity set; usually an instance of lithium\data\model\Query.
$_result resource | object A pointer or resource that is used to load entities from the backend data source that originated this collection.
$_schema lithium\data\Schema If the Collection has a schema object assigned (rather than loading one from a model), it will be assigned here.
$_started boolean Set to true when the collection has begun iterating.
$_stats array Contains an array of backend-specific statistics generated by the query that produced this Collection object. These stats are accessible via the stats() method.
$_valid boolean Indicates whether the current position is valid or not. This overrides the default value of the parent class.

Открытые методы

Метод Описание
__construct ( array $config = [] ) : void Constructor.
__destruct ( ) : void Destructor. Ensures that the data set's connection is closed when the object is destroyed.
assignTo ( object $parent, array $config = [] ) : void Configures protected properties of a Collection so that it is parented to $parent.
close ( ) Executes when the associated result resource pointer reaches the end of its data set. The resource is freed by the connection, and the reference to the connection is unlinked.
closed ( ) : boolean Checks to see if this entity has already fetched all available entities and freed the associated result resource.
current ( ) : object | boolean Returns the currently pointed to record in the set.
data ( ) : array Converts the current state of the data structure to an array.
each ( callback $filter ) : object Applies a callback to all data in the collection.
exists ( ) : boolean A flag indicating whether or not the items of this collection exists.
find ( mixed $filter, array $options = [] ) : mixed Overrides parent find() implementation to enable key/value-based filtering of entity objects contained in this collection.
first ( mixed $filter = null ) : object Overrides parent first() implementation to enable key/value-based filtering.
key ( boolean $full = false ) : mixed Returns the currently pointed to record's unique key.
keys ( ) : array Returns the item keys.
map ( callback $filter, array $options = [] ) : object Applies a callback to a copy of all data in the collection and returns the result.
meta ( ) : array Returns meta information for this Collection.
model ( ) : string Returns the model which this particular collection is based off of.
next ( ) : mixed Returns the next document in the set, and advances the object's internal pointer. If the end of the set is reached, a new document will be fetched from the data source connection handle If no more documents can be fetched, returns null.
offsetExists ( string $offset ) : boolean Returns a boolean indicating whether an offset exists for the current Collection.
offsetGet ( mixed $offset ) : mixed Gets an Entity object using PHP's array syntax, i.e. $documents[3] or $records[5].
offsetSet ( string $offset, mixed $data ) : mixed Adds the specified object to the Collection instance, and assigns associated metadata to the added object.
offsetUnset ( integer $offset ) Unsets an offset.
parent ( ) : object Returns the object's parent Document object.
reduce ( callback $filter, mixed $initial = false ) : mixed Reduce, or fold, a collection down to a single value
result ( ) : object Return's the pointer or resource that is used to load entities from the backend data source that originated this collection. This is useful in many cases for additional methods related to debugging queries.
rewind ( ) Rewinds the collection to the beginning.
schema ( $field = null )
serialize ( ) : string Prepares, enables and executes serialization of the object.
set ( arary $values ) : void Allows several items to be assigned at once.
sort ( string | callable $field = 'id', array $options = [] ) : lithium\data\Collection Sorts the objects in the collection, useful in situations where you are already using the underlying datastore to sort results.
stats ( string $name = null ) : mixed Gets the stat or stats associated with this Collection.
to ( string $format, array $options = [] ) : mixed Converts a Collection object to another type of object, or a simple type such as an array.
unserialize ( string $data ) : void Prepares, enables and executes unserialization of the object.
valid ( ) : boolean Checks if current position is valid.

Защищенные методы

Метод Описание
_filterFromArray ( array $filter ) : Closure Creates a filter based on an array of key/value pairs that must match the items in a Collection.
_init ( )
_populate ( ) : mixed A method to be implemented by concrete Collection classes which, provided a reference to a backend data source, and a resource representing a query result cursor, fetches new result data and wraps it in the appropriate object type, which is added into the Collection and returned.
_set ( mixed $data = null, mixed $offset = null, array $options = [] ) : object A method to be implemented by concrete Collection classes which sets data to a specified offset and wraps all data array in its appropriate object type.

Описание методов

__construct() публичный Метод

Constructor.
См. также: lithium\data\Collection::$_data
См. также: lithium\data\Collection::$_model
public __construct ( array $config = [] ) : void
$config array Available configuration options are: - `'data'` _array_ - `'model'` _string|null_
Результат void

__destruct() публичный Метод

Destructor. Ensures that the data set's connection is closed when the object is destroyed.
public __destruct ( ) : void
Результат void

_filterFromArray() защищенный Метод

Creates a filter based on an array of key/value pairs that must match the items in a Collection.
protected _filterFromArray ( array $filter ) : Closure
$filter array An array of key/value pairs used to filter `Collection` items.
Результат Closure Returns a closure that wraps the array and attempts to match each value against `Collection` item properties.

_init() защищенный Метод

protected _init ( )

_populate() абстрактный защищенный Метод

A method to be implemented by concrete Collection classes which, provided a reference to a backend data source, and a resource representing a query result cursor, fetches new result data and wraps it in the appropriate object type, which is added into the Collection and returned.
abstract protected _populate ( ) : mixed
Результат mixed Returns the next `Record`, `Document` object or other `Entity` object if exists. Returns `null` otherwise.

_set() абстрактный защищенный Метод

A method to be implemented by concrete Collection classes which sets data to a specified offset and wraps all data array in its appropriate object type.
См. также: lithium\data\Collection::_populate()
См. также: lithium\data\Collection::offsetSet()
abstract protected _set ( mixed $data = null, mixed $offset = null, array $options = [] ) : object
$data mixed An array or an `Entity` object to set.
$offset mixed The offset. If offset is `null` data is simply appended to the set.
$options array Any additional options to pass to the `Entity`'s constructor.
Результат object Returns the inserted `Record`, `Document` object or other `Entity` object.

assignTo() публичный Метод

Configures protected properties of a Collection so that it is parented to $parent.
public assignTo ( object $parent, array $config = [] ) : void
$parent object
$config array
Результат void

close() публичный Метод

Executes when the associated result resource pointer reaches the end of its data set. The resource is freed by the connection, and the reference to the connection is unlinked.
public close ( )

closed() публичный Метод

Checks to see if this entity has already fetched all available entities and freed the associated result resource.
public closed ( ) : boolean
Результат boolean Returns true if all entities are loaded and the database resources have been freed, otherwise returns false.

current() публичный Метод

Returns the currently pointed to record in the set.
public current ( ) : object | boolean
Результат object | boolean An instance of `Record` or `false` if there is no current valid one.

data() публичный Метод

Converts the current state of the data structure to an array.
public data ( ) : array
Результат array Returns the array value of the data in this `Collection`.

each() публичный Метод

Overridden to load any data that has not yet been loaded.
public each ( callback $filter ) : object
$filter callback The filter to apply.
Результат object This collection instance.

exists() публичный Метод

A flag indicating whether or not the items of this collection exists.
public exists ( ) : boolean
Результат boolean `True` if exists, `false` otherwise.

find() публичный Метод

Overrides parent find() implementation to enable key/value-based filtering of entity objects contained in this collection.
public find ( mixed $filter, array $options = [] ) : mixed
$filter mixed Callback to use for filtering, or array of key/value pairs which entity properties will be matched against.
$options array Options to modify the behavior of this method. See the documentation for the `$options` parameter of `lithium\util\Collection::find()`.
Результат mixed The filtered items. Will be an array unless `'collect'` is defined in the `$options` argument, then an instance of this class will be returned.

first() публичный Метод

Overrides parent first() implementation to enable key/value-based filtering.
public first ( mixed $filter = null ) : object
$filter mixed In addition to a callback (see parent), can also be an array where the keys and values must match the property values of the objects being inspected.
Результат object Returns the first object found matching the filter criteria.

key() публичный Метод

Returns the currently pointed to record's unique key.
public key ( boolean $full = false ) : mixed
$full boolean If true, returns the complete key.
Результат mixed

keys() публичный Метод

Returns the item keys.
public keys ( ) : array
Результат array The keys of the items.

map() публичный Метод

Overriden to load any data that has not yet been loaded.
public map ( callback $filter, array $options = [] ) : object
$filter callback The filter to apply.
$options array The available options are: - `'collect'`: If `true`, the results will be returned wrapped in a new `Collection` object or subclass.
Результат object The filtered data.

meta() публичный Метод

Returns meta information for this Collection.
public meta ( ) : array
Результат array

model() публичный Метод

Returns the model which this particular collection is based off of.
public model ( ) : string
Результат string The fully qualified model class name.

next() публичный Метод

Returns the next document in the set, and advances the object's internal pointer. If the end of the set is reached, a new document will be fetched from the data source connection handle If no more documents can be fetched, returns null.
public next ( ) : mixed
Результат mixed Returns the next document in the set, or `false`, if no more documents are available.

offsetExists() публичный Метод

Returns a boolean indicating whether an offset exists for the current Collection.
public offsetExists ( string $offset ) : boolean
$offset string String or integer indicating the offset or index of an entity in the set.
Результат boolean Result.

offsetGet() публичный Метод

Gets an Entity object using PHP's array syntax, i.e. $documents[3] or $records[5].
public offsetGet ( mixed $offset ) : mixed
$offset mixed The offset.
Результат mixed Returns an `Entity` object if exists otherwise returns `null`.

offsetSet() публичный Метод

Adds the specified object to the Collection instance, and assigns associated metadata to the added object.
public offsetSet ( string $offset, mixed $data ) : mixed
$offset string The offset to assign the value to.
$data mixed The entity object to add.
Результат mixed Returns the set `Entity` object.

offsetUnset() публичный Метод

Unsets an offset.
public offsetUnset ( integer $offset )
$offset integer The offset to unset.

parent() публичный Метод

Returns the object's parent Document object.
public parent ( ) : object
Результат object

reduce() публичный Метод

Overridden to load any data that has not yet been loaded.
public reduce ( callback $filter, mixed $initial = false ) : mixed
$filter callback The filter to apply.
$initial mixed Initial value
Результат mixed A single reduced value

result() публичный Метод

Return's the pointer or resource that is used to load entities from the backend data source that originated this collection. This is useful in many cases for additional methods related to debugging queries.
public result ( ) : object
Результат object The pointer or resource from the data source

rewind() публичный Метод

Rewinds the collection to the beginning.
public rewind ( )

schema() публичный Метод

public schema ( $field = null )

serialize() публичный Метод

Note: because of the limitations outlined below custom handlers are ignored with serialized objects. Pulls all results to entirely populate _data and closes the object freeing the associated result resource. This allows for skipping the _result property which may hold unserializable PDOStatements. Properties that hold anonymous functions are also skipped. Some of these can almost be reconstructed (_handlers) others cannot (_methodFilters).
public serialize ( ) : string
Результат string Serialized properties of the object.

set() публичный Метод

For example: $collection->set(array( 42 => array('title' => 'Lorem Ipsum'), 43 => array('title' => 'Dolor Amet') ));
public set ( arary $values ) : void
$values arary An associative array of fields and values to assign to the `Collection`.
Результат void

sort() публичный Метод

Overriden to load any data that has not yet been loaded.
См. также: lithium\util\Collection::sort()
public sort ( string | callable $field = 'id', array $options = [] ) : lithium\data\Collection
$field string | callable The field to sort the data on, can also be a callback to a custom sort function.
$options array Reserved for future use.
Результат lithium\data\Collection Returns itself.

stats() публичный Метод

Gets the stat or stats associated with this Collection.
public stats ( string $name = null ) : mixed
$name string Stat name.
Результат mixed Single stat if `$name` supplied, else all stats for this `Collection`.

to() публичный Метод

The supported values of $format depend on the format handlers registered in the static property Collection::$_formats. The Collection class comes with built-in support for array conversion, but other formats may be registered. Once the appropriate handlers are registered, a Collection instance can be converted into any handler-supported format, i.e.: $collection->to('json'); // returns a JSON string $collection->to('xml'); // returns an XML string _Please note that Lithium does not ship with a default XML handler, but one can be configured easily._
См. также: lithium\util\Collection::toArray()
См. также: lithium\util\Collection::formats()
См. также: lithium\util\Collection::$_formats
public to ( string $format, array $options = [] ) : mixed
$format string By default the only supported value is `'array'`. However, additional format handlers can be registered using the `formats()` method.
$options array Options for converting this collection: - `'internal'` _boolean_: Indicates whether the current internal representation of the collection should be exported. Defaults to `false`, which uses the standard iterator interfaces. This is useful for exporting record sets, where records are lazy-loaded, and the collection must be iterated in order to fetch all objects. - `'indexed'` _boolean|null_: Allows to control how converted data is keyed. When set to `true` will force indexed conversion of the collection (the default) even if the collection has a parent. When `false` will convert without indexing. Provide `null` as a value to this option to only index when the collection has no parent.
Результат mixed The object converted to the value specified in `$format`; usually an array or string.

unserialize() публичный Метод

Restores state of the object including pulled results. Tries to restore _handlers by calling into _init().
public unserialize ( string $data ) : void
$data string Serialized properties of the object.
Результат void

valid() публичный Метод

Checks if current position is valid.
public valid ( ) : boolean
Результат boolean `true` if valid, `false` otherwise.

Описание свойств

$_autoConfig защищенное свойство

Holds an array of values that should be processed on initialization.
protected array $_autoConfig
Результат array

$_exists защищенное свойство

Indicates whether this array was part of a document loaded from a data source, or is part of a new document, or is in newly-added field of an existing document.
protected bool $_exists
Результат boolean

$_handlers защищенное свойство

Hold the "data export" handlers where the keys are fully-namespaced class names, and the values are closures that take an instance of the class as a parameter, and return an array or scalar value that the instance represents.
См. также: lithium\data\Collection::to()
protected array $_handlers
Результат array

$_model защищенное свойство

The fully-namespaced class name of the model object to which this entity set is bound. This is usually the model that executed the query which created this object.
protected string $_model
Результат string

$_parent защищенное свойство

A reference to this object's parent Document object.
protected object $_parent
Результат object

$_pathKey защищенное свойство

If this Collection instance has a parent document (see $_parent), this value indicates the key name of the parent document that contains it.
См. также: lithium\data\Collection::$_parent
protected string $_pathKey
Результат string

$_query защищенное свойство

A reference to the query object that originated this entity set; usually an instance of lithium\data\model\Query.
См. также: lithium\data\model\Query
protected object $_query
Результат object

$_result защищенное свойство

A pointer or resource that is used to load entities from the backend data source that originated this collection.
protected resource|object $_result
Результат resource | object

$_schema защищенное свойство

If the Collection has a schema object assigned (rather than loading one from a model), it will be assigned here.
См. также: lithium\data\Schema
protected lithium\data\Schema $_schema
Результат lithium\data\Schema

$_started защищенное свойство

Set to true when the collection has begun iterating.
protected bool $_started
Результат boolean

$_stats защищенное свойство

Contains an array of backend-specific statistics generated by the query that produced this Collection object. These stats are accessible via the stats() method.
См. также: lithium\data\Collection::stats()
protected array $_stats
Результат array

$_valid защищенное свойство

Indicates whether the current position is valid or not. This overrides the default value of the parent class.
См. также: lithium\util\Collection::valid()
protected bool $_valid
Результат boolean