Remove illuminate/collections
This commit is contained in:
parent
275103e149
commit
419d1cec14
6 changed files with 89 additions and 260 deletions
42
src/Presentation/Collection/AbstractCollection.php
Normal file
42
src/Presentation/Collection/AbstractCollection.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Presentation\Collection;
|
||||
|
||||
use ArrayIterator;
|
||||
use Countable;
|
||||
use Iterator;
|
||||
use IteratorAggregate;
|
||||
|
||||
abstract class AbstractCollection implements Countable, IteratorAggregate
|
||||
{
|
||||
public function __construct(protected array $items = [])
|
||||
{
|
||||
}
|
||||
|
||||
public function count(): int
|
||||
{
|
||||
return count($this->items);
|
||||
}
|
||||
|
||||
public function filter(callable $callback): self
|
||||
{
|
||||
return new static(
|
||||
array_filter(
|
||||
array: $this->items,
|
||||
callback: $callback,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function getIterator(): Iterator
|
||||
{
|
||||
return new ArrayIterator($this->items);
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return $this->items;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue