feat: implement exception handling system with error context and policies
This commit is contained in:
45
src/Framework/ExceptionHandling/Strategy/LenientPolicy.php
Normal file
45
src/Framework/ExceptionHandling/Strategy/LenientPolicy.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Framework\ExceptionHandling\Strategy;
|
||||
|
||||
use App\Framework\ExceptionHandling\ErrorContext;
|
||||
use App\Framework\ExceptionHandling\ErrorDecision;
|
||||
use App\Framework\ExceptionHandling\ErrorHandlerStrategy;
|
||||
use App\Framework\Logging\Logger;
|
||||
use App\Framework\Logging\ValueObjects\LogContext;
|
||||
use ErrorException;
|
||||
|
||||
final readonly class LenientPolicy implements ErrorHandlerStrategy
|
||||
{
|
||||
public function __construct(private Logger $logger)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function handle(ErrorContext $context): ErrorDecision
|
||||
{
|
||||
if($context->isDeprecation()) {
|
||||
$this->logger->notice("[Deprecation] {$context->message}",
|
||||
LogContext::withData(
|
||||
[
|
||||
'file' => $context->file,
|
||||
'line' => $context->line]
|
||||
));
|
||||
|
||||
return ErrorDecision::HANDLED;
|
||||
}
|
||||
|
||||
if($context->isFatal()) {
|
||||
throw new ErrorException(
|
||||
$context->message,
|
||||
0,
|
||||
$context->severity,
|
||||
$context->file,
|
||||
$context->line
|
||||
);
|
||||
}
|
||||
|
||||
return ErrorDecision::DEFER;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user