W3cubDocs

/CakePHP 3.8

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
Extended by Cake\Collection\Collection implements Cake\Collection\CollectionInterface, Serializable uses Cake\Collection\CollectionTrait
Extended by Cake\Collection\Iterator\InsertIterator

Properties summary

  • $_path protected
    array

    An array containing each of the properties to be traversed to reach the point where the values should be inserted.

  • $_target protected
    string
    The property name to which values will be assigned
  • $_validValues protected
    boolean
    Holds whether the values collection is still valid. (has more records)
  • $_values protected
    The 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()source 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

InvalidArgumentException
If passed incorrect type for items.

Overrides

Cake\Collection\Collection::__construct()

current()source public

current( )

Returns the current element in the target collection after inserting the value from the source collection into the specified path.

Returns

mixed

Overrides

IteratorIterator::current()

next()source public

next( )

Advances the cursor to the next record

Overrides

IteratorIterator::next()

rewind()source public

rewind( )

Resets the collection pointer.

Overrides

IteratorIterator::rewind()

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

array

count()source public

count( )

Returns the amount of elements in the collection.

Returns

integer

Implementation of

Cake\Collection\CollectionInterface::count()

countKeys()source 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

integer

Implementation of

Cake\Collection\CollectionInterface::countKeys()

serialize()source public

serialize( )

Returns a string representation of this object that can be used to reconstruct it

Returns

string

Implementation 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( )

append()source public

append( $items )

appendItem()source public

appendItem( $item , $key = null )

avg()source public

avg( $matcher = null )

buffered()source public

buffered( )

Returns

Cake\Collection\Iterator\BufferedIterator

cartesianProduct()source public

cartesianProduct( callable $operation = null , callable $filter = null )

Parameters

callable $operation optional null
Operation
callable $filter optional null
Filter

Returns

Cake\Collection\CollectionInterface

Throws

LogicException

chunk()source public

chunk( $chunkSize )

chunkWithKeys()source public

chunkWithKeys( $chunkSize , $preserveKeys = true )

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 )

filter()source public

filter( callable $c = null )

Returns

Cake\Collection\Iterator\FilterIterator

first()source public

first( )

firstMatch()source public

firstMatch( array $conditions )

groupBy()source public

groupBy( $callback )

indexBy()source public

indexBy( $callback )

insert()source public

insert( $path , $values )

Returns

Cake\Collection\Iterator\InsertIterator

isEmpty()source public

isEmpty( )

jsonSerialize()source public

jsonSerialize( )

last()source public

last( )

lazy()source public

lazy( )

listNested()source public

listNested( $dir = 'desc' , $nestingKey = 'children' )

Returns

Cake\Collection\Iterator\TreeIterator

map()source public

map( callable $c )

Returns

Cake\Collection\Iterator\ReplaceIterator

match()source public

match( array $conditions )

max()source public

max( $callback , $type = \SORT_NUMERIC )

median()source public

median( $matcher = null )

min()source public

min( $callback , $type = \SORT_NUMERIC )

nest()source public

nest( $idPath , $parentPath , $nestingKey = 'children' )

newCollection()source protected

newCollection( ... $args )

Returns a new collection.

Allows classes which use this trait to determine their own type of returned collection interface

Parameters

... $args
$args Constructor arguments.

Returns

Cake\Collection\CollectionInterface

optimizeUnwrap()source protected

optimizeUnwrap( )

Unwraps this iterator and returns the simplest traversable that can be used for getting the data out

Returns

Traversable|array

prepend()source public

prepend( $items )

prependItem()source public

prependItem( $item , $key = null )

reduce()source public

reduce( callable $c , $zero = null )

reject()source public

reject( callable $c )

Returns

Cake\Collection\Iterator\FilterIterator

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 )

stopWhen()source public

stopWhen( $condition )

Returns

Cake\Collection\Iterator\StoppableIterator

sumOf()source public

sumOf( $matcher = null )

take()source public

take( $size = 1 , $from = 0 )

takeLast()source public

takeLast( $howMany )

through()source public

through( callable $handler )

toArray()source public

toArray( $preserveKeys = true )

toList()source public

toList( )

transpose()source public

transpose( )

Returns

Cake\Collection\CollectionInterface

Throws

LogicException

unfold()source public

unfold( callable $transformer = null )

unwrap()source public

unwrap( )

zip()source public

zip( $items )

zipWith()source public

zipWith( $items , $callable )

Magic methods inherited from Cake\Collection\CollectionInterface

cartesianProduct()

Properties detail

$_pathsource

protected array

An array containing each of the properties to be traversed to reach the point where the values should be inserted.

$_targetsource

protected string

The property name to which values will be assigned

$_validValuessource

protected boolean

Holds whether the values collection is still valid. (has more records)

true

$_valuessource

protected Cake\Collection\Collection

The collection from which to extract the values to be inserted

© 2005–present 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.
https://api.cakephp.org/3.8/class-Cake.Collection.Iterator.InsertIterator.html