39 lines
No EOL
726 B
PHP
39 lines
No EOL
726 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Loom\Utility\Collection;
|
|
|
|
use Loom\Utility\Collection\Interface\CollectionInterface;
|
|
|
|
class AbstractCollection implements CollectionInterface
|
|
{
|
|
public function __construct(protected array $items = [])
|
|
{
|
|
}
|
|
|
|
public function add(mixed $item): void
|
|
{
|
|
if (null === $item) {
|
|
return;
|
|
}
|
|
|
|
$this->items[] = $item;
|
|
}
|
|
|
|
public function remove(mixed $item): void
|
|
{
|
|
$key = array_search($item, $this->items, true);
|
|
|
|
if ($key) {
|
|
unset($this->items[$key]);
|
|
}
|
|
|
|
$this->items = array_values($this->items);
|
|
}
|
|
|
|
public function toArray(): array
|
|
{
|
|
return $this->items;
|
|
}
|
|
} |