/** * Handle exception * * @param \Exception $e * @return \Psr\Http\Message\ResponseInterface */ public function handle(\Exception $e) { $response = $this->provider->getResponse(); $response = $response->withStatus(500); $message = 'Internal Server Error'; $view = $this->provider->getView(); if ($this->provider->getConfig('display_exceptions')) { $view->exception = $e; } $view->message = $message; $config = $this->provider->getConfig(); if (isset($config['templates']['template_error'])) { $result = $view->renderFile($config['templates']['template_error']); } else { if (isset($view->exception)) { $body = sprintf("<h1>An error occurred</h1><h2>%s</h2><h3>Message</h3><p>%s</p><h3>Stack trace</h3><p>%s</p>", $message, $e->getMessage(), $e->getTraceAsString()); } else { $body = sprintf("<h1>An error occurred</h1><h2>%s</h2>", $message); } $result = sprintf("<html><head><title>%s</title><style>body {font-family: Helvetica,Arial,sans-serif;font-size: 20px;line-height: 28px;padding:20px;}</style></head><body>%s</body></html>", 'Tlumx application: ' . $message, $body); } $response->getBody()->write($result); $response->withHeader('Content-Type', 'text/html'); return $response; }
/** * Handle * * @param array $allowedMethods * @return \Psr\Http\Message\ResponseInterface */ public function handle(array $allowedMethods = []) { $response = $this->provider->getResponse(); if (empty($allowedMethods)) { $response = $response->withStatus(404); $message = 'Page not found'; } else { $response = $response->withStatus(405); $message = 'Method Not Allowed'; } $config = $this->provider->getConfig(); if (isset($config['templates']['template_404'])) { $view = $this->provider->getView(); $view->message = $message; $result = $view->renderFile($config['templates']['template_404']); } else { $body = sprintf("<h1>An error occurred</h1><h2>%s</h2>", $message); $result = sprintf("<html><head><title>%s</title><style>body {font-family: Helvetica,Arial,sans-serif;font-size: 20px;line-height: 28px;padding:20px;}</style></head><body>%s</body></html>", 'Tlumx application: ' . $message, $body); } $response->getBody()->write($result); $response->withHeader('Content-Type', 'text/html'); return $response; }
/** * Get config * * @param string|null $option * @return mixed */ public function getConfig($option = null) { return $this->serviceProvider->getConfig($option); }