feat: implement exception handling system with error context and policies

This commit is contained in:
2025-11-01 15:46:43 +01:00
parent f3440dff0d
commit a441da37f6
35 changed files with 920 additions and 88 deletions

View File

@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace App\Framework\ExceptionHandling;
use App\Framework\Config\EnvironmentType;
use App\Framework\ExceptionHandling\Strategy\ErrorPolicyResolver;
final readonly class ExceptionHandlerManager
{
public function __construct()
{
$resolver = new ErrorPolicyResolver();
$this->registerErrorHandler(new ErrorHandler($resolver->resolve(EnvironmentType::DEV)));
$this->registerExceptionHandler(new GlobalExceptionHandler());
$this->registerShutdownHandler(new ShutdownHandler());
}
public function registerExceptionHandler(ExceptionHandler $handler): void
{
set_exception_handler($handler->handle(...));
}
private function registerErrorHandler(ErrorHandler $handler):void
{
set_error_handler($handler->handle(...), E_ALL);
}
public function registerShutdownHandler(ShutdownHandler $handler): void
{
register_shutdown_function($handler->handle(...));
}
}