- A lot of fixes made again in this patch

This commit is contained in:
Dave Mc Nicoll committed 2021-05-24 20:03:38 +00:00
1 parent 4df9ececba
commit 7fb591e1f5
12 files changed
+222 -52

No files matched your search

+24 -5
View File
@@ -74,7 +74,7 @@ class EntityCollection extends \ArrayObject {
return null;
}
public function remove($value, string $field, bool $strict = true) : array
public function remove(/* mixed */ $values, string $field, bool $strict = true) : array
{
$removed = [];
@@ -89,7 +89,7 @@ class EntityCollection extends \ArrayObject {
public function search($value, string $field, bool $strict = true) : Generator
{
foreach($this->filters(fn($v) => $strict ? $v->$field === $value : $v->$field == $value) as $key => $item) {
foreach($this->filters(fn($v) => isset($v->$field) ? ( $strict ? $v->$field === $value : $v->$field == $value ) : false) as $key => $item) {
yield $key => $item;
}
}
@@ -104,12 +104,31 @@ class EntityCollection extends \ArrayObject {
return null;
}
public function searchAll($value, string $field, bool $strict = true) : self
public function searchAll(/* mixed*/ $values, string $field, bool $strict = true, bool $compareArray = false) : self
{
$obj = new static();
foreach($this->search($value, $field, $strict) as $item) {
$obj->append($item);
$values = is_array($values) && $compareArray ? [ $values ] : $values;
foreach((array) $values as $value) {
foreach ($this->search($value, $field, $strict) as $item) {
$obj->append($item);
}
}
return $obj;
}
public function diffAll(/* mixed */ $values, string $field, bool $strict = true, bool $compareArray = false) : self
{
$obj = new static($this->getArrayCopy());
$values = is_array($values) && $compareArray ? [ $values ] : $values;
foreach((array) $values as $value) {
foreach($obj->search($value, $field, $strict) as $key => $item) {
$obj->offsetUnset($key);
}
}
return $obj;