<?php
declare(strict_types=1);
namespace PpPhp\Packages\Ui\Ppui\Foundation\Registries;
use PpPhp\Packages\Ui\Ppui\Foundation\Contracts\DefinitionInterface;
use PpPhp\Packages\Ui\Ppui\Foundation\Contracts\RegistryInterface;
abstract class AbstractRegistry implements RegistryInterface
{
    /** @var array<string, DefinitionInterface> */
    protected array $items = [];
    public function register(DefinitionInterface $definition): void { $this->items[$definition->id()] = $definition; }
    public function has(string $id): bool { return isset($this->items[$id]); }
    public function get(string $id): ?DefinitionInterface { return $this->items[$id] ?? null; }
    public function all(): array { return $this->items; }
    public function toArray(): array { return array_map(static fn(DefinitionInterface $d): array => $d->toArray(), $this->items); }
}
