class Fast404ExceptionHtmlSubscriber in Drupal 8
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/EventSubscriber/Fast404ExceptionHtmlSubscriber.php \Drupal\Core\EventSubscriber\Fast404ExceptionHtmlSubscriber
- 10 core/lib/Drupal/Core/EventSubscriber/Fast404ExceptionHtmlSubscriber.php \Drupal\Core\EventSubscriber\Fast404ExceptionHtmlSubscriber
High-performance 404 exception subscriber.
This subscriber will return a minimalist 404 response for HTML requests without running a full page theming operation.
Hierarchy
- class \Drupal\Core\EventSubscriber\HttpExceptionSubscriberBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
- class \Drupal\Core\EventSubscriber\Fast404ExceptionHtmlSubscriber
Expanded class hierarchy of Fast404ExceptionHtmlSubscriber
1 string reference to 'Fast404ExceptionHtmlSubscriber'
- core.services.yml in core/
core.services.yml - core/core.services.yml
1 service uses Fast404ExceptionHtmlSubscriber
File
- core/
lib/ Drupal/ Core/ EventSubscriber/ Fast404ExceptionHtmlSubscriber.php, line 17
Namespace
Drupal\Core\EventSubscriberView source
class Fast404ExceptionHtmlSubscriber extends HttpExceptionSubscriberBase {
/**
* The HTTP kernel.
*
* @var \Symfony\Component\HttpKernel\HttpKernelInterface
*/
protected $httpKernel;
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* Constructs a new Fast404ExceptionHtmlSubscriber.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration factory.
* @param \Symfony\Component\HttpKernel\HttpKernelInterface $http_kernel
* The HTTP Kernel service.
*/
public function __construct(ConfigFactoryInterface $config_factory, HttpKernelInterface $http_kernel) {
$this->configFactory = $config_factory;
$this->httpKernel = $http_kernel;
}
/**
* {@inheritdoc}
*/
protected static function getPriority() {
// A very high priority so that it can take precedent over anything else,
// and thus be fast.
return 200;
}
/**
* {@inheritdoc}
*/
protected function getHandledFormats() {
return [
'html',
];
}
/**
* Handles a 404 error for HTML.
*
* @param \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event
* The event to process.
*/
public function on404(GetResponseForExceptionEvent $event) {
$request = $event
->getRequest();
$config = $this->configFactory
->get('system.performance');
$exclude_paths = $config
->get('fast_404.exclude_paths');
if ($config
->get('fast_404.enabled') && $exclude_paths && !preg_match($exclude_paths, $request
->getPathInfo())) {
$fast_paths = $config
->get('fast_404.paths');
if ($fast_paths && preg_match($fast_paths, $request
->getPathInfo())) {
$fast_404_html = strtr($config
->get('fast_404.html'), [
'@path' => Html::escape($request
->getUri()),
]);
$response = new Response($fast_404_html, Response::HTTP_NOT_FOUND);
$event
->setResponse($response);
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Fast404ExceptionHtmlSubscriber:: |
protected | property | The config factory. | |
Fast404ExceptionHtmlSubscriber:: |
protected | property | The HTTP kernel. | |
Fast404ExceptionHtmlSubscriber:: |
protected | function |
Specifies the request formats this subscriber will respond to. Overrides HttpExceptionSubscriberBase:: |
|
Fast404ExceptionHtmlSubscriber:: |
protected static | function |
Specifies the priority of all listeners in this class. Overrides HttpExceptionSubscriberBase:: |
|
Fast404ExceptionHtmlSubscriber:: |
public | function | Handles a 404 error for HTML. | |
Fast404ExceptionHtmlSubscriber:: |
public | function | Constructs a new Fast404ExceptionHtmlSubscriber. | |
HttpExceptionSubscriberBase:: |
public static | function | Registers the methods in this class that should be listeners. | |
HttpExceptionSubscriberBase:: |
public | function | Handles errors for this subscriber. |