gacela-project /
router
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Gacela\Router\Configure; |
||
| 6 | |||
| 7 | use Exception; |
||
| 8 | use Gacela\Router\Exceptions\NotFound404Exception; |
||
| 9 | use Gacela\Router\Handlers\FallbackExceptionHandler; |
||
| 10 | use Gacela\Router\Handlers\NotFound404ExceptionHandler; |
||
| 11 | |||
| 12 | final class Handlers |
||
| 13 | { |
||
| 14 | /** @var array<class-string, callable|class-string> */ |
||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
| 15 | private array $handlers = []; |
||
| 16 | |||
| 17 | 112 | public function __construct() |
|
| 18 | { |
||
| 19 | 112 | $this->addBuiltInHandlers(); |
|
| 20 | } |
||
| 21 | /** |
||
| 22 | * @param class-string<Exception> $exception |
||
|
0 ignored issues
–
show
|
|||
| 23 | * @param callable|class-string $handler |
||
| 24 | */ |
||
| 25 | 112 | public function handle(string $exception, callable|string $handler): self |
|
| 26 | { |
||
| 27 | 112 | $this->handlers[$exception] = $handler; |
|
| 28 | 112 | return $this; |
|
| 29 | } |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @return array<class-string, callable|class-string> |
||
|
0 ignored issues
–
show
|
|||
| 33 | */ |
||
| 34 | 18 | public function getAllHandlers(): array |
|
| 35 | { |
||
| 36 | 18 | return $this->handlers; |
|
| 37 | } |
||
| 38 | |||
| 39 | 112 | private function addBuiltInHandlers(): void |
|
| 40 | { |
||
| 41 | 112 | $this->handle(NotFound404Exception::class, NotFound404ExceptionHandler::class); |
|
| 42 | 112 | $this->handle(Exception::class, FallbackExceptionHandler::class); |
|
| 43 | } |
||
| 44 | } |
||
| 45 |