Class InsertIterator
This iterator will insert values into a property of each of the records returned. The values to be inserted come out of another traversal object. This is useful when you have two separate collections and want to merge them together by placing each of the values from one collection into a property inside the other collection.
- IteratorIterator implements Iterator, Traversable, OuterIterator
-
Cake\Collection\Collection implements Cake\Collection\CollectionInterface, Serializable uses Cake\Collection\CollectionTrait
-
Cake\Collection\Iterator\InsertIterator
Properties summary
-
$_path
protectedarray
An array containing each of the properties to be traversed to reach the point where the values should be inserted.
-
$_target
protectedstring
The property name to which values will be assigned -
$_validValues
protectedboolean
Holds whether the values collection is still valid. (has more records) -
$_values
protectedThe collection from which to extract the values to be inserted
Method Summary
-
__construct() public
Constructs a new collection that will dynamically add properties to it out of the values found in $values.
-
current() public
Returns the current element in the target collection after inserting the value from the source collection into the specified path.
-
next() public
Advances the cursor to the next record -
rewind() public
Resets the collection pointer.
Method Detail
__construct() public ¶
__construct( array|Traversable $into , string $path , array|Traversable $values )
Constructs a new collection that will dynamically add properties to it out of the values found in $values.
Parameters
- array|Traversable $into
The target collection to which the values will be inserted at the specified path.
- string $path
A dot separated list of properties that need to be traversed to insert the value into the target collection.
- array|Traversable $values
The source collection from which the values will be inserted at the specified path.
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
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
$_path ¶
An array containing each of the properties to be traversed to reach the point where the values should be inserted.
$_validValues ¶
Holds whether the values collection is still valid. (has more records)
true
$_values ¶
Cake\Collection\Collection
The collection from which to extract the values to be inserted