InsertIterator
extends Collection
in package
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.
Table of Contents
Properties
- $_path : array<string|int, string>
- An array containing each of the properties to be traversed to reach the point where the values should be inserted.
- $_target : string
- The property name to which values will be assigned
- $_validValues : bool
- Holds whether the values collection is still valid. (has more records)
- $_values : Collection
- The collection from which to extract the values to be inserted
Methods
- __construct() : mixed
- Constructs a new collection that will dynamically add properties to it out of the values found in $values.
- __debugInfo() : array<string, mixed>
- Returns an array that can be used to describe the internal state of this object.
- __serialize() : array<string|int, mixed>
- Returns an array for serializing this of this object.
- __unserialize() : void
- Rebuilds the Collection instance.
- append() : CollectionInterface
- appendItem() : CollectionInterface
- avg() : mixed
- buffered() : CollectionInterface
- cartesianProduct() : CollectionInterface
- {@inheritDoc}
- chunk() : CollectionInterface
- chunkWithKeys() : CollectionInterface
- combine() : CollectionInterface
- compile() : CollectionInterface
- contains() : bool
- count() : int
- Returns the amount of elements in the collection.
- countBy() : CollectionInterface
- countKeys() : int
- Returns the number of unique keys in this iterator. This is the same as the number of elements the collection will contain after calling `toArray()`
- current() : mixed
- Returns the current element in the target collection after inserting the value from the source collection into the specified path.
- each() : mixed
- every() : bool
- extract() : CollectionInterface
- filter() : CollectionInterface
- first() : mixed
- firstMatch() : mixed
- groupBy() : CollectionInterface
- indexBy() : CollectionInterface
- insert() : CollectionInterface
- isEmpty() : bool
- jsonSerialize() : array<string|int, mixed>
- last() : mixed
- lazy() : CollectionInterface
- listNested() : CollectionInterface
- map() : CollectionInterface
- match() : CollectionInterface
- max() : mixed
- median() : mixed
- min() : mixed
- nest() : CollectionInterface
- next() : void
- Advances the cursor to the next record
- prepend() : CollectionInterface
- prependItem() : CollectionInterface
- reduce() : mixed
- reject() : CollectionInterface
- rewind() : void
- Resets the collection pointer.
- sample() : CollectionInterface
- serialize() : string
- Returns a string representation of this object that can be used to reconstruct it
- shuffle() : CollectionInterface
- skip() : CollectionInterface
- some() : bool
- sortBy() : CollectionInterface
- stopWhen() : CollectionInterface
- sumOf() : mixed
- take() : CollectionInterface
- takeLast() : CollectionInterface
- through() : CollectionInterface
- toArray() : array<string|int, mixed>
- toList() : array<string|int, mixed>
- transpose() : CollectionInterface
- {@inheritDoc}
- unfold() : CollectionInterface
- unserialize() : void
- Unserializes the passed string and rebuilds the Collection instance
- unwrap() : Traversable
- zip() : CollectionInterface
- zipWith() : CollectionInterface
- newCollection() : CollectionInterface
- Returns a new collection.
- optimizeUnwrap() : iterable<string|int, mixed>
- Unwraps this iterator and returns the simplest traversable that can be used for getting the data out
Properties
$_path
An array containing each of the properties to be traversed to reach the point where the values should be inserted.
protected
array<string|int, string>
$_path
$_target
The property name to which values will be assigned
protected
string
$_target
$_validValues
Holds whether the values collection is still valid. (has more records)
protected
bool
$_validValues
= true
$_values
The collection from which to extract the values to be inserted
protected
Collection
$_values
Methods
__construct()
Constructs a new collection that will dynamically add properties to it out of the values found in $values.
public
__construct(iterable<string|int, mixed> $into, string $path, iterable<string|int, mixed> $values) : mixed
Parameters
- $into : iterable<string|int, mixed>
-
The target collection to which the values will be inserted at the specified path.
- $path : string
-
A dot separated list of properties that need to be traversed to insert the value into the target collection.
- $values : iterable<string|int, mixed>
-
The source collection from which the values will be inserted at the specified path.
__debugInfo()
Returns an array that can be used to describe the internal state of this object.
public
__debugInfo() : array<string, mixed>
Return values
array<string, mixed>__serialize()
Returns an array for serializing this of this object.
public
__serialize() : array<string|int, mixed>
Return values
array<string|int, mixed>__unserialize()
Rebuilds the Collection instance.
public
__unserialize(array<string|int, mixed> $data) : void
Parameters
- $data : array<string|int, mixed>
-
Data array.
append()
public
append(mixed $items) : CollectionInterface
Parameters
- $items : mixed
Tags
Return values
CollectionInterfaceappendItem()
public
appendItem(mixed $item[, mixed $key = null ]) : CollectionInterface
Parameters
- $item : mixed
- $key : mixed = null
Tags
Return values
CollectionInterfaceavg()
public
avg([mixed $path = null ]) : mixed
Parameters
- $path : mixed = null
Tags
buffered()
public
buffered() : CollectionInterface
Tags
Return values
CollectionInterfacecartesianProduct()
{@inheritDoc}
public
cartesianProduct([callable|null $operation = null ][, callable|null $filter = null ]) : CollectionInterface
Parameters
- $operation : callable|null = null
-
A callable that allows you to customize the product result.
- $filter : callable|null = null
-
A filtering callback that must return true for a result to be part of the final results.
Tags
Return values
CollectionInterfacechunk()
public
chunk(int $chunkSize) : CollectionInterface
Parameters
- $chunkSize : int
Tags
Return values
CollectionInterfacechunkWithKeys()
public
chunkWithKeys(int $chunkSize[, bool $keepKeys = true ]) : CollectionInterface
Parameters
- $chunkSize : int
- $keepKeys : bool = true
Tags
Return values
CollectionInterfacecombine()
public
combine(mixed $keyPath, mixed $valuePath[, mixed $groupPath = null ]) : CollectionInterface
Parameters
- $keyPath : mixed
- $valuePath : mixed
- $groupPath : mixed = null
Tags
Return values
CollectionInterfacecompile()
public
compile([bool $keepKeys = true ]) : CollectionInterface
Parameters
- $keepKeys : bool = true
Tags
Return values
CollectionInterfacecontains()
public
contains(mixed $value) : bool
Parameters
- $value : mixed
Tags
Return values
boolcount()
Returns the amount of elements in the collection.
public
count() : int
Return values
intcountBy()
public
countBy(mixed $path) : CollectionInterface
Parameters
- $path : mixed
Tags
Return values
CollectionInterfacecountKeys()
Returns the number of unique keys in this iterator. This is the same as the number of elements the collection will contain after calling `toArray()`
public
countKeys() : int
Return values
intcurrent()
Returns the current element in the target collection after inserting the value from the source collection into the specified path.
public
current() : mixed
Attributes
- #[ReturnTypeWillChange]
each()
public
each(callable $callback) : mixed
Parameters
- $callback : callable
Tags
every()
public
every(callable $callback) : bool
Parameters
- $callback : callable
Tags
Return values
boolextract()
public
extract(mixed $path) : CollectionInterface
Parameters
- $path : mixed
Tags
Return values
CollectionInterfacefilter()
public
filter([callable|null $callback = null ]) : CollectionInterface
Parameters
- $callback : callable|null = null
Tags
Return values
CollectionInterfacefirst()
public
first() : mixed
Tags
firstMatch()
public
firstMatch(array<string|int, mixed> $conditions) : mixed
Parameters
- $conditions : array<string|int, mixed>
Tags
groupBy()
public
groupBy(mixed $path) : CollectionInterface
Parameters
- $path : mixed
Tags
Return values
CollectionInterfaceindexBy()
public
indexBy(mixed $path) : CollectionInterface
Parameters
- $path : mixed
Tags
Return values
CollectionInterfaceinsert()
public
insert(string $path, mixed $values) : CollectionInterface
Parameters
- $path : string
- $values : mixed
Tags
Return values
CollectionInterfaceisEmpty()
public
isEmpty() : bool
Tags
Return values
booljsonSerialize()
public
jsonSerialize() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>last()
public
last() : mixed
Tags
lazy()
public
lazy() : CollectionInterface
Tags
Return values
CollectionInterfacelistNested()
public
listNested([mixed $order = 'desc' ][, mixed $nestingKey = 'children' ]) : CollectionInterface
Parameters
- $order : mixed = 'desc'
- $nestingKey : mixed = 'children'
Tags
Return values
CollectionInterfacemap()
public
map(callable $callback) : CollectionInterface
Parameters
- $callback : callable
Tags
Return values
CollectionInterfacematch()
public
match(array<string|int, mixed> $conditions) : CollectionInterface
Parameters
- $conditions : array<string|int, mixed>
Tags
Return values
CollectionInterfacemax()
public
max(mixed $path[, int $sort = SORT_NUMERIC ]) : mixed
Parameters
- $path : mixed
- $sort : int = SORT_NUMERIC
Tags
median()
public
median([mixed $path = null ]) : mixed
Parameters
- $path : mixed = null
Tags
min()
public
min(mixed $path[, int $sort = SORT_NUMERIC ]) : mixed
Parameters
- $path : mixed
- $sort : int = SORT_NUMERIC
Tags
nest()
public
nest(mixed $idPath, mixed $parentPath[, string $nestingKey = 'children' ]) : CollectionInterface
Parameters
- $idPath : mixed
- $parentPath : mixed
- $nestingKey : string = 'children'
Tags
Return values
CollectionInterfacenext()
Advances the cursor to the next record
public
next() : void
prepend()
public
prepend(mixed $items) : CollectionInterface
Parameters
- $items : mixed
Tags
Return values
CollectionInterfaceprependItem()
public
prependItem(mixed $item[, mixed $key = null ]) : CollectionInterface
Parameters
- $item : mixed
- $key : mixed = null
Tags
Return values
CollectionInterfacereduce()
public
reduce(callable $callback[, mixed $initial = null ]) : mixed
Parameters
- $callback : callable
- $initial : mixed = null
Tags
reject()
public
reject(callable $callback) : CollectionInterface
Parameters
- $callback : callable
Tags
Return values
CollectionInterfacerewind()
Resets the collection pointer.
public
rewind() : void
sample()
public
sample([int $length = 10 ]) : CollectionInterface
Parameters
- $length : int = 10
Tags
Return values
CollectionInterfaceserialize()
Returns a string representation of this object that can be used to reconstruct it
public
serialize() : string
Return values
stringshuffle()
public
shuffle() : CollectionInterface
Tags
Return values
CollectionInterfaceskip()
public
skip(int $length) : CollectionInterface
Parameters
- $length : int
Tags
Return values
CollectionInterfacesome()
public
some(callable $callback) : bool
Parameters
- $callback : callable
Tags
Return values
boolsortBy()
public
sortBy(mixed $path[, int $order = SORT_DESC ][, int $sort = SORT_NUMERIC ]) : CollectionInterface
Parameters
- $path : mixed
- $order : int = SORT_DESC
- $sort : int = SORT_NUMERIC
Tags
Return values
CollectionInterfacestopWhen()
public
stopWhen(mixed $condition) : CollectionInterface
Parameters
- $condition : mixed
Tags
Return values
CollectionInterfacesumOf()
public
sumOf([mixed $path = null ]) : mixed
Parameters
- $path : mixed = null
Tags
take()
public
take([int $length = 1 ][, int $offset = 0 ]) : CollectionInterface
Parameters
- $length : int = 1
- $offset : int = 0
Tags
Return values
CollectionInterfacetakeLast()
public
takeLast(int $length) : CollectionInterface
Parameters
- $length : int
Tags
Return values
CollectionInterfacethrough()
public
through(callable $callback) : CollectionInterface
Parameters
- $callback : callable
Tags
Return values
CollectionInterfacetoArray()
public
toArray([bool $keepKeys = true ]) : array<string|int, mixed>
Parameters
- $keepKeys : bool = true
Tags
Return values
array<string|int, mixed>toList()
public
toList() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>transpose()
{@inheritDoc}
public
transpose() : CollectionInterface
Tags
Return values
CollectionInterfaceunfold()
public
unfold([callable|null $callback = null ]) : CollectionInterface
Parameters
- $callback : callable|null = null
Tags
Return values
CollectionInterfaceunserialize()
Unserializes the passed string and rebuilds the Collection instance
public
unserialize(string $collection) : void
Parameters
- $collection : string
-
The serialized collection
unwrap()
public
unwrap() : Traversable
Tags
Return values
Traversablezip()
public
zip(iterable<string|int, mixed> $items) : CollectionInterface
Parameters
- $items : iterable<string|int, mixed>
Tags
Return values
CollectionInterfacezipWith()
public
zipWith(iterable<string|int, mixed> $items, mixed $callback) : CollectionInterface
Parameters
- $items : iterable<string|int, mixed>
- $callback : mixed
Tags
Return values
CollectionInterfacenewCollection()
Returns a new collection.
protected
newCollection(mixed ...$args) : CollectionInterface
Allows classes which use this trait to determine their own type of returned collection interface
Parameters
- $args : mixed
-
Constructor arguments.
Return values
CollectionInterfaceoptimizeUnwrap()
Unwraps this iterator and returns the simplest traversable that can be used for getting the data out
protected
optimizeUnwrap() : iterable<string|int, mixed>