comparison core/lib/Drupal/Core/DrupalKernel.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents c2387f117808
children af1871eacc83
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
3 namespace Drupal\Core; 3 namespace Drupal\Core;
4 4
5 use Composer\Autoload\ClassLoader; 5 use Composer\Autoload\ClassLoader;
6 use Drupal\Component\Assertion\Handle; 6 use Drupal\Component\Assertion\Handle;
7 use Drupal\Component\FileCache\FileCacheFactory; 7 use Drupal\Component\FileCache\FileCacheFactory;
8 use Drupal\Component\Utility\Unicode;
9 use Drupal\Component\Utility\UrlHelper; 8 use Drupal\Component\Utility\UrlHelper;
10 use Drupal\Core\Cache\DatabaseBackend; 9 use Drupal\Core\Cache\DatabaseBackend;
11 use Drupal\Core\Config\BootstrapConfigStorageFactory; 10 use Drupal\Core\Config\BootstrapConfigStorageFactory;
12 use Drupal\Core\Config\NullStorage; 11 use Drupal\Core\Config\NullStorage;
13 use Drupal\Core\Database\Database; 12 use Drupal\Core\Database\Database;
18 use Drupal\Core\Extension\ExtensionDiscovery; 17 use Drupal\Core\Extension\ExtensionDiscovery;
19 use Drupal\Core\File\MimeType\MimeTypeGuesser; 18 use Drupal\Core\File\MimeType\MimeTypeGuesser;
20 use Drupal\Core\Http\TrustedHostsRequestFactory; 19 use Drupal\Core\Http\TrustedHostsRequestFactory;
21 use Drupal\Core\Installer\InstallerRedirectTrait; 20 use Drupal\Core\Installer\InstallerRedirectTrait;
22 use Drupal\Core\Language\Language; 21 use Drupal\Core\Language\Language;
22 use Drupal\Core\Security\PharExtensionInterceptor;
23 use Drupal\Core\Security\RequestSanitizer; 23 use Drupal\Core\Security\RequestSanitizer;
24 use Drupal\Core\Site\Settings; 24 use Drupal\Core\Site\Settings;
25 use Drupal\Core\Test\TestDatabase; 25 use Drupal\Core\Test\TestDatabase;
26 use Symfony\Cmf\Component\Routing\RouteObjectInterface; 26 use Symfony\Cmf\Component\Routing\RouteObjectInterface;
27 use Symfony\Component\ClassLoader\ApcClassLoader; 27 use Symfony\Component\ClassLoader\ApcClassLoader;
34 use Symfony\Component\HttpFoundation\Response; 34 use Symfony\Component\HttpFoundation\Response;
35 use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; 35 use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
36 use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; 36 use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
37 use Symfony\Component\HttpKernel\TerminableInterface; 37 use Symfony\Component\HttpKernel\TerminableInterface;
38 use Symfony\Component\Routing\Route; 38 use Symfony\Component\Routing\Route;
39 use TYPO3\PharStreamWrapper\Manager as PharStreamWrapperManager;
40 use TYPO3\PharStreamWrapper\Behavior as PharStreamWrapperBehavior;
41 use TYPO3\PharStreamWrapper\PharStreamWrapper;
39 42
40 /** 43 /**
41 * The DrupalKernel class is the core of Drupal itself. 44 * The DrupalKernel class is the core of Drupal itself.
42 * 45 *
43 * This class is responsible for building the Dependency Injection Container and 46 * This class is responsible for building the Dependency Injection Container and
297 } 300 }
298 $this->root = $app_root; 301 $this->root = $app_root;
299 } 302 }
300 303
301 /** 304 /**
302 * Determine the application root directory based on assumptions. 305 * Determine the application root directory based on this file's location.
303 * 306 *
304 * @return string 307 * @return string
305 * The application root. 308 * The application root.
306 */ 309 */
307 protected static function guessApplicationRoot() { 310 protected static function guessApplicationRoot() {
311 // Determine the application root by:
312 // - Removing the namespace directories from the path.
313 // - Getting the path to the directory two levels up from the path
314 // determined in the previous step.
308 return dirname(dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__)))); 315 return dirname(dirname(substr(__DIR__, 0, -strlen(__NAMESPACE__))));
309 } 316 }
310 317
311 /** 318 /**
312 * Returns the appropriate site directory for a request. 319 * Returns the appropriate site directory for a request.
465 472
466 $this->bootstrapContainer = new $this->bootstrapContainerClass(Settings::get('bootstrap_container_definition', $this->defaultBootstrapContainerDefinition)); 473 $this->bootstrapContainer = new $this->bootstrapContainerClass(Settings::get('bootstrap_container_definition', $this->defaultBootstrapContainerDefinition));
467 474
468 // Initialize the container. 475 // Initialize the container.
469 $this->initializeContainer(); 476 $this->initializeContainer();
477
478 if (in_array('phar', stream_get_wrappers(), TRUE)) {
479 // Set up a stream wrapper to handle insecurities due to PHP's builtin
480 // phar stream wrapper. This is not registered as a regular stream wrapper
481 // to prevent \Drupal\Core\File\FileSystem::validScheme() treating "phar"
482 // as a valid scheme.
483 try {
484 $behavior = new PharStreamWrapperBehavior();
485 PharStreamWrapperManager::initialize(
486 $behavior->withAssertion(new PharExtensionInterceptor())
487 );
488 }
489 catch (\LogicException $e) {
490 // Continue if the PharStreamWrapperManager is already initialized. For
491 // example, this occurs during a module install.
492 // @see \Drupal\Core\Extension\ModuleInstaller::install()
493 };
494 stream_wrapper_unregister('phar');
495 stream_wrapper_register('phar', PharStreamWrapper::class);
496 }
470 497
471 $this->booted = TRUE; 498 $this->booted = TRUE;
472 499
473 return $this; 500 return $this;
474 } 501 }
998 1025
999 // Set sane locale settings, to ensure consistent string, dates, times and 1026 // Set sane locale settings, to ensure consistent string, dates, times and
1000 // numbers handling. 1027 // numbers handling.
1001 setlocale(LC_ALL, 'C'); 1028 setlocale(LC_ALL, 'C');
1002 1029
1003 // Detect string handling method. 1030 // Set appropriate configuration for multi-byte strings.
1004 Unicode::check(); 1031 mb_internal_encoding('utf-8');
1032 mb_language('uni');
1005 1033
1006 // Indicate that code is operating in a test child site. 1034 // Indicate that code is operating in a test child site.
1007 if (!defined('DRUPAL_TEST_IN_CHILD_SITE')) { 1035 if (!defined('DRUPAL_TEST_IN_CHILD_SITE')) {
1008 if ($test_prefix = drupal_valid_test_ua()) { 1036 if ($test_prefix = drupal_valid_test_ua()) {
1009 $test_db = new TestDatabase($test_prefix); 1037 $test_db = new TestDatabase($test_prefix);
1089 // specific web-head will not clear any other web-heads. Therefore 1117 // specific web-head will not clear any other web-heads. Therefore
1090 // fallback to the composer class loader that only statically caches 1118 // fallback to the composer class loader that only statically caches
1091 // misses. 1119 // misses.
1092 $old_loader = $this->classLoader; 1120 $old_loader = $this->classLoader;
1093 $this->classLoader = $loader; 1121 $this->classLoader = $loader;
1094 // Our class loaders are preprended to ensure they come first like the 1122 // Our class loaders are prepended to ensure they come first like the
1095 // class loader they are replacing. 1123 // class loader they are replacing.
1096 $old_loader->register(TRUE); 1124 $old_loader->register(TRUE);
1097 $loader->register(TRUE); 1125 $loader->register(TRUE);
1098 } 1126 }
1099 } 1127 }
1602 * @return string|null 1630 * @return string|null
1603 * The name of the any active install profile or distribution. 1631 * The name of the any active install profile or distribution.
1604 */ 1632 */
1605 protected function getInstallProfile() { 1633 protected function getInstallProfile() {
1606 $config = $this->getConfigStorage()->read('core.extension'); 1634 $config = $this->getConfigStorage()->read('core.extension');
1607 if (!empty($config['profile'])) { 1635 if (isset($config['profile'])) {
1608 $install_profile = $config['profile']; 1636 $install_profile = $config['profile'];
1609 } 1637 }
1610 // @todo https://www.drupal.org/node/2831065 remove the BC layer. 1638 // @todo https://www.drupal.org/node/2831065 remove the BC layer.
1611 else { 1639 else {
1612 // If system_update_8300() has not yet run fallback to using settings. 1640 // If system_update_8300() has not yet run fallback to using settings.
1613 $install_profile = Settings::get('install_profile'); 1641 $settings = Settings::getAll();
1642 $install_profile = isset($settings['install_profile']) ? $settings['install_profile'] : NULL;
1614 } 1643 }
1615 1644
1616 // Normalize an empty string to a NULL value. 1645 // Normalize an empty string to a NULL value.
1617 return empty($install_profile) ? NULL : $install_profile; 1646 return empty($install_profile) ? NULL : $install_profile;
1618 } 1647 }