From 7d3be895ae21e3bca0c1651ceabfa2f43babf689 Mon Sep 17 00:00:00 2001
From: Nathaniel Catchpole <catch@35733.no-reply.drupal.org>
Date: Mon, 12 Jan 2015 11:37:32 +0000
Subject: [PATCH] Issue #2392787 by beejeebus, dawehner, alexpott: Move include
 statements from DrupalKernel::boot() into DrupalKernel::preHandle()

---
 core/core.services.yml                        |  2 +-
 core/includes/bootstrap.inc                   | 50 +++++++++++++++++++
 core/includes/common.inc                      | 50 -------------------
 .../Core/Controller/ControllerResolver.php    | 17 +------
 core/lib/Drupal/Core/DrupalKernel.php         | 39 +++++++++------
 .../lib/Drupal/Core/DrupalKernelInterface.php |  5 ++
 .../lib/Drupal/Core/Test/TestRunnerKernel.php |  1 +
 7 files changed, 81 insertions(+), 83 deletions(-)

diff --git a/core/core.services.yml b/core/core.services.yml
index 8a5a126e5440..d4f021d1395b 100644
--- a/core/core.services.yml
+++ b/core/core.services.yml
@@ -428,7 +428,7 @@ services:
     arguments: ['@kernel']
   controller_resolver:
     class: Drupal\Core\Controller\ControllerResolver
-    arguments: ['@class_resolver', '@logger.channel.default']
+    arguments: ['@class_resolver']
   class_resolver:
     class: Drupal\Core\DependencyInjection\ClassResolver
     calls:
diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index ae3f55ac27c1..ff20f28fba07 100644
--- a/core/includes/bootstrap.inc
+++ b/core/includes/bootstrap.inc
@@ -293,6 +293,23 @@ function drupal_get_filename($type, $name, $filename = NULL) {
   }
 }
 
+/**
+ * Returns the path to a system item (module, theme, etc.).
+ *
+ * @param $type
+ *   The type of the item; one of 'core', 'profile', 'module', 'theme', or
+ *   'theme_engine'.
+ * @param $name
+ *   The name of the item for which the path is requested. Ignored for
+ *   $type 'core'.
+ *
+ * @return
+ *   The path to the requested item or an empty string if the item is not found.
+ */
+function drupal_get_path($type, $name) {
+  return dirname(drupal_get_filename($type, $name));
+}
+
 /**
  * Gets the page cache cid for this request.
  *
@@ -1066,6 +1083,39 @@ function drupal_installation_attempted() {
   return isset($GLOBALS['install_state']) && empty($GLOBALS['install_state']['installation_finished']);
 }
 
+/**
+ * Gets the name of the currently active installation profile.
+ *
+ * When this function is called during Drupal's initial installation process,
+ * the name of the profile that's about to be installed is stored in the global
+ * installation state. At all other times, the "install_profile" setting will be
+ * available in settings.php.
+ *
+ * @return string|null $profile
+ *   The name of the installation profile or NULL if no installation profile is
+ *   currently active. This is the case for example during the first steps of
+ *   the installer or during unit tests.
+ */
+function drupal_get_profile() {
+  global $install_state;
+
+  if (drupal_installation_attempted()) {
+    // If the profile has been selected return it.
+    if (isset($install_state['parameters']['profile'])) {
+      $profile = $install_state['parameters']['profile'];
+    }
+    else {
+      $profile = NULL;
+    }
+  }
+  else {
+    // Fall back to NULL, if there is no 'install_profile' setting.
+    $profile = Settings::get('install_profile');
+  }
+
+  return $profile;
+}
+
 /**
  * Returns a list of languages set up on the site.
  *
diff --git a/core/includes/common.inc b/core/includes/common.inc
index 6d1b013ed18e..08f25f285a53 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -144,39 +144,6 @@
  */
 const LOCALE_PLURAL_DELIMITER = "\03";
 
-/**
- * Gets the name of the currently active installation profile.
- *
- * When this function is called during Drupal's initial installation process,
- * the name of the profile that's about to be installed is stored in the global
- * installation state. At all other times, the "install_profile" setting will be
- * available in settings.php.
- *
- * @return string|null $profile
- *   The name of the installation profile or NULL if no installation profile is
- *   currently active. This is the case for example during the first steps of
- *   the installer or during unit tests.
- */
-function drupal_get_profile() {
-  global $install_state;
-
-  if (drupal_installation_attempted()) {
-    // If the profile has been selected return it.
-    if (isset($install_state['parameters']['profile'])) {
-      $profile = $install_state['parameters']['profile'];
-    }
-    else {
-      $profile = NULL;
-    }
-  }
-  else {
-    // Fall back to NULL, if there is no 'install_profile' setting.
-    $profile = Settings::get('install_profile');
-  }
-
-  return $profile;
-}
-
 /**
  * Adds output to the HEAD tag of the HTML page.
  *
@@ -798,23 +765,6 @@ function drupal_set_time_limit($time_limit) {
   }
 }
 
-/**
- * Returns the path to a system item (module, theme, etc.).
- *
- * @param $type
- *   The type of the item; one of 'core', 'profile', 'module', 'theme', or
- *   'theme_engine'.
- * @param $name
- *   The name of the item for which the path is requested. Ignored for
- *   $type 'core'.
- *
- * @return
- *   The path to the requested item or an empty string if the item is not found.
- */
-function drupal_get_path($type, $name) {
-  return dirname(drupal_get_filename($type, $name));
-}
-
 /**
  * Returns the base URL path (i.e., directory) of the Drupal installation.
  *
diff --git a/core/lib/Drupal/Core/Controller/ControllerResolver.php b/core/lib/Drupal/Core/Controller/ControllerResolver.php
index febffd906ed3..eb78f6c4db09 100644
--- a/core/lib/Drupal/Core/Controller/ControllerResolver.php
+++ b/core/lib/Drupal/Core/Controller/ControllerResolver.php
@@ -30,13 +30,6 @@
  */
 class ControllerResolver extends BaseControllerResolver implements ControllerResolverInterface {
 
-  /**
-   * The PSR-3 logger. (optional)
-   *
-   * @var \Psr\Log\LoggerInterface;
-   */
-  protected $logger;
-
   /**
    * The class resolver.
    *
@@ -49,13 +42,9 @@ class ControllerResolver extends BaseControllerResolver implements ControllerRes
    *
    * @param \Drupal\Core\DependencyInjection\ClassResolverInterface $class_resolver
    *   The class resolver.
-   * @param \Psr\Log\LoggerInterface $logger
-   *   (optional) A LoggerInterface instance.
    */
-  public function __construct(ClassResolverInterface $class_resolver, LoggerInterface $logger = NULL) {
+  public function __construct(ClassResolverInterface $class_resolver) {
     $this->classResolver = $class_resolver;
-
-    parent::__construct($logger);
   }
 
   /**
@@ -90,10 +79,6 @@ public function getControllerFromDefinition($controller, $path = '') {
    */
   public function getController(Request $request) {
     if (!$controller = $request->attributes->get('_controller')) {
-      if ($this->logger !== NULL) {
-        $this->logger->warning('Unable to look for the controller as the "_controller" parameter is missing');
-      }
-
       return FALSE;
     }
     return $this->getControllerFromDefinition($controller, $request->getPathInfo());
diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php
index d5e6059345b7..ac9dbeef7f30 100644
--- a/core/lib/Drupal/Core/DrupalKernel.php
+++ b/core/lib/Drupal/Core/DrupalKernel.php
@@ -377,22 +377,6 @@ public function boot() {
     // Start a page timer:
     Timer::start('page');
 
-    // Load legacy and other functional code.
-    require_once $this->root . '/core/includes/common.inc';
-    require_once $this->root . '/core/includes/database.inc';
-    require_once $this->root . '/core/includes/path.inc';
-    require_once $this->root . '/core/includes/module.inc';
-    require_once $this->root . '/core/includes/theme.inc';
-    require_once $this->root . '/core/includes/pager.inc';
-    require_once $this->root . '/core/includes/menu.inc';
-    require_once $this->root . '/core/includes/tablesort.inc';
-    require_once $this->root . '/core/includes/file.inc';
-    require_once $this->root . '/core/includes/unicode.inc';
-    require_once $this->root . '/core/includes/form.inc';
-    require_once $this->root . '/core/includes/errors.inc';
-    require_once $this->root . '/core/includes/schema.inc';
-    require_once $this->root . '/core/includes/entity.inc';
-
     // Ensure that findSitePath is set.
     if (!$this->sitePath) {
       throw new \Exception('Kernel does not have site path set before calling boot()');
@@ -431,10 +415,33 @@ public function getContainer() {
     return $this->container;
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  public function loadLegacyIncludes() {
+    require_once $this->root . '/core/includes/common.inc';
+    require_once $this->root . '/core/includes/database.inc';
+    require_once $this->root . '/core/includes/path.inc';
+    require_once $this->root . '/core/includes/module.inc';
+    require_once $this->root . '/core/includes/theme.inc';
+    require_once $this->root . '/core/includes/pager.inc';
+    require_once $this->root . '/core/includes/menu.inc';
+    require_once $this->root . '/core/includes/tablesort.inc';
+    require_once $this->root . '/core/includes/file.inc';
+    require_once $this->root . '/core/includes/unicode.inc';
+    require_once $this->root . '/core/includes/form.inc';
+    require_once $this->root . '/core/includes/errors.inc';
+    require_once $this->root . '/core/includes/schema.inc';
+    require_once $this->root . '/core/includes/entity.inc';
+  }
+
   /**
    * {@inheritdoc}
    */
   public function preHandle(Request $request) {
+
+    $this->loadLegacyIncludes();
+
     // Load all enabled modules.
     $this->container->get('module_handler')->loadAll();
 
diff --git a/core/lib/Drupal/Core/DrupalKernelInterface.php b/core/lib/Drupal/Core/DrupalKernelInterface.php
index e7c468fb0506..0ba61dee2dfc 100644
--- a/core/lib/Drupal/Core/DrupalKernelInterface.php
+++ b/core/lib/Drupal/Core/DrupalKernelInterface.php
@@ -124,4 +124,9 @@ public function prepareLegacyRequest(Request $request);
    */
   public function preHandle(Request $request);
 
+  /**
+   * Helper method that loads legacy Drupal include files.
+   */
+  public function loadLegacyIncludes();
+
 }
diff --git a/core/lib/Drupal/Core/Test/TestRunnerKernel.php b/core/lib/Drupal/Core/Test/TestRunnerKernel.php
index 0b2f790b8e3b..a6dc573c0795 100644
--- a/core/lib/Drupal/Core/Test/TestRunnerKernel.php
+++ b/core/lib/Drupal/Core/Test/TestRunnerKernel.php
@@ -79,6 +79,7 @@ public function boot() {
     $this->getContainer()->get('stream_wrapper_manager')->register();
 
     // Create the build/artifacts directory if necessary.
+    include_once DRUPAL_ROOT . '/core/includes/file.inc';
     if (!is_dir('public://simpletest')) {
       mkdir('public://simpletest', 0777, TRUE);
     }
-- 
GitLab