Commit 8121d120 authored by webchick's avatar webchick

Issue #2038135 by RobLoach, donquixote, Crell, ParisLiakos, catch: Use the...

Issue #2038135 by RobLoach, donquixote, Crell, ParisLiakos, catch: Use the Composer autoloader to make everything simpler.
parent 88b6c938
...@@ -27,7 +27,10 @@ ...@@ -27,7 +27,10 @@
"Drupal\\Core": "core/lib/", "Drupal\\Core": "core/lib/",
"Drupal\\Component": "core/lib/", "Drupal\\Component": "core/lib/",
"Drupal\\Driver": "drivers/lib/" "Drupal\\Driver": "drivers/lib/"
} },
"files": [
"core/lib/Drupal.php"
]
}, },
"config": { "config": {
"vendor-dir": "core/vendor", "vendor-dir": "core/vendor",
......
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
// Change the directory to the Drupal root. // Change the directory to the Drupal root.
chdir('..'); chdir('..');
require_once __DIR__ . '/vendor/autoload.php';
/** /**
* Global flag to identify update.php and authorize.php runs. * Global flag to identify update.php and authorize.php runs.
* *
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
use Drupal\Core\Database\Database; use Drupal\Core\Database\Database;
use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Utility\Title; use Drupal\Core\Utility\Title;
use Symfony\Component\ClassLoader\ClassLoader;
use Symfony\Component\ClassLoader\ApcClassLoader; use Symfony\Component\ClassLoader\ApcClassLoader;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\Container;
...@@ -510,9 +509,6 @@ function drupal_override_server_variables($variables = array()) { ...@@ -510,9 +509,6 @@ function drupal_override_server_variables($variables = array()) {
* Initializes the PHP environment. * Initializes the PHP environment.
*/ */
function drupal_environment_initialize() { function drupal_environment_initialize() {
// Make sure the \Drupal class is available.
require_once DRUPAL_ROOT . '/core/lib/Drupal.php';
if (!isset($_SERVER['HTTP_REFERER'])) { if (!isset($_SERVER['HTTP_REFERER'])) {
$_SERVER['HTTP_REFERER'] = ''; $_SERVER['HTTP_REFERER'] = '';
} }
...@@ -595,7 +591,8 @@ function drupal_settings_initialize() { ...@@ -595,7 +591,8 @@ function drupal_settings_initialize() {
if (is_readable(DRUPAL_ROOT . '/' . $conf_path . '/settings.php')) { if (is_readable(DRUPAL_ROOT . '/' . $conf_path . '/settings.php')) {
include_once DRUPAL_ROOT . '/' . $conf_path . '/settings.php'; include_once DRUPAL_ROOT . '/' . $conf_path . '/settings.php';
} }
require_once DRUPAL_ROOT . '/core/lib/Drupal/Component/Utility/Settings.php'; require_once __DIR__ . '../../lib/Drupal/Component/Utility/Settings.php';
new Settings(isset($settings) ? $settings : array()); new Settings(isset($settings) ? $settings : array());
$is_https = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on'; $is_https = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on';
...@@ -2732,7 +2729,7 @@ function arg($index = NULL, $path = NULL) { ...@@ -2732,7 +2729,7 @@ function arg($index = NULL, $path = NULL) {
* loader class when calling drupal_classloader() from settings.php. It is * loader class when calling drupal_classloader() from settings.php. It is
* ignored otherwise. * ignored otherwise.
* *
* @return \Symfony\Component\ClassLoader\ClassLoader * @return \Composer\Autoload\ClassLoader
* A ClassLoader class instance (or extension thereof). * A ClassLoader class instance (or extension thereof).
*/ */
function drupal_classloader($class_loader = NULL) { function drupal_classloader($class_loader = NULL) {
...@@ -2743,9 +2740,8 @@ function drupal_classloader($class_loader = NULL) { ...@@ -2743,9 +2740,8 @@ function drupal_classloader($class_loader = NULL) {
if (!isset($loader)) { if (!isset($loader)) {
// Include the Symfony ClassLoader for loading PSR-0-compatible classes. // Retrieve the Composer ClassLoader for loading classes.
require_once DRUPAL_ROOT . '/core/vendor/symfony/class-loader/Symfony/Component/ClassLoader/ClassLoader.php'; $loader = include __DIR__ . '/../vendor/autoload.php';
$loader = new ClassLoader();
// Register the class loader. // Register the class loader.
// When configured to use APC, the ApcClassLoader is registered instead. // When configured to use APC, the ApcClassLoader is registered instead.
...@@ -2756,20 +2752,11 @@ function drupal_classloader($class_loader = NULL) { ...@@ -2756,20 +2752,11 @@ function drupal_classloader($class_loader = NULL) {
$class_loader = settings()->get('class_loader', 'default'); $class_loader = settings()->get('class_loader', 'default');
} }
if ($class_loader === 'apc') { if ($class_loader === 'apc') {
require_once DRUPAL_ROOT . '/core/vendor/symfony/class-loader/Symfony/Component/ClassLoader/ApcClassLoader.php'; require_once __DIR__ . '/../vendor/symfony/class-loader/Symfony/Component/Classloader/ApcClassLoader.php';
$apc_loader = new ApcClassLoader('drupal.' . drupal_get_hash_salt(), $loader); $apc_loader = new ApcClassLoader('drupal.' . drupal_get_hash_salt(), $loader);
$loader->unregister();
$apc_loader->register(); $apc_loader->register();
} }
else {
$loader->register();
}
// Register namespaces for vendor libraries managed by Composer.
$prefixes_and_namespaces = require DRUPAL_ROOT . '/core/vendor/composer/autoload_namespaces.php';
$loader->addPrefixes($prefixes_and_namespaces);
// Register the loader with PHP.
$loader->register();
} }
return $loader; return $loader;
} }
...@@ -2784,7 +2771,7 @@ function drupal_classloader($class_loader = NULL) { ...@@ -2784,7 +2771,7 @@ function drupal_classloader($class_loader = NULL) {
*/ */
function drupal_classloader_register($name, $path) { function drupal_classloader_register($name, $path) {
$loader = drupal_classloader(); $loader = drupal_classloader();
$loader->addPrefix('Drupal\\' . $name, DRUPAL_ROOT . '/' . $path . '/lib'); $loader->add('Drupal\\' . $name, DRUPAL_ROOT . '/' . $path . '/lib');
} }
/** /**
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
// Change the directory to the Drupal root. // Change the directory to the Drupal root.
chdir('..'); chdir('..');
require_once __DIR__ . '/vendor/autoload.php';
/** /**
* Global flag to indicate the site is in installation mode. * Global flag to indicate the site is in installation mode.
* *
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
use Drupal\Core\CoreServiceProvider; use Drupal\Core\CoreServiceProvider;
use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\YamlFileLoader; use Drupal\Core\DependencyInjection\YamlFileLoader;
use Symfony\Component\ClassLoader\ClassLoader;
use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\DependencyInjection\Dumper\PhpDumper; use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
...@@ -20,6 +19,7 @@ ...@@ -20,6 +19,7 @@
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\TerminableInterface; use Symfony\Component\HttpKernel\TerminableInterface;
use Composer\Autoload\ClassLoader;
/** /**
* The DrupalKernel class is the core of Drupal itself. * The DrupalKernel class is the core of Drupal itself.
...@@ -97,7 +97,7 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface { ...@@ -97,7 +97,7 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface {
/** /**
* The classloader object. * The classloader object.
* *
* @var \Symfony\Component\ClassLoader\ClassLoader * @var \Composer\Autoload\ClassLoader
*/ */
protected $classLoader; protected $classLoader;
...@@ -150,7 +150,7 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface { ...@@ -150,7 +150,7 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface {
* String indicating the environment, e.g. 'prod' or 'dev'. Used by * String indicating the environment, e.g. 'prod' or 'dev'. Used by
* Symfony\Component\HttpKernel\Kernel::__construct(). Drupal does not use * Symfony\Component\HttpKernel\Kernel::__construct(). Drupal does not use
* this value currently. Pass 'prod'. * this value currently. Pass 'prod'.
* @param \Symfony\Component\ClassLoader\ClassLoader $class_loader * @param \Composer\Autoload\ClassLoader $class_loader
* (optional) The classloader is only used if $storage is not given or * (optional) The classloader is only used if $storage is not given or
* the load from storage fails and a container rebuild is required. In * the load from storage fails and a container rebuild is required. In
* this case, the loaded modules will be registered with this loader in * this case, the loaded modules will be registered with this loader in
...@@ -521,7 +521,7 @@ protected function buildContainer() { ...@@ -521,7 +521,7 @@ protected function buildContainer() {
$container->setParameter('container.namespaces', $namespaces); $container->setParameter('container.namespaces', $namespaces);
// Register synthetic services. // Register synthetic services.
$container->register('class_loader', 'Symfony\Component\ClassLoader\ClassLoader')->setSynthetic(TRUE); $container->register('class_loader')->setSynthetic(TRUE);
$container->register('kernel', 'Symfony\Component\HttpKernel\KernelInterface')->setSynthetic(TRUE); $container->register('kernel', 'Symfony\Component\HttpKernel\KernelInterface')->setSynthetic(TRUE);
$container->register('service_container', 'Symfony\Component\DependencyInjection\ContainerInterface')->setSynthetic(TRUE); $container->register('service_container', 'Symfony\Component\DependencyInjection\ContainerInterface')->setSynthetic(TRUE);
$yaml_loader = new YamlFileLoader($container); $yaml_loader = new YamlFileLoader($container);
...@@ -661,6 +661,8 @@ protected function getModuleNamespaces($moduleFileNames) { ...@@ -661,6 +661,8 @@ protected function getModuleNamespaces($moduleFileNames) {
* Registers a list of namespaces. * Registers a list of namespaces.
*/ */
protected function registerNamespaces(array $namespaces = array()) { protected function registerNamespaces(array $namespaces = array()) {
$this->classLoader->addPrefixes($namespaces); foreach ($namespaces as $prefix => $path) {
$this->classLoader->add($prefix, $path);
}
} }
} }
...@@ -520,27 +520,21 @@ function simpletest_classloader_register() { ...@@ -520,27 +520,21 @@ function simpletest_classloader_register() {
'theme' => array('dir' => 'themes', 'extension' => 'info'), 'theme' => array('dir' => 'themes', 'extension' => 'info'),
'profile' => array('dir' => 'profiles', 'extension' => 'profile'), 'profile' => array('dir' => 'profiles', 'extension' => 'profile'),
); );
$classloader = drupal_classloader();
foreach ($types as $type => $info) { foreach ($types as $type => $info) {
$matches = drupal_system_listing('/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\.' . $info['extension'] . '$/', $info['dir']); $matches = drupal_system_listing('/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\.' . $info['extension'] . '$/', $info['dir']);
foreach ($matches as $name => $file) { foreach ($matches as $name => $file) {
drupal_classloader_register($name, dirname($file->uri)); drupal_classloader_register($name, dirname($file->uri));
drupal_classloader()->addPrefix('Drupal\\' . $name . '\\Tests', DRUPAL_ROOT . '/' . dirname($file->uri) . '/tests'); $classloader->add('Drupal\\' . $name . '\\Tests', DRUPAL_ROOT . '/' . dirname($file->uri) . '/tests');
// While being there, prime drupal_get_filename(). // While being there, prime drupal_get_filename().
drupal_get_filename($type, $name, $file->uri); drupal_get_filename($type, $name, $file->uri);
} }
} }
// Register the core test directory so we can find \Drupal\UnitTestCase. // Register the core test directory so we can find \Drupal\UnitTestCase.
drupal_classloader()->addPrefix('Drupal\\Tests', DRUPAL_ROOT . '/core/tests'); $classloader->add('Drupal\\Tests', DRUPAL_ROOT . '/core/tests');
// Manually register phpunit prefixes because they use a classmap instead of a
// prefix. This can be safely removed if we move to using composer's
// autoloader with a classmap.
drupal_classloader()->addPrefixes(array(
'PHPUnit' => DRUPAL_ROOT . '/core/vendor/phpunit/phpunit',
'File_Iterator' => DRUPAL_ROOT . '/core/vendor/phpunit/php-file-iterator/',
'PHP_Timer' => DRUPAL_ROOT . '/core/vendor/phpunit/php-timer/',
));
} }
/** /**
......
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
chdir('../../..'); chdir('../../..');
// Load the Drupal bootstrap. // Load the Drupal bootstrap.
include_once dirname(dirname(__DIR__)) . '/includes/bootstrap.inc'; require_once dirname(dirname(__DIR__)) . '/vendor/autoload.php';
require_once dirname(dirname(__DIR__)) . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES); drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES);
if (\Drupal::config('statistics.settings')->get('count_content_views')) { if (\Drupal::config('statistics.settings')->get('count_content_views')) {
......
...@@ -18,5 +18,6 @@ ...@@ -18,5 +18,6 @@
// Change current directory to the Drupal root. // Change current directory to the Drupal root.
chdir('../../../..'); chdir('../../../..');
require_once dirname(dirname(dirname(__DIR__))) . '/vendor/autoload.php';
require_once dirname(dirname(dirname(__DIR__))) . '/includes/bootstrap.inc'; require_once dirname(dirname(dirname(__DIR__))) . '/includes/bootstrap.inc';
drupal_handle_request(TRUE); drupal_handle_request(TRUE);
...@@ -20,5 +20,6 @@ ...@@ -20,5 +20,6 @@
// Change current directory to the Drupal root. // Change current directory to the Drupal root.
chdir('../../../..'); chdir('../../../..');
require_once dirname(dirname(dirname(__DIR__))) . '/vendor/autoload.php';
require_once dirname(dirname(dirname(__DIR__))) . '/includes/bootstrap.inc'; require_once dirname(dirname(dirname(__DIR__))) . '/includes/bootstrap.inc';
drupal_handle_request(TRUE); drupal_handle_request(TRUE);
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
* @file * @file
* This script runs Drupal tests from command line. * This script runs Drupal tests from command line.
*/ */
require_once __DIR__ . '/../vendor/autoload.php';
use Drupal\Core\StreamWrapper\PublicStream; use Drupal\Core\StreamWrapper\PublicStream;
const SIMPLETEST_SCRIPT_COLOR_PASS = 32; // Green. const SIMPLETEST_SCRIPT_COLOR_PASS = 32; // Green.
......
...@@ -2,9 +2,7 @@ ...@@ -2,9 +2,7 @@
// Register the namespaces we'll need to autoload from. // Register the namespaces we'll need to autoload from.
$loader = require __DIR__ . "/../vendor/autoload.php"; $loader = require __DIR__ . "/../vendor/autoload.php";
$loader->add('Drupal\\', __DIR__); $loader->add('Drupal\\Tests', __DIR__);
$loader->add('Drupal\Core', __DIR__ . "/../../core/lib");
$loader->add('Drupal\Component', __DIR__ . "/../../core/lib");
foreach (scandir(__DIR__ . "/../modules") as $module) { foreach (scandir(__DIR__ . "/../modules") as $module) {
$loader->add('Drupal\\' . $module, __DIR__ . "/../modules/" . $module . "/lib"); $loader->add('Drupal\\' . $module, __DIR__ . "/../modules/" . $module . "/lib");
...@@ -17,7 +15,6 @@ ...@@ -17,7 +15,6 @@
} }
} }
require __DIR__ . "/../../core/lib/Drupal.php";
// Look into removing this later. // Look into removing this later.
define('REQUEST_TIME', (int) $_SERVER['REQUEST_TIME']); define('REQUEST_TIME', (int) $_SERVER['REQUEST_TIME']);
......
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
// Change the directory to the Drupal root. // Change the directory to the Drupal root.
chdir('..'); chdir('..');
require_once __DIR__ . '/vendor/autoload.php';
// Exit early if an incompatible PHP version would cause fatal errors. // Exit early if an incompatible PHP version would cause fatal errors.
// The minimum version is specified explicitly, as DRUPAL_MINIMUM_PHP is not // The minimum version is specified explicitly, as DRUPAL_MINIMUM_PHP is not
// yet available. It is defined in bootstrap.inc, but it is not possible to // yet available. It is defined in bootstrap.inc, but it is not possible to
......
...@@ -43,6 +43,7 @@ public static function getLoader() ...@@ -43,6 +43,7 @@ public static function getLoader()
$loader->register(true); $loader->register(true);
require $vendorDir . '/kriswallsmith/assetic/src/functions.php'; require $vendorDir . '/kriswallsmith/assetic/src/functions.php';
require $baseDir . '/core/lib/Drupal.php';
return $loader; return $loader;
} }
......
...@@ -8,7 +8,9 @@ ...@@ -8,7 +8,9 @@
* See COPYRIGHT.txt and LICENSE.txt files in the "core" directory. * See COPYRIGHT.txt and LICENSE.txt files in the "core" directory.
*/ */
require_once __DIR__ . '/core/vendor/autoload.php';
require_once __DIR__ . '/core/includes/bootstrap.inc'; require_once __DIR__ . '/core/includes/bootstrap.inc';
try { try {
drupal_handle_request(); drupal_handle_request();
} }
......
...@@ -411,14 +411,15 @@ ...@@ -411,14 +411,15 @@
/** /**
* Class Loader. * Class Loader.
* *
* By default, Drupal uses the Symfony UniversalClassLoader which is best for * By default, Drupal uses Composer's ClassLoader, which is best for
* development, as it does not break when code is moved on the file system. * development, as it does not break when code is moved on the file
* The APC classloader provides better performance and is recommended for * system. It is possible, however, to wrap the class loader with a
* production sites. * cached class loader solution for better performance, which is
* recommended for production sites.
* *
* Examples: * Examples:
* $class_loader = 'apc' * $settings['class_loader'] = 'apc';
* $class_loader = 'default' * $settings['class_loader'] = 'default';
*/ */
# $settings['class_loader'] = 'apc'; # $settings['class_loader'] = 'apc';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment