Untitled

 avatar
unknown
php
6 days ago
538 B
6
Indexable
<?php
final class ExceptionHandlerResolver
{
    /** @var List<ExceptionHandler> */
    private array $handlers = [];

    public function __construct(
        private readonly Arr $arr
    ) {}

    public function addHandler(ExceptionHandler $handler): void
    {
        $this->handlers[] = $handler;
    }

    private function getHandler(Throwable $exception): ?ExceptionHandler
    {
        return $this->arr::first(
            $this->handlers,
            static fn ($handler) => $handler->handles($exception)
        );
    }
}
Editor is loading...
Leave a Comment