annotate core/lib/Drupal/Core/EventSubscriber/RequestCloseSubscriber.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +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\Extension\ModuleHandlerInterface;
Chris@0 6 use Symfony\Component\HttpKernel\KernelEvents;
Chris@0 7 use Symfony\Component\HttpKernel\Event\PostResponseEvent;
Chris@0 8 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
Chris@0 9
Chris@0 10 /**
Chris@0 11 * Subscriber for all responses.
Chris@0 12 */
Chris@0 13 class RequestCloseSubscriber implements EventSubscriberInterface {
Chris@0 14
Chris@0 15 /**
Chris@0 16 * @var \Drupal\Core\Extension\ModuleHandlerInterface
Chris@0 17 */
Chris@0 18 protected $moduleHandler;
Chris@0 19
Chris@0 20 /**
Chris@0 21 * Constructs a new RequestCloseSubscriber instance.
Chris@0 22 *
Chris@0 23 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
Chris@0 24 * The module handler.
Chris@0 25 */
Chris@0 26 public function __construct(ModuleHandlerInterface $module_handler) {
Chris@0 27 $this->moduleHandler = $module_handler;
Chris@0 28 }
Chris@0 29
Chris@0 30 /**
Chris@0 31 * Performs end of request tasks.
Chris@0 32 *
Chris@0 33 * @todo The body of this function has just been copied almost verbatim from
Chris@0 34 * drupal_page_footer(). There's probably a lot in here that needs to get
Chris@0 35 * removed/changed. Also, if possible, do more light-weight shutdowns on
Chris@0 36 * AJAX requests.
Chris@0 37 *
Chris@0 38 * @param Symfony\Component\HttpKernel\Event\PostResponseEvent $event
Chris@0 39 * The Event to process.
Chris@0 40 */
Chris@0 41 public function onTerminate(PostResponseEvent $event) {
Chris@0 42 $this->moduleHandler->writeCache();
Chris@0 43 }
Chris@0 44
Chris@0 45 /**
Chris@0 46 * Registers the methods in this class that should be listeners.
Chris@0 47 *
Chris@0 48 * @return array
Chris@0 49 * An array of event listener definitions.
Chris@0 50 */
Chris@0 51 public static function getSubscribedEvents() {
Chris@0 52 $events[KernelEvents::TERMINATE][] = ['onTerminate', 100];
Chris@0 53
Chris@0 54 return $events;
Chris@0 55 }
Chris@0 56
Chris@0 57 }