class MaintenanceModeSubscriber in Maintenance 200 8
Hierarchy
- class \Drupal\maintenance200\EventSubscriber\MaintenanceModeSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of MaintenanceModeSubscriber
1 string reference to 'MaintenanceModeSubscriber'
1 service uses MaintenanceModeSubscriber
File
- src/
EventSubscriber/ MaintenanceModeSubscriber.php, line 17
Namespace
Drupal\maintenance200\EventSubscriberView source
class MaintenanceModeSubscriber implements EventSubscriberInterface {
/**
* @inheritDoc
*/
public function __construct(ConfigFactoryInterface $configFactory, MaintenanceModeInterface $maintenanceMode, AccountInterface $account) {
$this->config = $configFactory
->get('maintenance200.settings');
$this->maintenanceMode = $maintenanceMode;
$this->account = $account;
}
/**
* Respond to RESPONSE Kernel event by setting status code if in maintenance.
*
*/
public function onKernelResponse(FilterResponseEvent $event) {
if ($this->config
->get('maintenance200_enabled')) {
$status_code = $this->config
->get('maintenance200_status_code');
$request = $event
->getRequest();
$routeMatch = RouteMatch::createFromRequest($request);
$response = $event
->getResponse();
if ($this->maintenanceMode
->applies($routeMatch) && !$this->maintenanceMode
->exempt($this->account)) {
$response
->setStatusCode($status_code);
$event
->setResponse($response);
}
}
}
/**
* @inheritDoc
*/
public static function getSubscribedEvents() {
$events[KernelEvents::RESPONSE][] = [
'onKernelResponse',
31,
];
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MaintenanceModeSubscriber:: |
public static | function | @inheritDoc | |
MaintenanceModeSubscriber:: |
public | function | Respond to RESPONSE Kernel event by setting status code if in maintenance. | |
MaintenanceModeSubscriber:: |
public | function | @inheritDoc |