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
-
unwrap() public
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
current() public ¶
current( )
Returns the column value defined in $path or null if the path could not be followed
Returns
Overrides
IteratorIterator::current()
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
count() public ¶
count( )
Returns the amount of elements in the collection.
Returns
Implementation of
countKeys() public ¶
countKeys( )
Returns the number of unique keys in this iterator. This is, the number of
elements the collection will contain after calling toArray()
Returns
Implementation of
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
cartesianProduct() public ¶
cartesianProduct( callable $operation null , callable $filter null )
Parameters
- callable $operation optional null
- Operation
- callable $filter optional null
- Filter
Returns
Throws
optimizeUnwrap() protected ¶
optimizeUnwrap( )
Unwraps this iterator and returns the simplest traversable that can be used for getting the data out
Returns
Magic methods inherited from Cake\Collection\CollectionInterface
cartesianProduct()
|
Properties detail
$_extractor ¶
A callable responsible for extracting a single value for each item in the collection.