Mediator

Mediator registers PHP's error, exception, and shutdown handlers, and renders whatever reaches them — a development renderer favoring diagnosis, or a production renderer favoring safety. See Request/Response Lifecycle for where it sits in a real request.

Setup

Mediator::configure(bool $debug, ?Psr\Log\LoggerInterface $logger = null): void
Mediator::register(): void

Called once from config/bootstrap.php, before any request is handled:

Mediator::configure(debug: $env('ENV_MODE', 'production') !== 'production', logger: new Logger());
Mediator::register();

What each renderer shows

  • Development ($debug = true) — exception class, message, file/line, a source excerpt around the failing line, the full stack trace, and the previous-exception chain if one exists. Status 500.
  • Production ($debug = false) — no internals: a generic message, an incident ID, status 500. The full exception is still recorded through the configured logger either way.

Calling it directly

Mediator::handleException(Throwable $exception, ?Request $request = null): Response

Callable outside the global-handler machinery — existing call sites in DB and Session hand Mediator a caught exception directly, the same way the global handler would have reached it.

Next steps