class Fast404EventSubscriber in Fast 404 8.2
Same name and namespace in other branches
- 8 src/EventSubscriber/Fast404EventSubscriber.php \Drupal\fast404\EventSubscriber\Fast404EventSubscriber
Class Fast404EventSubscriber.
@package Drupal\fast404\EventSubscriber
Hierarchy
- class \Drupal\fast404\EventSubscriber\Fast404EventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of Fast404EventSubscriber
1 file declares its use of Fast404EventSubscriber
- Fast404EventSubscriberTest.php in tests/
src/ Unit/ Fast404EventSubscriberTest.php
1 string reference to 'Fast404EventSubscriber'
1 service uses Fast404EventSubscriber
File
- src/
EventSubscriber/ Fast404EventSubscriber.php, line 19
Namespace
Drupal\fast404\EventSubscriberView source
class Fast404EventSubscriber implements EventSubscriberInterface {
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
public $requestStack;
/**
* Constructs a new Fast404EventSubscriber instance.
*
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
* The Request Stack.
*/
public function __construct(RequestStack $request_stack) {
$this->requestStack = $request_stack;
}
/**
* Ensures Fast 404 output returned if applicable.
*/
public function onKernelRequest(GetResponseEvent $event) {
$request = $this->requestStack
->getCurrentRequest();
$fast_404 = new Fast404($request);
$fast_404
->extensionCheck();
if ($fast_404
->isPathBlocked()) {
$event
->setResponse($fast_404
->response(TRUE));
}
$fast_404
->pathCheck();
if ($fast_404
->isPathBlocked()) {
$event
->setResponse($fast_404
->response(TRUE));
}
}
/**
* Ensures Fast 404 output returned upon NotFoundHttpException.
*
* @param \Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent $event
* The response for exception event.
*/
public function onNotFoundException(GetResponseForExceptionEvent $event) {
// Check to see if we will completely replace the Drupal 404 page.
if (Settings::get('fast404_not_found_exception', FALSE)) {
if ($event
->getException() instanceof NotFoundHttpException) {
$fast_404 = new Fast404($event
->getRequest());
$event
->setResponse($fast_404
->response(TRUE));
}
}
}
/**
* Registers the methods in this class that should be listeners.
*
* @return array
* An array of event listener definitions.
*/
public static function getSubscribedEvents() {
$events[KernelEvents::REQUEST][] = [
'onKernelRequest',
100,
];
$events[KernelEvents::EXCEPTION][] = [
'onNotFoundException',
0,
];
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Fast404EventSubscriber:: |
public | property | The request stack. | |
Fast404EventSubscriber:: |
public static | function | Registers the methods in this class that should be listeners. | |
Fast404EventSubscriber:: |
public | function | Ensures Fast 404 output returned if applicable. | |
Fast404EventSubscriber:: |
public | function | Ensures Fast 404 output returned upon NotFoundHttpException. | |
Fast404EventSubscriber:: |
public | function | Constructs a new Fast404EventSubscriber instance. |