Class ReplaceIterator
Creates an iterator from another iterator that will modify each of the values by converting them using a callback function.
- IteratorIterator implements Iterator, Traversable, OuterIterator
- Cake\Collection\Collection implements Cake\Collection\CollectionInterface, Serializable uses Cake\Collection\CollectionTrait
- Cake\Collection\Iterator\ReplaceIterator
Properties summary
-
$_callback
protectedcallable
The callback function to be used to transform values -
$_innerIterator
protectedIterator
A reference to the internal iterator this object is wrapping.
Method Summary
-
__construct() public
Creates an iterator from another iterator that will modify each of the values by converting them using a callback function.
-
current() public
Returns the value returned by the callback after passing the current value in the iteration
-
unwrap() public
Method Detail
__construct() public ¶
__construct( array|Traversable $items , callable $callback )
Creates an iterator from another iterator that will modify each of the values by converting them using a callback function.
Each time the callback is executed it will receive the value of the element in the current iteration, the key of the element and the passed $items iterator as arguments, in that order.
Parameters
- array|Traversable $items
- The items to be filtered.
- callable $callback
- Callback.
Throws
If passed incorrect type for items.
Overrides
current() public ¶
current( )
Returns the value returned by the callback after passing the current value in the iteration
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()
|