Chris@0: configFactory = $config_factory; Chris@0: $this->httpKernel = $http_kernel; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: protected static function getPriority() { Chris@0: // A very high priority so that it can take precedent over anything else, Chris@0: // and thus be fast. Chris@0: return 200; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: protected function getHandledFormats() { Chris@0: return ['html']; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Handles a 404 error for HTML. Chris@0: * Chris@0: * @param \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event Chris@0: * The event to process. Chris@0: */ Chris@0: public function on404(GetResponseForExceptionEvent $event) { Chris@0: $request = $event->getRequest(); Chris@0: Chris@0: $config = $this->configFactory->get('system.performance'); Chris@0: $exclude_paths = $config->get('fast_404.exclude_paths'); Chris@0: if ($config->get('fast_404.enabled') && $exclude_paths && !preg_match($exclude_paths, $request->getPathInfo())) { Chris@0: $fast_paths = $config->get('fast_404.paths'); Chris@0: if ($fast_paths && preg_match($fast_paths, $request->getPathInfo())) { Chris@0: $fast_404_html = strtr($config->get('fast_404.html'), ['@path' => Html::escape($request->getUri())]); Chris@0: $response = new Response($fast_404_html, Response::HTTP_NOT_FOUND); Chris@0: $event->setResponse($response); Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: }