Class ExtractIterator
Creates an iterator from another iterator that extract the requested column or property based on a path
- IteratorIterator implements Iterator, Traversable, OuterIterator
-
Cake\Collection\Collection implements Cake\Collection\CollectionInterface, Serializable uses Cake\Collection\CollectionTrait
-
Cake\Collection\Iterator\ExtractIterator
Properties summary
-
$_extractor
protectedcallable
A callable responsible for extracting a single value for each item in the collection.
Method Summary
-
__construct() public
Creates the iterator that will return the requested property for each value in the collection expressed in $path
-
current() public
Returns the column value defined in $path or null if the path could not be followed
Method Detail
__construct() public ¶
__construct( array|Traversable $items , string $path )
Creates the iterator that will return the requested property for each value in the collection expressed in $path
Example:
Extract the user name for all comments in the array:
$items = [ ['comment' => ['body' => 'cool', 'user' => ['name' => 'Mark']], ['comment' => ['body' => 'very cool', 'user' => ['name' => 'Renan']] ]; $extractor = new ExtractIterator($items, 'comment.user.name'');
Parameters
- array|Traversable $items
- The list of values to iterate
- string $path
a dot separated string symbolizing the path to follow inside the hierarchy of each value so that the column can be extracted.
Throws
If passed incorrect type for items.
Overrides
Methods inherited from Cake\Collection\Collection
__debugInfo() public ¶
__debugInfo( )
Returns an array that can be used to describe the internal state of this object.
Returns
serialize() public ¶
serialize( )
Returns a string representation of this object that can be used to reconstruct it
Returns
Implementation of
Serializable::serialize()
unserialize() public ¶
unserialize( string $collection )
Unserializes the passed string and rebuilds the Collection instance
Parameters
- string $collection
- The serialized collection
Implementation of
Serializable::unserialize()
Methods used from Cake\Collection\CollectionTrait
Properties detail
$_extractor ¶
A callable responsible for extracting a single value for each item in the collection.