Mercurial > hg > isophonics-drupal-site
annotate core/lib/Drupal/Core/EventSubscriber/HtmlResponseSubscriber.php @ 13:5fb285c0d0e3
Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've
been lucky to get away with this so far, as we don't support self-registration
which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5
was vulnerable to.
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:33:26 +0100 |
parents | 4c8ae668cc8c |
children |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 |
Chris@0 | 3 namespace Drupal\Core\EventSubscriber; |
Chris@0 | 4 |
Chris@0 | 5 use Drupal\Core\Render\HtmlResponse; |
Chris@0 | 6 use Drupal\Core\Render\AttachmentsResponseProcessorInterface; |
Chris@0 | 7 use Symfony\Component\HttpKernel\Event\FilterResponseEvent; |
Chris@0 | 8 use Symfony\Component\HttpKernel\KernelEvents; |
Chris@0 | 9 use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
Chris@0 | 10 |
Chris@0 | 11 /** |
Chris@0 | 12 * Response subscriber to handle HTML responses. |
Chris@0 | 13 */ |
Chris@0 | 14 class HtmlResponseSubscriber implements EventSubscriberInterface { |
Chris@0 | 15 |
Chris@0 | 16 /** |
Chris@0 | 17 * The HTML response attachments processor service. |
Chris@0 | 18 * |
Chris@0 | 19 * @var \Drupal\Core\Render\AttachmentsResponseProcessorInterface |
Chris@0 | 20 */ |
Chris@0 | 21 protected $htmlResponseAttachmentsProcessor; |
Chris@0 | 22 |
Chris@0 | 23 /** |
Chris@0 | 24 * Constructs a HtmlResponseSubscriber object. |
Chris@0 | 25 * |
Chris@0 | 26 * @param \Drupal\Core\Render\AttachmentsResponseProcessorInterface $html_response_attachments_processor |
Chris@0 | 27 * The HTML response attachments processor service. |
Chris@0 | 28 */ |
Chris@0 | 29 public function __construct(AttachmentsResponseProcessorInterface $html_response_attachments_processor) { |
Chris@0 | 30 $this->htmlResponseAttachmentsProcessor = $html_response_attachments_processor; |
Chris@0 | 31 } |
Chris@0 | 32 |
Chris@0 | 33 /** |
Chris@0 | 34 * Processes attachments for HtmlResponse responses. |
Chris@0 | 35 * |
Chris@0 | 36 * @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event |
Chris@0 | 37 * The event to process. |
Chris@0 | 38 */ |
Chris@0 | 39 public function onRespond(FilterResponseEvent $event) { |
Chris@0 | 40 $response = $event->getResponse(); |
Chris@0 | 41 if (!$response instanceof HtmlResponse) { |
Chris@0 | 42 return; |
Chris@0 | 43 } |
Chris@0 | 44 |
Chris@0 | 45 $event->setResponse($this->htmlResponseAttachmentsProcessor->processAttachments($response)); |
Chris@0 | 46 } |
Chris@0 | 47 |
Chris@0 | 48 /** |
Chris@0 | 49 * {@inheritdoc} |
Chris@0 | 50 */ |
Chris@0 | 51 public static function getSubscribedEvents() { |
Chris@0 | 52 $events[KernelEvents::RESPONSE][] = ['onRespond']; |
Chris@0 | 53 return $events; |
Chris@0 | 54 } |
Chris@0 | 55 |
Chris@0 | 56 } |