- Some bugfixes made in Relation
- Fixed search() methods in EntityCollection - Work done on Relations of EntityTrait ; a lot of work still to be done. It must also move to another file.
This commit is contained in:
1 parent
4d221859fc
commit
8e521025d3
4 files changed
+40
-15
No files matched your search
@@ -14,7 +14,7 @@ class EntityCollection extends \ArrayObject {
|
||||
if ( $callback($item, $key, $idx) ) {
|
||||
$idx++;
|
||||
|
||||
yield $item;
|
||||
yield $key => $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,20 +30,45 @@ class EntityCollection extends \ArrayObject {
|
||||
return $collection;
|
||||
}
|
||||
|
||||
public function searchOne($value, string $field) : ? object
|
||||
public function removeOne($value, string $field, bool $strict = true) : ? object
|
||||
{
|
||||
# Returning first value only
|
||||
foreach($this->search($value, $field) as $item) {
|
||||
foreach($this->search($value, $field, $strict) as $key => $item) {
|
||||
|
||||
$this->offsetUnset($key);
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function search($value, string $field) : Generator
|
||||
public function remove($value, string $field, bool $strict = true) : array
|
||||
{
|
||||
foreach($this->filters(fn($v) => $v->$field === $value) as $item) {
|
||||
yield $item;
|
||||
$removed = [];
|
||||
|
||||
foreach($this->search($value, $field, $strict) as $key => $item) {
|
||||
$this->offsetUnset($key);
|
||||
|
||||
$removed[] = $item;
|
||||
}
|
||||
|
||||
return $removed;
|
||||
}
|
||||
|
||||
public function searchOne($value, string $field, bool $strict = true) : ? object
|
||||
{
|
||||
# Returning first value only
|
||||
foreach($this->search($value, $field, $strict) as $item) {
|
||||
return $item;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
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) {
|
||||
yield $key => $item;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user