diff --git a/src/Framework/ExceptionHandling/ExceptionHandlingInitializer.php b/src/Framework/ExceptionHandling/ExceptionHandlingInitializer.php index eca266b7..42665428 100644 --- a/src/Framework/ExceptionHandling/ExceptionHandlingInitializer.php +++ b/src/Framework/ExceptionHandling/ExceptionHandlingInitializer.php @@ -7,12 +7,15 @@ namespace App\Framework\ExceptionHandling; use App\Framework\Config\EnvironmentType; use App\Framework\Console\ConsoleOutput; use App\Framework\Context\ExecutionContext; +use App\Framework\ErrorAggregation\ErrorAggregatorInterface; use App\Framework\DI\Container; use App\Framework\DI\Initializer; +use App\Framework\ExceptionHandling\Audit\ExceptionAuditLogger; use App\Framework\ExceptionHandling\Context\ExceptionContextProvider; use App\Framework\ExceptionHandling\Reporter\LogReporter; use App\Framework\ExceptionHandling\Reporter\Reporter; use App\Framework\ExceptionHandling\Reporter\ReporterRegistry; +use App\Framework\ExceptionHandling\RateLimit\ExceptionRateLimiter; use App\Framework\ExceptionHandling\Strategy\ErrorPolicyResolver; use App\Framework\Logging\Logger; use App\Framework\View\Engine; @@ -52,8 +55,25 @@ final readonly class ExceptionHandlingInitializer isDebugMode: $isDebugMode )); - // ErrorKernel - can be autowired (optional dependencies are nullable) - // No explicit binding needed - container will autowire + // ErrorKernel - bind singleton with explicit debug flag so HTTP renderers respect environment + $container->singleton(ErrorKernel::class, static function (Container $c) use ($isDebugMode, $executionContext, $consoleOutput): ErrorKernel { + $errorAggregator = $c->has(ErrorAggregatorInterface::class) ? $c->get(ErrorAggregatorInterface::class) : null; + $contextProvider = $c->has(ExceptionContextProvider::class) ? $c->get(ExceptionContextProvider::class) : null; + $auditLogger = $c->has(ExceptionAuditLogger::class) ? $c->get(ExceptionAuditLogger::class) : null; + $rateLimiter = $c->has(ExceptionRateLimiter::class) ? $c->get(ExceptionRateLimiter::class) : null; + + return new ErrorKernel( + rendererFactory: $c->get(ErrorRendererFactory::class), + reporter: $c->get(Reporter::class), + errorAggregator: $errorAggregator, + contextProvider: $contextProvider, + auditLogger: $auditLogger, + rateLimiter: $rateLimiter, + executionContext: $executionContext, + consoleOutput: $consoleOutput, + isDebugMode: $isDebugMode + ); + }); // GlobalExceptionHandler - can be autowired // No explicit binding needed - container will autowire