Property | Type | Description | |
---|---|---|---|
$_autoConfig | array | Allows a collection's items to be automatically assigned from class construction options. | |
$_data | array | The items contained in the collection. | |
$_formats | array | Accessed via the formats() method. |
Method | Description | |
---|---|---|
__call ( string $method, array $parameters = [] ) : mixed | Hook to handle dispatching of methods against all items in the collection. | |
append ( mixed $value ) | Appends an item. | |
count ( ) : integer | Counts the items of the object. | |
current ( ) : mixed | Returns the current item. | |
each ( callback $filter ) : |
Applies a callback to all items in the collection. | |
end ( ) : mixed | Moves forward to the last item. | |
find ( callback $filter, array $options = [] ) : mixed | Filters a copy of the items in the collection. | |
first ( callback $filter = null ) : mixed | Returns the first non-empty value in the collection after a filter is applied, or rewinds the collection and returns the first value. | |
formats ( string $format, mixed $handler = null ) : mixed | Accessor method for adding format handlers to instances and subclasses of Collection. | |
invoke ( string $method, array $params = [], array $options = [] ) : mixed | Handles dispatching of methods against all items in the collection. | |
key ( ) : scalar | Returns the key of the current item. | |
keys ( ) : array | Returns the item keys. | |
map ( callback $filter, array $options = [] ) : mixed | Applies a callback to a copy of all data in the collection and returns the result. | |
next ( ) : The | Move forwards to the next item. | |
offsetExists ( string $offset ) : boolean | Checks whether or not an offset exists. | |
offsetGet ( string $offset ) : mixed | Returns the value at specified offset. | |
offsetSet ( string $offset, mixed $value ) : mixed | Assigns a value to the specified offset. | |
offsetUnset ( string $offset ) | Unsets an offset. | |
prev ( ) : mixed | Moves backward to the previous item. If already at the first item, moves to the last one. | |
reduce ( callback $reducer, mixed $initial = false ) : mixed | Reduce, or fold, a collection down to a single value | |
respondsTo ( string $method, boolean $internal = false ) : boolean | Determines if a given method can be called. | |
rewind ( ) : mixed | Rewinds to the first item. | |
sort ( string | callable $sorter = 'sort', array $options = [] ) : |
Sorts the objects in the collection. | |
to ( string $format, array $options = [] ) : mixed | Converts a Collection object to another type of object, or a simple type such as an array. | |
toArray ( mixed $data, array $options = [] ) : array | Exports a Collection instance to an array. Used by Collection::to(). | |
valid ( ) : boolean | Checks if current position is valid. |
Method | Description | |
---|---|---|
_init ( ) : void | Initializes the collection object by merging in collection items and removing redundant object properties. | |
_to ( $format, &$data, &$options ) |
public find ( callback $filter, array $options = [] ) : mixed | ||
$filter | callback | Callback to use for filtering. |
$options | array | The available options are: - `'collect'`: If `true`, the results will be returned wrapped in a new `Collection` object or subclass. Defaults to `true`. |
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 first ( callback $filter = null ) : mixed | ||
$filter | callback | A closure through which collection values will be passed. If the return value of this function is non-empty, it will be returned as the result of the method call. If `null`, the collection is rewound (see `rewind()`) and the first item is returned. |
return | mixed | Returns the first non-empty collection value returned from `$filter`. |
public static formats ( string $format, mixed $handler = null ) : mixed | ||
$format | string | A string representing the name of the format that a `Collection` can be converted to. This corresponds to the `$format` parameter in the `to()` method. Alternatively, the fully-namespaced class name of a format-handler class. |
$handler | mixed | If `$format` is the name of a format string, `$handler` should be the function that handles the conversion, either an anonymous function, or a reference to a method name in `"Class::method"` form. If `$format` is a class name, can be `null`. |
return | mixed | Returns the value of the format handler assigned. |
public invoke ( string $method, array $params = [], array $options = [] ) : mixed | ||
$method | string | The name of the method to call on each instance in the collection. |
$params | array | The parameters to pass on each method call. |
$options | array | Specifies options for how to run the given method against the object collection. The available options are: - `'collect'`: If `true`, the results of this method call will be returned wrapped in a new `Collection` object or subclass. - `'merge'`: Used primarily if the method being invoked returns an array. If set to `true`, merges all results arrays into one. |
return | mixed | Returns either an array of the return values of the methods, or the return values wrapped in a `Collection` instance. |
public key ( ) : scalar | ||
return | scalar | Scalar on success or `null` on failure. |
public map ( callback $filter, array $options = [] ) : mixed | ||
$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. |
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 next ( ) : The | ||
return | The | current item after moving or `false` on failure. |
public offsetExists ( string $offset ) : boolean | ||
$offset | string | An offset to check for. |
return | boolean | `true` if offset exists, `false` otherwise. |
public offsetUnset ( string $offset ) | ||
$offset | string | The offset to unset. |
public respondsTo ( string $method, boolean $internal = false ) : boolean | ||
$method | string | Name of the method. |
$internal | boolean | Provide `true` to perform check from inside the class/object. When `false` checks also for public visibility; defaults to `false`. |
return | boolean | Returns `true` if the method can be called, `false` otherwise. |
public sort ( string | callable $sorter = 'sort', array $options = [] ) : |
||
$sorter | string | callable | The sorter for the data. Either a callable to use as the sort function or a string with the name of a well-known sort function like `'natsort'` or a compare function like `'strcmp'`. Defaults to `'sort'`. |
$options | array | Reserved for future use. |
return | Returns itself. |
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. |
return | mixed | The object converted to the value specified in `$format`; usually an array or string. |
public static toArray ( mixed $data, array $options = [] ) : array | ||
$data | mixed | Either a `Collection` instance, or an array representing a `Collection`'s internal state. |
$options | array | Options used when converting `$data` to an array: - `'handlers'` _array_: An array 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. |
return | array | Returns the value of `$data` as a pure PHP array, recursively converting all sub-objects and other values to their closest array or scalar equivalents. |
protected array $_autoConfig | ||
return | array |
protected array $_data | ||
return | array |
protected static array $_formats | ||
return | array |