You are here

class AcsfMaintenanceModeSubscriber in Acquia Cloud Site Factory Connector 8.2

Same name and namespace in other branches
  1. 8 src/EventSubscriber/AcsfMaintenanceModeSubscriber.php \Drupal\acsf\EventSubscriber\AcsfMaintenanceModeSubscriber

Response subscriber to add SF maintenance mode header.

Hierarchy

Expanded class hierarchy of AcsfMaintenanceModeSubscriber

1 string reference to 'AcsfMaintenanceModeSubscriber'
acsf.services.yml in ./acsf.services.yml
acsf.services.yml
1 service uses AcsfMaintenanceModeSubscriber
acsf.maintenance_mode_subscriber in ./acsf.services.yml
Drupal\acsf\EventSubscriber\AcsfMaintenanceModeSubscriber

File

src/EventSubscriber/AcsfMaintenanceModeSubscriber.php, line 13

Namespace

Drupal\acsf\EventSubscriber
View source
class AcsfMaintenanceModeSubscriber implements EventSubscriberInterface {

  /**
   * Name of ACSF maintenance mode's response header.
   */
  const HEADER = 'X-SF-Maintenance';

  /**
   * The state.
   *
   * @var \Drupal\Core\State\StateInterface
   */
  protected $state;

  /**
   * Constructs a new AcsfMaintenanceModeSubscriber.
   *
   * @param \Drupal\Core\State\StateInterface $state
   *   The state.
   */
  public function __construct(StateInterface $state) {
    $this->state = $state;
  }

  /**
   * Sets SF maintenance mode header (on successful responses).
   *
   * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
   *   The event to process.
   */
  public function onRespond(FilterResponseEvent $event) {
    if (!$event
      ->isMasterRequest()) {
      return;
    }
    if ($this->state
      ->get('system.maintenance_mode')) {
      $response = $event
        ->getResponse();
      $response->headers
        ->set(self::HEADER, 'enabled');
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[KernelEvents::RESPONSE][] = [
      'onRespond',
    ];
    return $events;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AcsfMaintenanceModeSubscriber::$state protected property The state.
AcsfMaintenanceModeSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
AcsfMaintenanceModeSubscriber::HEADER constant Name of ACSF maintenance mode's response header.
AcsfMaintenanceModeSubscriber::onRespond public function Sets SF maintenance mode header (on successful responses).
AcsfMaintenanceModeSubscriber::__construct public function Constructs a new AcsfMaintenanceModeSubscriber.