diff --git a/composer.json b/composer.json index 4c4f823..397fdf0 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,10 @@ "Drupal\\Core": "core/lib/", "Drupal\\Component": "core/lib/", "Drupal\\Driver": "drivers/lib/" - } + }, + "files": [ + "core/lib/Drupal.php" + ] }, "config": { "vendor-dir": "core/vendor", diff --git a/core/authorize.php b/core/authorize.php index fe39394..8a76fe4 100644 --- a/core/authorize.php +++ b/core/authorize.php @@ -23,6 +23,8 @@ // Change the directory to the Drupal root. chdir('..'); +require_once __DIR__ . '/vendor/autoload.php'; + /** * Global flag to identify update.php and authorize.php runs. * diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 5472321..8f04eba 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -11,7 +11,6 @@ use Drupal\Core\Database\Database; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\Utility\Title; -use Symfony\Component\ClassLoader\ClassLoader; use Symfony\Component\ClassLoader\ApcClassLoader; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Container; @@ -510,9 +509,6 @@ function drupal_override_server_variables($variables = array()) { * Initializes the PHP environment. */ function drupal_environment_initialize() { - // Make sure the \Drupal class is available. - require_once DRUPAL_ROOT . '/core/lib/Drupal.php'; - if (!isset($_SERVER['HTTP_REFERER'])) { $_SERVER['HTTP_REFERER'] = ''; } @@ -595,7 +591,7 @@ function drupal_settings_initialize() { if (is_readable(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'; + new Settings(isset($settings) ? $settings : array()); $is_https = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on'; @@ -1833,51 +1829,6 @@ function drupal_bootstrap($phase = NULL, $new_phase = TRUE) { } /** - * Handles an entire PHP request. - * - * This function may be called by PHP scripts (e.g., Drupal's index.php) that - * want Drupal to take over the entire PHP processing of the request. The only - * expectation is that PHP's superglobals are initialized as desired (PHP does - * this automatically, but some scripts might want to alter them) and that the - * DRUPAL_ROOT constant is defined and set to the absolute server directory of - * Drupal's codebase. - * - * Scripts and applications that want to invoke multiple Drupal requests within - * a single PHP request, or Drupal request handling within some larger workflow, - * should not call this function, but instead instantiate and use - * \Drupal\Core\DrupalKernel as needed. - * - * @param boolean $test_only - * Whether to restrict handling to only requests invoked by SimpleTest. - * - * @see index.php - */ -function drupal_handle_request($test_only = FALSE) { - // Initialize the environment, load settings.php, and activate a PSR-0 class - // autoloader with required namespaces registered. - drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION); - - // Exit if we should be in a test environment but aren't. - if ($test_only && !drupal_valid_test_ua()) { - header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden'); - exit; - } - - $kernel = new DrupalKernel('prod', drupal_classloader(), !$test_only); - - // @todo Remove this once everything in the bootstrap has been - // converted to services in the DIC. - $kernel->boot(); - drupal_bootstrap(DRUPAL_BOOTSTRAP_CODE); - - // Create a request object from the HttpFoundation. - $request = Request::createFromGlobals(); - $response = $kernel->handle($request)->prepare($request)->send(); - - $kernel->terminate($request, $response); -} - -/** * Returns the time zone of the current user. */ function drupal_get_user_timezone() { @@ -2732,7 +2683,7 @@ function arg($index = NULL, $path = NULL) { * loader class when calling drupal_classloader() from settings.php. It is * ignored otherwise. * - * @return \Symfony\Component\ClassLoader\ClassLoader + * @return \Composer\Autoload\ClassLoader * A ClassLoader class instance (or extension thereof). */ function drupal_classloader($class_loader = NULL) { @@ -2743,9 +2694,8 @@ function drupal_classloader($class_loader = NULL) { if (!isset($loader)) { - // Include the Symfony ClassLoader for loading PSR-0-compatible classes. - require_once DRUPAL_ROOT . '/core/vendor/symfony/class-loader/Symfony/Component/ClassLoader/ClassLoader.php'; - $loader = new ClassLoader(); + // Retrieve the Composer ClassLoader for loading classes. + $loader = include __DIR__ . '/../vendor/autoload.php'; // Register the class loader. // When configured to use APC, the ApcClassLoader is registered instead. @@ -2756,20 +2706,10 @@ function drupal_classloader($class_loader = NULL) { $class_loader = settings()->get('class_loader', 'default'); } if ($class_loader === 'apc') { - require_once DRUPAL_ROOT . '/core/vendor/symfony/class-loader/Symfony/Component/ClassLoader/ApcClassLoader.php'; $apc_loader = new ApcClassLoader('drupal.' . drupal_get_hash_salt(), $loader); + $loader->unregister(); $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; } @@ -2784,7 +2724,7 @@ function drupal_classloader($class_loader = NULL) { */ function drupal_classloader_register($name, $path) { $loader = drupal_classloader(); - $loader->addPrefix('Drupal\\' . $name, DRUPAL_ROOT . '/' . $path . '/lib'); + $loader->add('Drupal\\' . $name, DRUPAL_ROOT . '/' . $path . '/lib'); } /** diff --git a/core/install.php b/core/install.php index 641403d..7152fd8 100644 --- a/core/install.php +++ b/core/install.php @@ -8,6 +8,8 @@ // Change the directory to the Drupal root. chdir('..'); +require_once __DIR__ . '/vendor/autoload.php'; + /** * Global flag to indicate the site is in installation mode. * diff --git a/core/lib/Drupal/Core/Bootstrap.php b/core/lib/Drupal/Core/Bootstrap.php new file mode 100644 index 0000000..02f1704 --- /dev/null +++ b/core/lib/Drupal/Core/Bootstrap.php @@ -0,0 +1,66 @@ +boot(); + drupal_bootstrap(DRUPAL_BOOTSTRAP_CODE); + + // Create a request object from the HttpFoundation. + $request = Request::createFromGlobals(); + $response = $kernel->handle($request)->prepare($request)->send(); + + $kernel->terminate($request, $response); + } + +} diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index af1fe52..8f43e4f 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -12,7 +12,6 @@ use Drupal\Core\CoreServiceProvider; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\DependencyInjection\YamlFileLoader; -use Symfony\Component\ClassLoader\ClassLoader; use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; use Symfony\Component\DependencyInjection\Dumper\PhpDumper; @@ -20,6 +19,7 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\TerminableInterface; +use Composer\Autoload\ClassLoader; /** * The DrupalKernel class is the core of Drupal itself. @@ -97,7 +97,7 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface { /** * The classloader object. * - * @var \Symfony\Component\ClassLoader\ClassLoader + * @var \Composer\Autoload\ClassLoader */ protected $classLoader; @@ -150,7 +150,7 @@ class DrupalKernel implements DrupalKernelInterface, TerminableInterface { * String indicating the environment, e.g. 'prod' or 'dev'. Used by * Symfony\Component\HttpKernel\Kernel::__construct(). Drupal does not use * 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 * the load from storage fails and a container rebuild is required. In * this case, the loaded modules will be registered with this loader in @@ -521,7 +521,7 @@ protected function buildContainer() { $container->setParameter('container.namespaces', $namespaces); // 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('service_container', 'Symfony\Component\DependencyInjection\ContainerInterface')->setSynthetic(TRUE); $yaml_loader = new YamlFileLoader($container); @@ -661,6 +661,8 @@ protected function getModuleNamespaces($moduleFileNames) { * Registers a list of namespaces. */ protected function registerNamespaces(array $namespaces = array()) { - $this->classLoader->addPrefixes($namespaces); + foreach ($namespaces as $prefix => $path) { + $this->classLoader->add($prefix, $path); + } } } diff --git a/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module index 1c17909..8eb160d 100644 --- a/core/modules/simpletest/simpletest.module +++ b/core/modules/simpletest/simpletest.module @@ -520,27 +520,28 @@ function simpletest_classloader_register() { 'theme' => array('dir' => 'themes', 'extension' => 'info'), 'profile' => array('dir' => 'profiles', 'extension' => 'profile'), ); + + $classloader = drupal_classloader(); + foreach ($types as $type => $info) { $matches = drupal_system_listing('/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\.' . $info['extension'] . '$/', $info['dir']); foreach ($matches as $name => $file) { 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(). drupal_get_filename($type, $name, $file->uri); } } // 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/', - )); + $classloader->add('PHPUnit', DRUPAL_ROOT . '/core/vendor/phpunit/phpunit'); + $classloader->add('File_Iterator', DRUPAL_ROOT . '/core/vendor/phpunit/php-file-iterator/'); + $classloader->add('PHP_Timer', DRUPAL_ROOT . '/core/vendor/phpunit/php-timer/'); } /** diff --git a/core/modules/statistics/statistics.php b/core/modules/statistics/statistics.php index 20a2ec9..ed132e8 100644 --- a/core/modules/statistics/statistics.php +++ b/core/modules/statistics/statistics.php @@ -9,7 +9,8 @@ chdir('../../..'); // 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); if (\Drupal::config('statistics.settings')->get('count_content_views')) { diff --git a/core/modules/system/tests/http.php b/core/modules/system/tests/http.php index 5e5e702..d12b8fb 100644 --- a/core/modules/system/tests/http.php +++ b/core/modules/system/tests/http.php @@ -18,5 +18,5 @@ // Change current directory to the Drupal root. chdir('../../../..'); -require_once dirname(dirname(dirname(__DIR__))) . '/includes/bootstrap.inc'; -drupal_handle_request(TRUE); +require_once dirname(dirname(dirname(__DIR__))) . '/vendor/autoload.php'; +Drupal\Core\Bootstrap::handleRequest(TRUE); diff --git a/core/modules/system/tests/https.php b/core/modules/system/tests/https.php index e509c15..ca0ccca 100644 --- a/core/modules/system/tests/https.php +++ b/core/modules/system/tests/https.php @@ -20,5 +20,5 @@ // Change current directory to the Drupal root. chdir('../../../..'); -require_once dirname(dirname(dirname(__DIR__))) . '/includes/bootstrap.inc'; -drupal_handle_request(TRUE); +require_once dirname(dirname(dirname(__DIR__))) . '/vendor/autoload.php'; +Drupal\Core\Bootstrap::handleRequest(TRUE); diff --git a/core/scripts/run-tests.sh b/core/scripts/run-tests.sh index 31a9c89..31ea371 100755 --- a/core/scripts/run-tests.sh +++ b/core/scripts/run-tests.sh @@ -3,6 +3,9 @@ * @file * This script runs Drupal tests from command line. */ + +require_once __DIR__ . '/../vendor/autoload.php'; + use Drupal\Core\StreamWrapper\PublicStream; const SIMPLETEST_SCRIPT_COLOR_PASS = 32; // Green. diff --git a/core/tests/bootstrap.php b/core/tests/bootstrap.php index 08d8871..ee87504 100644 --- a/core/tests/bootstrap.php +++ b/core/tests/bootstrap.php @@ -2,9 +2,7 @@ // Register the namespaces we'll need to autoload from. $loader = require __DIR__ . "/../vendor/autoload.php"; -$loader->add('Drupal\\', __DIR__); -$loader->add('Drupal\Core', __DIR__ . "/../../core/lib"); -$loader->add('Drupal\Component', __DIR__ . "/../../core/lib"); +$loader->add('Drupal\\Tests', __DIR__); foreach (scandir(__DIR__ . "/../modules") as $module) { $loader->add('Drupal\\' . $module, __DIR__ . "/../modules/" . $module . "/lib"); @@ -17,7 +15,6 @@ } } -require __DIR__ . "/../../core/lib/Drupal.php"; // Look into removing this later. define('REQUEST_TIME', (int) $_SERVER['REQUEST_TIME']); diff --git a/core/update.php b/core/update.php index 3052584..ac36b2a 100644 --- a/core/update.php +++ b/core/update.php @@ -22,6 +22,8 @@ // Change the directory to the Drupal root. chdir('..'); +require_once __DIR__ . '/vendor/autoload.php'; + // Exit early if an incompatible PHP version would cause fatal errors. // 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 diff --git a/core/vendor/composer/autoload_real.php b/core/vendor/composer/autoload_real.php index 8b99b80..c63bb82 100644 --- a/core/vendor/composer/autoload_real.php +++ b/core/vendor/composer/autoload_real.php @@ -43,6 +43,7 @@ public static function getLoader() $loader->register(true); require $vendorDir . '/kriswallsmith/assetic/src/functions.php'; + require $baseDir . '/core/lib/Drupal.php'; return $loader; } diff --git a/index.php b/index.php index 4934bd2..363186c 100644 --- a/index.php +++ b/index.php @@ -8,9 +8,10 @@ * See COPYRIGHT.txt and LICENSE.txt files in the "core" directory. */ -require_once __DIR__ . '/core/includes/bootstrap.inc'; +require_once __DIR__ . '/core/vendor/autoload.php'; + try { - drupal_handle_request(); + Drupal\Core\Bootstrap::handleRequest(); } catch (Exception $e) { print 'If you have just changed code (for example deployed a new module or moved an existing one) read http://drupal.org/documentation/rebuild'; diff --git a/sites/default/default.settings.php b/sites/default/default.settings.php index a11647d..a58d60e 100644 --- a/sites/default/default.settings.php +++ b/sites/default/default.settings.php @@ -411,14 +411,15 @@ /** * Class Loader. * - * By default, Drupal uses the Symfony UniversalClassLoader which is best for - * development, as it does not break when code is moved on the file system. - * The APC classloader provides better performance and is recommended for - * production sites. + * 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. It is possible, however, to wrap the class loader with a + * cached class loader solution for better performance, which is + * recommended for production sites. * * Examples: - * $class_loader = 'apc' - * $class_loader = 'default' + * $settings['class_loader'] = 'apc'; + * $settings['class_loader'] = 'default'; */ # $settings['class_loader'] = 'apc';