- A lot of bugfixes, mainly with escaping (still working on it to get 100% coverage)
This commit is contained in:
1 parent
e3d0e45a4e
commit
3905047111
8 files changed
+91
-126
No files matched your search
+41
-49
@@ -25,12 +25,12 @@ class EntityCollection extends \ArrayObject {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function filtersCollection(Callable $callback, bool $replaceCollection = false) : self
|
||||
|
||||
public function filtersCollection(Callable $callback, bool $yieldValueOnly = false, bool $replaceCollection = false) : self
|
||||
{
|
||||
$collection = new static();
|
||||
|
||||
foreach($this->filters($callback, true) as $item) {
|
||||
|
||||
foreach($this->filters($callback, $yieldValueOnly) as $item) {
|
||||
$collection->append($item);
|
||||
}
|
||||
|
||||
@@ -86,15 +86,8 @@ class EntityCollection extends \ArrayObject {
|
||||
|
||||
return $removed;
|
||||
}
|
||||
|
||||
public function clear() : self
|
||||
{
|
||||
$this->exchangeArray([]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function search($value, string $field, bool $strict = true) : Generator
|
||||
|
||||
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;
|
||||
@@ -121,12 +114,7 @@ class EntityCollection extends \ArrayObject {
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
public function searchInstances(string $className) : self
|
||||
{
|
||||
return $this->filtersCollection(fn($obj) => is_a($obj, $className));
|
||||
}
|
||||
|
||||
|
||||
public function column($field, bool $unique = false) : array
|
||||
{
|
||||
$list = [];
|
||||
@@ -138,9 +126,9 @@ class EntityCollection extends \ArrayObject {
|
||||
else {
|
||||
$value = $item->$field;
|
||||
}
|
||||
|
||||
if ($unique && in_array($value, $list, true)) {
|
||||
continue;
|
||||
|
||||
if ($unique && in_array($value, $list)) {
|
||||
break;
|
||||
}
|
||||
|
||||
$list[] = $value;
|
||||
@@ -269,22 +257,15 @@ class EntityCollection extends \ArrayObject {
|
||||
parent::append($value);
|
||||
}
|
||||
}
|
||||
|
||||
public function mergeWith(... $datasets) : self
|
||||
|
||||
public function mergeWith( /*array|EntityCollection*/ $datasets ) : self
|
||||
{
|
||||
$list = [];
|
||||
|
||||
foreach($datasets as $dataset) {
|
||||
if ( is_object($dataset) ) {
|
||||
$list = array_merge($dataset->getArrayCopy(), $list);
|
||||
}
|
||||
else {
|
||||
$list = array_merge($dataset, $list);
|
||||
}
|
||||
if ( is_object($datasets) ) {
|
||||
$datasets = $datasets->getArrayCopy();
|
||||
}
|
||||
|
||||
$this->exchangeArray( array_merge( $this->getArrayCopy(), $list ) );
|
||||
|
||||
|
||||
$this->exchangeArray( array_merge( $this->getArrayCopy(), $datasets ) );
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -329,11 +310,32 @@ class EntityCollection extends \ArrayObject {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function rsort(callable $callback, $function = "uasort") : self
|
||||
public function pop() /* : mixed */
|
||||
{
|
||||
$this->sort(...func_get_args());
|
||||
$arr = $this->getArrayCopy();
|
||||
$pop = array_pop($arr);
|
||||
$this->exchangeArray($arr);
|
||||
|
||||
return $this->reverse();
|
||||
return $pop;
|
||||
}
|
||||
|
||||
public function shift() /* : mixed */
|
||||
{
|
||||
$arr = $this->getArrayCopy();
|
||||
$shift = array_shift($arr);
|
||||
$this->exchangeArray($arr);
|
||||
|
||||
return $shift;
|
||||
}
|
||||
|
||||
public function reverse() : self
|
||||
{
|
||||
return $this->replaceWith(array_reverse($this->getArrayCopy()));
|
||||
}
|
||||
|
||||
public function slice(int $offset, ? int $length = null) : self
|
||||
{
|
||||
return new self(array_slice($this->getArrayCopy(), $offset, $length));
|
||||
}
|
||||
|
||||
public function sortField(? string $field = null) : self
|
||||
@@ -345,14 +347,4 @@ class EntityCollection extends \ArrayObject {
|
||||
{
|
||||
return $this->sort(fn($e1, $e2) => $field ? $e2->$field <=> $e1->$field : $e2 <=> $e1);
|
||||
}
|
||||
|
||||
public function reverse() : self
|
||||
{
|
||||
return $this->replaceWith(array_reverse($this->getArrayCopy()));;
|
||||
}
|
||||
|
||||
public function slice(int $offset, ? int $length = null) : self
|
||||
{
|
||||
return new self(array_slice($this->getArrayCopy(), $offset, $length));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user