Mercurial > hg > isophonics-drupal-site
comparison core/lib/Drupal/Core/EventSubscriber/PsrResponseSubscriber.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Core\EventSubscriber; | |
4 | |
5 use Psr\Http\Message\ResponseInterface; | |
6 | |
7 use Symfony\Bridge\PsrHttpMessage\HttpFoundationFactoryInterface; | |
8 use Symfony\Component\EventDispatcher\EventSubscriberInterface; | |
9 use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; | |
10 use Symfony\Component\HttpKernel\KernelEvents; | |
11 | |
12 /** | |
13 * Response subscriber for handling PSR-7 responses. | |
14 */ | |
15 class PsrResponseSubscriber implements EventSubscriberInterface { | |
16 | |
17 /** | |
18 * The httpFoundation factory. | |
19 * | |
20 * @var \Symfony\Bridge\PsrHttpMessage\HttpFoundationFactoryInterface | |
21 */ | |
22 protected $httpFoundationFactory; | |
23 | |
24 /** | |
25 * Constructs a new PathRootsSubscriber instance. | |
26 * | |
27 * @param \Symfony\Bridge\PsrHttpMessage\HttpFoundationFactoryInterface $http_foundation_factory | |
28 * The httpFoundation factory. | |
29 */ | |
30 public function __construct(HttpFoundationFactoryInterface $http_foundation_factory) { | |
31 $this->httpFoundationFactory = $http_foundation_factory; | |
32 } | |
33 | |
34 /** | |
35 * Converts a PSR-7 response to a Symfony response. | |
36 * | |
37 * @param \Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent $event | |
38 * The Event to process. | |
39 */ | |
40 public function onKernelView(GetResponseForControllerResultEvent $event) { | |
41 $controller_result = $event->getControllerResult(); | |
42 | |
43 if ($controller_result instanceof ResponseInterface) { | |
44 $event->setResponse($this->httpFoundationFactory->createResponse($controller_result)); | |
45 } | |
46 | |
47 } | |
48 | |
49 /** | |
50 * {@inheritdoc} | |
51 */ | |
52 public static function getSubscribedEvents() { | |
53 $events[KernelEvents::VIEW][] = ['onKernelView']; | |
54 return $events; | |
55 } | |
56 | |
57 } |