Verified Commit 4a26ee1f authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3436599 by longwave: Replace RequestCloseSubscriber with...

Issue #3436599 by longwave: Replace RequestCloseSubscriber with needs_destruction tag on ModuleHandler
parent 9555002a
Loading
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -620,6 +620,8 @@ services:
  module_handler:
    class: Drupal\Core\Extension\ModuleHandler
    arguments: ['%app.root%', '%container.modules%', '@cache.bootstrap']
    tags:
      - { name: needs_destruction }
  Drupal\Core\Extension\ModuleHandlerInterface: '@module_handler'
  module_installer:
    class: Drupal\Core\Extension\ModuleInstaller
@@ -1389,9 +1391,6 @@ services:
    autowire: true
  redirect_leading_slashes_subscriber:
    class: Drupal\Core\EventSubscriber\RedirectLeadingSlashesSubscriber
  request_close_subscriber:
    class: Drupal\Core\EventSubscriber\RequestCloseSubscriber
    arguments: ['@module_handler']
  config_import_subscriber:
    class: Drupal\Core\EventSubscriber\ConfigImportSubscriber
    tags:
+0 −57
Original line number Diff line number Diff line
<?php

namespace Drupal\Core\EventSubscriber;

use Drupal\Core\Extension\ModuleHandlerInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\TerminateEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * Subscriber for all responses.
 */
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;
  }

}
+9 −1
Original line number Diff line number Diff line
@@ -5,12 +5,13 @@
use Drupal\Component\Graph\Graph;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\DestructableInterface;
use Drupal\Core\Extension\Exception\UnknownExtensionException;

/**
 * Class that manages modules in a Drupal installation.
 */
class ModuleHandler implements ModuleHandlerInterface {
class ModuleHandler implements ModuleHandlerInterface, DestructableInterface {

  /**
   * List of loaded files.
@@ -331,6 +332,13 @@ public function writeCache() {
    }
  }

  /**
   * {@inheritdoc}
   */
  public function destruct() {
    $this->writeCache();
  }

  /**
   * {@inheritdoc}
   */