- Upgraded doc intro to match new attribute uses.

This commit is contained in:
mcndave committed 2023-02-23 17:16:22 +00:00
1 parent c9c6a11ebd
commit 36cddf8f78
2 files changed
+29 -19

No files matched your search

+23 -3
View File
@@ -58,6 +58,26 @@ class EntityCollection extends \ArrayObject {
return null;
}
public function extract(Callable $callback) : self
{
$idx = 0;
$replace = [];
$collection = new static();
foreach($this as $key => $item) {
if ( $callback($item, $key, $idx++) ) {
$collection->append($item);
}
else {
$replace[] = $item;
}
}
$this->replaceWith($replace);
return $collection;
}
public function iterate(Callable $callback) : self
{
foreach($this as $item) {
@@ -117,17 +137,17 @@ class EntityCollection extends \ArrayObject {
public function searchAll(/* mixed*/ $values, string $field, bool $strict = true, bool $compareArray = false) : self
{
$obj = new static();
$collection = new static();
$values = is_array($values) && $compareArray ? [ $values ] : $values;
foreach((array) $values as $value) {
foreach ($this->search($value, $field, $strict) as $item) {
$obj->append($item);
$collection->append($item);
}
}
return $obj;
return $collection;
}
public function diffAll(/* mixed */ $values, string $field, bool $strict = true, bool $compareArray = false) : self