Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 11 |
HtmlResponseSubscriber | |
0.00% |
0 / 1 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 11 |
__construct | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
onRespond | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 6 |
|||
getSubscribedEvents | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 3 |
<?php | |
/** | |
* @file | |
* Contains \Drupal\Core\EventSubscriber\HtmlResponseSubscriber. | |
*/ | |
namespace Drupal\Core\EventSubscriber; | |
use Drupal\Core\Render\HtmlResponse; | |
use Drupal\Core\Render\AttachmentsResponseProcessorInterface; | |
use Symfony\Component\HttpKernel\Event\FilterResponseEvent; | |
use Symfony\Component\HttpKernel\KernelEvents; | |
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | |
/** | |
* Response subscriber to handle HTML responses. | |
*/ | |
class HtmlResponseSubscriber implements EventSubscriberInterface { | |
/** | |
* The HTML response attachments processor service. | |
* | |
* @var \Drupal\Core\Render\AttachmentsResponseProcessorInterface | |
*/ | |
protected $htmlResponseAttachmentsProcessor; | |
/** | |
* Constructs a HtmlResponseSubscriber object. | |
* | |
* @param \Drupal\Core\Render\AttachmentsResponseProcessorInterface $html_response_attachments_processor | |
* The HTML response attachments processor service. | |
*/ | |
public function __construct(AttachmentsResponseProcessorInterface $html_response_attachments_processor) { | |
$this->htmlResponseAttachmentsProcessor = $html_response_attachments_processor; | |
} | |
/** | |
* Processes attachments for HtmlResponse responses. | |
* | |
* @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event | |
* The event to process. | |
*/ | |
public function onRespond(FilterResponseEvent $event) { | |
$response = $event->getResponse(); | |
if (!$response instanceof HtmlResponse) { | |
return; | |
} | |
$event->setResponse($this->htmlResponseAttachmentsProcessor->processAttachments($response)); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public static function getSubscribedEvents() { | |
$events[KernelEvents::RESPONSE][] = ['onRespond']; | |
return $events; | |
} | |
} |