PHP 클래스 lithium\data\Collection

상속: extends lithium\util\Collection
파일 보기 프로젝트 열기: unionofrad/lithium 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$_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