exceptionHandler($exception); } public function exceptionHandler(Throwable $e, bool $return = false): string { if (!$this->request instanceof Request) { $this->request = new Request(); } $handler = isset($this->handler[$this->environment->value]) ? $this->handler[$this->environment->value] : new Legacy(); $handler->report($e); ob_start(); $handler->render($this->request, $e); if ($return) { $output = ob_get_contents(); ob_end_clean(); return $output; } http_response_code(500); ob_end_flush(); $this->terminateApplicationImmediately(); return ''; } /** * Exit the application * * @codeCoverageIgnore */ protected function terminateApplicationImmediately(string $message = ''): void { echo $message; die(1); } public function getEnvironment(): Environment { return $this->environment; } public function setEnvironment(Environment $environment): void { $this->environment = $environment; } /** * @return HandlerInterface|HandlerInterface[] */ public function getHandler(Environment $environment = null): HandlerInterface|array { if (!is_null($environment)) { return $this->handler[$environment->value]; } return $this->handler; } public function setHandler(Environment $environment, HandlerInterface $handler): void { $this->handler[$environment->value] = $handler; } public function getRequest(): Request { return $this->request; } public function setRequest(Request $request): void { $this->request = $request; } }