ExtractIterator (class)
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()source 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
InvalidArgumentExceptionIf passed incorrect type for items.
Overrides
Cake\Collection\Collection::__construct()
current()source public
current( )
Returns the column value defined in $path or null if the path could not be followed
Returns
mixedOverrides
IteratorIterator::current()
Methods inherited from Cake\Collection\Collection
__debugInfo()source public
__debugInfo( )
Returns an array that can be used to describe the internal state of this object.
Returns
arraycount()source public
count( )
Throws an exception.
Issuing a count on a Collection can have many side effects, some making the Collection unusable after the count operation.
Throws
LogicExceptionserialize()source public
serialize( )
Returns a string representation of this object that can be used to reconstruct it
Returns
stringImplementation of
Serializable::serialize()
unserialize()source 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
_unwrap()source public
_unwrap( )
Backwards compatible wrapper for unwrap()
Deprecated
Returns
Iteratorappend()source public
append( $items )
chunk()source public
chunk( $chunkSize )
combine()source public
combine( $keyPath , $valuePath , $groupPath null )
compile()source public
compile( $preserveKeys true )
contains()source public
contains( $value )
countBy()source public
countBy( $callback )
each()source public
each( callable $c )
every()source public
every( callable $c )
extract()source public
extract( $matcher )
first()source public
first( )
firstMatch()source public
firstMatch( array $conditions )
groupBy()source public
groupBy( $callback )
indexBy()source public
indexBy( $callback )
isEmpty()source public
isEmpty( )
jsonSerialize()source public
jsonSerialize( )
last()source public
last( )
listNested()source public
listNested( $dir 'desc' , $nestingKey 'children' )
Returns
Cake\Collection\Iterator\TreeIterator
match()source public
match( array $conditions )
max()source public
max( $callback , $type SORT_NUMERIC )
min()source public
min( $callback , $type SORT_NUMERIC )
nest()source public
nest( $idPath , $parentPath )
reduce()source public
reduce( callable $c , $zero null )
sample()source public
sample( $size 10 )
shuffle()source public
shuffle( )
skip()source public
skip( $howMany )
some()source public
some( callable $c )
sortBy()source public
sortBy( $callback , $dir SORT_DESC , $type SORT_NUMERIC )
sumOf()source public
sumOf( $matcher null )
take()source public
take( $size 1 , $from 0 )
through()source public
through( callable $handler )
toArray()source public
toArray( $preserveKeys true )
toList()source public
toList( )
unfold()source public
unfold( callable $transformer null )
unwrap()source public
unwrap( )
zip()source public
zip( $items )
zipWith()source public
zipWith( $items , $callable )
Properties detail
$_extractorsource
protected callable
A callable responsible for extracting a single value for each item in the collection.
© 2005–2016 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
http://api.cakephp.org/3.2/class-Cake.Collection.Iterator.ExtractIterator.html