- Some work done on correcting LDAP package compatibility
This commit is contained in:
1 parent
71de0a8ac1
commit
e3d0e45a4e
13 files changed
+110
-22
No files matched your search
@@ -44,6 +44,15 @@ class EntityCollection extends \ArrayObject {
|
||||
}
|
||||
}
|
||||
|
||||
public function filtersOne(Callable $callback) : ? object
|
||||
{
|
||||
foreach($this->filters($callback, true) as $item) {
|
||||
return $item;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function iterate(Callable $callback) : self
|
||||
{
|
||||
foreach($this as $item) {
|
||||
@@ -290,6 +299,20 @@ class EntityCollection extends \ArrayObject {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function batch(int $size, $fill = null, $preserveKeys = true) : array
|
||||
{
|
||||
$batch = [];
|
||||
$split = ceil( $this->count() / $size );
|
||||
|
||||
for($i = 0; $i < $split; $i++) {
|
||||
$slice = array_slice($this->getArrayCopy(), $i * $size, $size, $preserveKeys);
|
||||
$pad = ( count($slice) !== $size ) && ( $fill !== null );
|
||||
$batch[] = $pad ? array_pad($slice, $size, $fill) : $slice;
|
||||
}
|
||||
|
||||
return $batch;
|
||||
}
|
||||
|
||||
public function randomize() : self
|
||||
{
|
||||
$arr = $this->getArrayCopy();
|
||||
@@ -313,6 +336,16 @@ class EntityCollection extends \ArrayObject {
|
||||
return $this->reverse();
|
||||
}
|
||||
|
||||
public function sortField(? string $field = null) : self
|
||||
{
|
||||
return $this->sort(fn($e1, $e2) => $field ? $e1->$field <=> $e2->$field : $e1 <=> $e2);
|
||||
}
|
||||
|
||||
public function rsortField(string $field) : self
|
||||
{
|
||||
return $this->sort(fn($e1, $e2) => $field ? $e2->$field <=> $e1->$field : $e2 <=> $e1);
|
||||
}
|
||||
|
||||
public function reverse() : self
|
||||
{
|
||||
return $this->replaceWith(array_reverse($this->getArrayCopy()));;
|
||||
|
||||
Reference in new issue
Block a user