3 namespace Drupal\Core\EventSubscriber;
5 use Drupal\Core\Extension\ModuleHandlerInterface;
6 use Symfony\Component\HttpKernel\KernelEvents;
7 use Symfony\Component\HttpKernel\Event\PostResponseEvent;
8 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
11 * Subscriber for all responses.
13 class RequestCloseSubscriber implements EventSubscriberInterface {
16 * @var \Drupal\Core\Extension\ModuleHandlerInterface
18 protected $moduleHandler;
21 * Constructs a new RequestCloseSubscriber instance.
23 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
26 public function __construct(ModuleHandlerInterface $module_handler) {
27 $this->moduleHandler = $module_handler;
31 * Performs end of request tasks.
33 * @todo The body of this function has just been copied almost verbatim from
34 * drupal_page_footer(). There's probably a lot in here that needs to get
35 * removed/changed. Also, if possible, do more light-weight shutdowns on
38 * @param Symfony\Component\HttpKernel\Event\PostResponseEvent $event
39 * The Event to process.
41 public function onTerminate(PostResponseEvent $event) {
42 $this->moduleHandler->writeCache();
46 * Registers the methods in this class that should be listeners.
49 * An array of event listener definitions.
51 public static function getSubscribedEvents() {
52 $events[KernelEvents::TERMINATE][] = ['onTerminate', 100];