|
|
@ -77,19 +77,51 @@ class ImmutableCollection implements IImmutableCollection {
|
|
|
|
$this->elements[$this->_normalizeKey($key)] = $value;
|
|
|
|
$this->elements[$this->_normalizeKey($key)] = $value;
|
|
|
|
return $this;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Internally merge one or multiple collections in the current one
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param IImmutableCollection ...$collections The collections to merge
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return $this
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
protected function _merge (IImmutableCollection ...$collections): self {
|
|
|
|
|
|
|
|
foreach ($collections as $collection) {
|
|
|
|
|
|
|
|
foreach ($collection as $key => $value) {
|
|
|
|
|
|
|
|
$this->_set($key, $value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Internally add a value
|
|
|
|
* Internally add a value
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param mixed $value The value
|
|
|
|
* @param mixed ...$values The value
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @psalm-param TValue $value
|
|
|
|
* @psalm-param TValue ...$value
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
* @return $this
|
|
|
|
* @internal
|
|
|
|
* @internal
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
protected function _add ($value): self {
|
|
|
|
protected function _add (...$values): self {
|
|
|
|
|
|
|
|
foreach ($values as $value) {
|
|
|
|
$this->elements[] = $value;
|
|
|
|
$this->elements[] = $value;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Internally add the <b>values</b> of one or multiple collections
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param IImmutableCollection ...$collections The collections to add
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return mixed
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
protected function _addCollection (IImmutableCollection ...$collections): self {
|
|
|
|
|
|
|
|
foreach ($collections as $collection) {
|
|
|
|
|
|
|
|
foreach ($collection as $value) {
|
|
|
|
|
|
|
|
$this->_add($value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return $this;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -296,4 +328,11 @@ class ImmutableCollection implements IImmutableCollection {
|
|
|
|
public static function split (string $value, string $separator): self {
|
|
|
|
public static function split (string $value, string $separator): self {
|
|
|
|
return new static (explode($separator, $value));
|
|
|
|
return new static (explode($separator, $value));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @inheritDoc
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function combineWith (IImmutableCollection ...$collections): IImmutableCollection {
|
|
|
|
|
|
|
|
return (clone $this)->_merge(...$collections);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|