You are here

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'
maintenance200.services.yml in ./maintenance200.services.yml
maintenance200.services.yml
1 service uses MaintenanceModeSubscriber
maintenance_mode_200_subscriber in ./maintenance200.services.yml
\Drupal\maintenance200\EventSubscriber\MaintenanceModeSubscriber

File

src/EventSubscriber/MaintenanceModeSubscriber.php, line 17

Namespace

Drupal\maintenance200\EventSubscriber
View 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

Namesort descending Modifiers Type Description Overrides
MaintenanceModeSubscriber::getSubscribedEvents public static function @inheritDoc
MaintenanceModeSubscriber::onKernelResponse public function Respond to RESPONSE Kernel event by setting status code if in maintenance.
MaintenanceModeSubscriber::__construct public function @inheritDoc