v1/vendor/chi-teck/drupal-code-generator/templates/service/event-subscriber/event-subscriber.twig

71 lines
1.5 KiB
Twig

{% import '_lib/di.twig' as di %}
<?php
namespace Drupal\{{ machine_name }}\EventSubscriber;
{% sort %}
{% if services %}
{{ di.use(services) }}
{% endif %}
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
{% endsort %}
/**
* {{ name }} event subscriber.
*/
class {{ class }} implements EventSubscriberInterface {
{% if services %}
{{ di.properties(services) }}
/**
* Constructs {{ class|article }} object.
*
{{ di.annotation(services) }}
*/
public function __construct({{ di.signature(services) }}) {
{{ di.assignment(services) }}
}
{% endif %}
/**
* Kernel request event handler.
*
* @param \Symfony\Component\HttpKernel\Event\RequestEvent $event
* Response event.
*/
public function onKernelRequest(RequestEvent $event) {
// @todo Place code here.
{% if SUT_TEST %}
$this->messenger->addStatus(__FUNCTION__);
{% endif %}
}
/**
* Kernel response event handler.
*
* @param \Symfony\Component\HttpKernel\Event\ResponseEvent $event
* Response event.
*/
public function onKernelResponse(ResponseEvent $event) {
// @todo Place code here.
{% if SUT_TEST %}
$this->messenger->addStatus(__FUNCTION__);
{% endif %}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
KernelEvents::REQUEST => ['onKernelRequest'],
KernelEvents::RESPONSE => ['onKernelResponse'],
];
}
}