<?php

declare(strict_types=1);

namespace App\Framework\DI;

/**
 * Verwaltet alle Service-Bindings
 */
final class BindingRegistry
{
    private array $bindings = [];

    public function bind(string $abstract, callable|string|object $concrete): void
    {
        $this->bindings[$abstract] = $concrete;
    }

    public function hasBinding(string $abstract): bool
    {
        return isset($this->bindings[$abstract]);
    }

    public function getBinding(string $abstract): callable|string|object|null
    {
        return $this->bindings[$abstract] ?? null;
    }

    public function forget(string $abstract): void
    {
        unset($this->bindings[$abstract]);
    }

    public function flush(): void
    {
        $this->bindings = [];
    }

    public function getAllBindings(): array
    {
        return $this->bindings;
    }

    public function getAllKeys(): array
    {
        return array_keys($this->bindings);
    }
}
