class AmpHtmlResponseSubscriber in Accelerated Mobile Pages (AMP) 8
Same name and namespace in other branches
- 8.2 src/EventSubscriber/AmpHtmlResponseSubscriber.php \Drupal\amp\EventSubscriber\AmpHtmlResponseSubscriber
Response subscriber to handle amp HTML responses.
Hierarchy
- class \Drupal\amp\EventSubscriber\AmpHtmlResponseSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of AmpHtmlResponseSubscriber
1 string reference to 'AmpHtmlResponseSubscriber'
1 service uses AmpHtmlResponseSubscriber
File
- src/
EventSubscriber/ AmpHtmlResponseSubscriber.php, line 20 - Contains \Drupal\amp\EventSubscriber\AmpHtmlResponseSubscriber.
Namespace
Drupal\amp\EventSubscriberView source
class AmpHtmlResponseSubscriber implements EventSubscriberInterface {
/**
* The AMP HTML response markup processor service.
*
* @var \Drupal\amp\Render\AmpHtmlResponseMarkupProcessor
*/
protected $ampHtmlResponseMarkupProcessor;
/**
* The route amp context to determine whether a route is an amp one.
*
* @var \Drupal\amp\Routing\AmpContext
*/
protected $ampContext;
/**
* Constructs an AmpHtmlResponseSubscriber object.
*
* @param \Drupal\amp\Render\AmpHtmlResponseMarkupProcessor $amp_html_response_markup_processor
* The HTML response attachments processor service.
*/
public function __construct(AmpHtmlResponseMarkupProcessor $amp_html_response_markup_processor, AmpContext $amp_context) {
$this->ampHtmlResponseMarkupProcessor = $amp_html_response_markup_processor;
$this->ampContext = $amp_context;
}
/**
* Processes markup 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;
}
if ($this->ampContext
->isAmpRoute()) {
$event
->setResponse($this->ampHtmlResponseMarkupProcessor
->processMarkupToAmp($response));
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
// We want to run this as late as possible, after the HTML has been modified by all the Response listeners
$events[KernelEvents::RESPONSE][] = [
'onRespond',
-1024,
];
return $events;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AmpHtmlResponseSubscriber:: |
protected | property | The route amp context to determine whether a route is an amp one. | |
AmpHtmlResponseSubscriber:: |
protected | property | The AMP HTML response markup processor service. | |
AmpHtmlResponseSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
AmpHtmlResponseSubscriber:: |
public | function | Processes markup for HtmlResponse responses. | |
AmpHtmlResponseSubscriber:: |
public | function | Constructs an AmpHtmlResponseSubscriber object. |