Property | Type | Description | |
---|---|---|---|
$_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. |
Method | Description | |
---|---|---|
__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. |
Method | Description | |
---|---|---|
_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. |
public __construct ( array $config = [] ) : void | ||
$config | array | Available configuration options are: - `'data'` _array_ - `'model'` _string|null_ |
return | void |
public __destruct ( ) : void | ||
return | void |
protected _filterFromArray ( array $filter ) : Closure | ||
$filter | array | An array of key/value pairs used to filter `Collection` items. |
return | Closure | Returns a closure that wraps the array and attempts to match each value against `Collection` item properties. |
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. |
return | object | Returns the inserted `Record`, `Document` object or other `Entity` object. |
public close ( ) |
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()`. |
return | 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. |
public offsetExists ( string $offset ) : boolean | ||
$offset | string | String or integer indicating the offset or index of an entity in the set. |
return | boolean | Result. |
public offsetUnset ( integer $offset ) | ||
$offset | integer | The offset to unset. |
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. |
return | mixed | The object converted to the value specified in `$format`; usually an array or string. |
public unserialize ( string $data ) : void | ||
$data | string | Serialized properties of the object. |
return | void |
protected array $_autoConfig | ||
return | array |
protected bool $_exists | ||
return | boolean |
protected array $_handlers | ||
return | array |
protected string $_model | ||
return | string |
protected object $_parent | ||
return | object |
protected string $_pathKey | ||
return | string |
protected object $_query | ||
return | object |
protected resource|object $_result | ||
return | resource | object |
protected lithium\data\Schema $_schema | ||
return | lithium\data\Schema |
protected bool $_started | ||
return | boolean |
protected array $_stats | ||
return | array |
protected bool $_valid | ||
return | boolean |