class RequestCloseSubscriber

Same name in other branches
  1. 9 core/lib/Drupal/Core/EventSubscriber/RequestCloseSubscriber.php \Drupal\Core\EventSubscriber\RequestCloseSubscriber
  2. 8.9.x core/lib/Drupal/Core/EventSubscriber/RequestCloseSubscriber.php \Drupal\Core\EventSubscriber\RequestCloseSubscriber
  3. 11.x core/lib/Drupal/Core/EventSubscriber/RequestCloseSubscriber.php \Drupal\Core\EventSubscriber\RequestCloseSubscriber

Subscriber for all responses.

Hierarchy

  • class \Drupal\Core\EventSubscriber\RequestCloseSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of RequestCloseSubscriber

File

core/lib/Drupal/Core/EventSubscriber/RequestCloseSubscriber.php, line 13

Namespace

Drupal\Core\EventSubscriber
View source
class RequestCloseSubscriber implements EventSubscriberInterface {
    
    /**
     * @var \Drupal\Core\Extension\ModuleHandlerInterface
     */
    protected $moduleHandler;
    
    /**
     * Constructs a new RequestCloseSubscriber instance.
     *
     * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
     *   The module handler.
     */
    public function __construct(ModuleHandlerInterface $module_handler) {
        $this->moduleHandler = $module_handler;
    }
    
    /**
     * Performs end of request tasks.
     *
     * @todo The body of this function has just been copied almost verbatim from
     *   drupal_page_footer(). There's probably a lot in here that needs to get
     *   removed/changed. Also, if possible, do more light-weight shutdowns on
     *   AJAX requests.
     *
     * @param \Symfony\Component\HttpKernel\Event\TerminateEvent $event
     *   The Event to process.
     */
    public function onTerminate(TerminateEvent $event) {
        $this->moduleHandler
            ->writeCache();
    }
    
    /**
     * Registers the methods in this class that should be listeners.
     *
     * @return array
     *   An array of event listener definitions.
     */
    public static function getSubscribedEvents() : array {
        $events[KernelEvents::TERMINATE][] = [
            'onTerminate',
            100,
        ];
        return $events;
    }

}

Members

Title Sort descending Modifiers Object type Summary
RequestCloseSubscriber::$moduleHandler protected property
RequestCloseSubscriber::getSubscribedEvents public static function Registers the methods in this class that should be listeners.
RequestCloseSubscriber::onTerminate public function Performs end of request tasks.
RequestCloseSubscriber::__construct public function Constructs a new RequestCloseSubscriber instance.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.