public function __invoke(Request $request, Response $response) { $data = ['uri' => $request->getUri()->getPath(), 'contact' => $this->container->router->pathFor('contact')]; // We need a new response body $headers = new Headers(['Content-Type' => 'text/html; charset=UTF-8']); $res = new Response(404, $headers); // Start buffering ob_start(); $view = new View($res); $view->setTemplate('errors.404'); $view->render($data); // Get the buffer output $content = ob_get_clean(); return $res->write($content); }
/** * __invoke magical method * * @param ServerRequestInterface $request A valid PSR-7 Request object that inherits the `ServerRequestInterface` interface * @param ResponseInterface $response A valid PSR-7 Response object that inherits `ResponseInterface` interface * @param Exception $exception Exception to be handled * @return ResponseInterface object */ public function __invoke(ServerRequestInterface $request, ResponseInterface $response, Exception $exception) { // We need a new response body $headers = new Headers(['Content-Type' => 'text/html; charset=UTF-8']); $res = new Response(500, $headers); $handler = new Handler($exception); // Start buffering ob_start(); // Create a new View instance just for this page $view = new View($res); $view->setTemplate('errors.exhan'); $view->render($handler->getExceptionData()); // Get the buffer output $content = ob_get_clean(); return $res->write($content); }