factory = $factory; $this->view = $view; } public function __invoke(Request $request, Handler $handler): Response { try { return $handler->handle($request); } catch (HttpNotFoundException $e) { $page = $request->getUri()->getPath(); $response = $this->factory->createResponse(404); return $this->view->render($response, '404', compact('page')); } } }