class PsrResponseSubscriber

Same name in other branches
  1. 9 core/lib/Drupal/Core/EventSubscriber/PsrResponseSubscriber.php \Drupal\Core\EventSubscriber\PsrResponseSubscriber
  2. 8.9.x core/lib/Drupal/Core/EventSubscriber/PsrResponseSubscriber.php \Drupal\Core\EventSubscriber\PsrResponseSubscriber
  3. 11.x core/lib/Drupal/Core/EventSubscriber/PsrResponseSubscriber.php \Drupal\Core\EventSubscriber\PsrResponseSubscriber

Response subscriber for handling PSR-7 responses.

Hierarchy

  • class \Drupal\Core\EventSubscriber\PsrResponseSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of PsrResponseSubscriber

1 file declares its use of PsrResponseSubscriber
PsrResponseSubscriberTest.php in core/tests/Drupal/Tests/Core/EventSubscriber/PsrResponseSubscriberTest.php
1 string reference to 'PsrResponseSubscriber'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses PsrResponseSubscriber
psr_response_view_subscriber in core/core.services.yml
Drupal\Core\EventSubscriber\PsrResponseSubscriber

File

core/lib/Drupal/Core/EventSubscriber/PsrResponseSubscriber.php, line 15

Namespace

Drupal\Core\EventSubscriber
View source
class PsrResponseSubscriber implements EventSubscriberInterface {
    
    /**
     * The httpFoundation factory.
     *
     * @var \Symfony\Bridge\PsrHttpMessage\HttpFoundationFactoryInterface
     */
    protected $httpFoundationFactory;
    
    /**
     * Constructs a new PathRootsSubscriber instance.
     *
     * @param \Symfony\Bridge\PsrHttpMessage\HttpFoundationFactoryInterface $http_foundation_factory
     *   The httpFoundation factory.
     */
    public function __construct(HttpFoundationFactoryInterface $http_foundation_factory) {
        $this->httpFoundationFactory = $http_foundation_factory;
    }
    
    /**
     * Converts a PSR-7 response to a Symfony response.
     *
     * @param \Symfony\Component\HttpKernel\Event\ViewEvent $event
     *   The Event to process.
     */
    public function onKernelView(ViewEvent $event) {
        $controller_result = $event->getControllerResult();
        if ($controller_result instanceof ResponseInterface) {
            $event->setResponse($this->httpFoundationFactory
                ->createResponse($controller_result));
        }
    }
    
    /**
     * {@inheritdoc}
     */
    public static function getSubscribedEvents() : array {
        $events[KernelEvents::VIEW][] = [
            'onKernelView',
        ];
        return $events;
    }

}

Members

Title Sort descending Modifiers Object type Summary
PsrResponseSubscriber::$httpFoundationFactory protected property The httpFoundation factory.
PsrResponseSubscriber::getSubscribedEvents public static function
PsrResponseSubscriber::onKernelView public function Converts a PSR-7 response to a Symfony response.
PsrResponseSubscriber::__construct public function Constructs a new PathRootsSubscriber instance.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.