You are here

class ResponseSubscriber in Commerce Core 8.2

Response subscriber to add the "X-Commerce-Core" header tag.

Hierarchy

  • class \Drupal\commerce\EventSubscriber\ResponseSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of ResponseSubscriber

1 string reference to 'ResponseSubscriber'
commerce.services.yml in ./commerce.services.yml
commerce.services.yml
1 service uses ResponseSubscriber
commerce.response_subscriber in ./commerce.services.yml
Drupal\commerce\EventSubscriber\ResponseSubscriber

File

src/EventSubscriber/ResponseSubscriber.php, line 12

Namespace

Drupal\commerce\EventSubscriber
View source
class ResponseSubscriber implements EventSubscriberInterface {

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

  /**
   * Sets extra X-Commerce-Core header on successful responses.
   *
   * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
   *   The event to process.
   */
  public function onResponse(FilterResponseEvent $event) {
    if (!$event
      ->isMasterRequest()) {
      return;
    }
    $response = $event
      ->getResponse();
    $response->headers
      ->set('X-Commerce-Core', '2');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ResponseSubscriber::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
ResponseSubscriber::onResponse public function Sets extra X-Commerce-Core header on successful responses.