feat: implement exception handling system with error context and policies
This commit is contained in:
35
src/Framework/ExceptionHandling/ExceptionHandlerManager.php
Normal file
35
src/Framework/ExceptionHandling/ExceptionHandlerManager.php
Normal 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(...));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user