Mercurial > hg > isophonics-drupal-site
comparison core/lib/Drupal/Core/EventSubscriber/RequestCloseSubscriber.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Core\EventSubscriber; | |
4 | |
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; | |
9 | |
10 /** | |
11 * Subscriber for all responses. | |
12 */ | |
13 class RequestCloseSubscriber implements EventSubscriberInterface { | |
14 | |
15 /** | |
16 * @var \Drupal\Core\Extension\ModuleHandlerInterface | |
17 */ | |
18 protected $moduleHandler; | |
19 | |
20 /** | |
21 * Constructs a new RequestCloseSubscriber instance. | |
22 * | |
23 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler | |
24 * The module handler. | |
25 */ | |
26 public function __construct(ModuleHandlerInterface $module_handler) { | |
27 $this->moduleHandler = $module_handler; | |
28 } | |
29 | |
30 /** | |
31 * Performs end of request tasks. | |
32 * | |
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 | |
36 * AJAX requests. | |
37 * | |
38 * @param Symfony\Component\HttpKernel\Event\PostResponseEvent $event | |
39 * The Event to process. | |
40 */ | |
41 public function onTerminate(PostResponseEvent $event) { | |
42 $this->moduleHandler->writeCache(); | |
43 } | |
44 | |
45 /** | |
46 * Registers the methods in this class that should be listeners. | |
47 * | |
48 * @return array | |
49 * An array of event listener definitions. | |
50 */ | |
51 public static function getSubscribedEvents() { | |
52 $events[KernelEvents::TERMINATE][] = ['onTerminate', 100]; | |
53 | |
54 return $events; | |
55 } | |
56 | |
57 } |