commit a307229eb70e8ff9453a5b372f509d2280768f04 Merge: 4b18067 26eb01c Author: James Gilliland Date: Tue May 6 14:05:25 2014 -0500 Merge remote-tracking branch 'origin/8.x' into kernel-2016629-neclimdul Conflicts: core/authorize.php core/includes/bootstrap.inc core/includes/install.core.inc core/scripts/password-hash.sh core/scripts/rebuild_token_calculator.sh diff --cc core/includes/install.core.inc index a6b198c,b00d23b..41d9777 --- a/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@@ -371,10 -377,10 +371,12 @@@ function install_begin_request(&$instal $container->get('string_translation') ->addTranslator($container->get('string_translator.file_translation')); + $kernel->preHandle($request); + - // Add in installation language if present. + // Set the default language to the selected language, if any. if (isset($install_state['parameters']['langcode'])) { + $default_language = new Language(array('id' => $install_state['parameters']['langcode'])); + $container->get('language.default')->set($default_language); \Drupal::translation()->setDefaultLangcode($install_state['parameters']['langcode']); } diff --cc core/lib/Drupal/Core/DrupalKernel.php index aaad6f8,8baa101..6d136ed --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@@ -7,13 -7,10 +7,14 @@@ namespace Drupal\Core; -use Drupal\Core\PhpStorage\PhpStorageFactory; +use Drupal\Component\Utility\Crypt; +use Drupal\Core\Site\Settings; +use Drupal\Component\Utility\Timer; +use Drupal\Component\Utility\Unicode; +use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Config\BootstrapConfigStorageFactory; use Drupal\Core\Config\NullStorage; -use Drupal\Core\CoreServiceProvider; ++use Drupal\Core\Database\Database; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\DependencyInjection\ServiceProviderInterface; use Drupal\Core\DependencyInjection\YamlFileLoader; @@@ -196,36 -174,11 +197,36 @@@ class DrupalKernel implements DrupalKer if ($this->booted) { return; } - $this->initializeContainer(); - $this->booted = TRUE; - if ($this->containerNeedsDumping && !$this->dumpDrupalContainer($this->container, static::CONTAINER_BASE_CLASS)) { - watchdog('DrupalKernel', 'Container cannot be written to disk'); + + // Include our bootstrap file. + require_once dirname(dirname(dirname(__DIR__))) . '/includes/bootstrap.inc'; + + // Exit if we should be in a test environment but aren't. + if ($this->testOnly && !drupal_valid_test_ua()) { + header($request->server->get('SERVER_PROTOCOL') . ' 403 Forbidden'); + exit; } + + $this->bootEnvironment(); + + // Get our most basic settings setup. + Settings::initialize($request); + + // Initialize Request globals. + $this->initializeRequestGlobals($request); + + // Start a page timer: + Timer::start('page'); + + // Redirect the user to the installation script if Drupal has not been + // installed yet (i.e., if no $databases array has been defined in the + // settings.php file) and we are not already installing. - if (empty($GLOBALS['databases']) && !drupal_installation_attempted() && !drupal_is_cli()) { ++ if (!Database::getConnectionInfo() && !drupal_installation_attempted() && !drupal_is_cli()) { + include_once DRUPAL_ROOT . '/core/includes/install.inc'; + install_goto('core/install.php'); + } + + $this->booted = TRUE; } /** @@@ -449,15 -281,6 +450,20 @@@ } /** + * {@inheritdoc} + */ + public function preHandle(Request $request) { + + $this->boot($request); + $this->bootCode($request); ++ // Normally this is handled in the HttpKernel object but prehandle exists ++ // for pages that don't run through a http kernel. ++ $this->container->enterScope('request'); ++ $this->container->set('request', $request); ++ $this->container->get('request_stack')->push($request); + } + + /** * Returns module data on the filesystem. * * @param $module diff --cc core/lib/Drupal/Core/Site/Settings.php index 4b7545f,fe2260d..e014cac --- a/core/lib/Drupal/Core/Site/Settings.php +++ b/core/lib/Drupal/Core/Site/Settings.php @@@ -7,8 -7,6 +7,9 @@@ namespace Drupal\Core\Site; ++use Drupal\Core\Database\Database; +use Symfony\Component\HttpFoundation\Request; + /** * Read only settings that are initialized with the class. * @@@ -90,82 -80,4 +91,87 @@@ final class Settings return self::$instance->storage; } + /** + * Bootstraps settings.php and the Settings singleton. + * + * @param \Symfony\Component\HttpFoundation\Request $request + * The current request. + */ + public static function initialize(Request $request) { + // Export these settings.php variables to the global namespace. - global $base_url, $databases, $cookie_domain, $config_directories, $config; ++ global $base_url, $cookie_domain, $config_directories, $config; + $settings = array(); + $config = array(); ++ $databases = array(); + + // Make conf_path() available as local variable in settings.php. + $conf_path = static::confPath($request); + if (is_readable(DRUPAL_ROOT . '/' . $conf_path . '/settings.php')) { + require DRUPAL_ROOT . '/' . $conf_path . '/settings.php'; + } ++ ++ // Initialize Database. ++ Database::setMultipleConnectionInfo($databases); ++ + // Initialize Settings. + new Settings($settings); + } + + + /** + * Returns the appropriate configuration directory. + * + * Returns the configuration path based on the site's hostname, port, and + * pathname. Uses find_conf_path() to find the current configuration + * directory. See default.settings.php for examples on how the URL is + * converted to a directory. + * + * @param \Symfony\Component\HttpFoundation\Request $request + * (optional) The current request. If not passed, defaults to request as + * stored in the container at \Drupal::request(). + * @param bool $require_settings + * Only configuration directories with an existing settings.php file + * will be recognized. Defaults to TRUE. During initial installation, + * this is set to FALSE so that Drupal can detect a matching directory, + * then create a new settings.php file in it. + * @param bool $reset + * Force a full search for matching directories even if one had been + * found previously. Defaults to FALSE. + * + * @return string + * The path of the matching directory. + * + * @see default.settings.php + */ + public static function confPath(Request $request = NULL, $require_settings = TRUE, $reset = FALSE) { + if (isset(static::$confPath) && !$reset) { + return static::$confPath; + } + + // Ideally we make this required but it isn't for the moment. + if (!isset($request)) { + if (\Drupal::hasRequest()) { + $request = \Drupal::request(); + } + // @todo Remove once external CLI scripts (Drush) are updated. + else { + $request = Request::createFromGlobals(); + } + } + + // Check for a simpletest override. + if ($test_prefix = drupal_valid_test_ua()) { + static::$confPath = 'sites/simpletest/' . substr($test_prefix, 10); + return static::$confPath; + } + + // Otherwise, use the normal $conf_path. + $script_name = $request->server->get('SCRIPT_NAME'); + if (!$script_name) { + $script_name = $request->server->get('SCRIPT_FILENAME'); + } + $http_host = $request->server->get('HTTP_HOST'); + static::$confPath = find_conf_path($http_host, $script_name, $require_settings); + return static::$confPath; + } } diff --cc core/scripts/password-hash.sh index 248960a,f80d75c..528301a --- a/core/scripts/password-hash.sh +++ b/core/scripts/password-hash.sh @@@ -13,9 -9,15 +9,16 @@@ */ use Drupal\Core\DrupalKernel; +use Symfony\Component\HttpFoundation\Request; - if (version_compare(PHP_VERSION, "5.2.0", "<")) { + // Check for $_SERVER['argv'] instead of PHP_SAPI === 'cli' to allow this script + // to be tested with the Simpletest UI test runner. + // @see \Drupal\system\Tests\System\ScriptTest + if (!isset($_SERVER['argv']) || !is_array($_SERVER['argv'])) { + return; + } + + if (version_compare(PHP_VERSION, "5.4.2", "<")) { $version = PHP_VERSION; echo <<boot(); +$autoloader = require_once $core . '/vendor/autoload.php'; +$request = Request::createFromGlobals(); +$kernel = new DrupalKernel('prod', $autoloader, FALSE); +$kernel->boot($request); $password_hasher = $kernel->getContainer()->get('password'); foreach ($passwords as $password) { diff --cc core/scripts/rebuild_token_calculator.sh index a54d336,9e7dc03..9d2f720 --- a/core/scripts/rebuild_token_calculator.sh +++ b/core/scripts/rebuild_token_calculator.sh @@@ -7,19 -7,20 +7,22 @@@ */ use Drupal\Component\Utility\Crypt; +use Drupal\Core\DrupalKernel; +use Symfony\Component\HttpFoundation\Request; use Drupal\Core\Site\Settings; + // Check for $_SERVER['argv'] instead of PHP_SAPI === 'cli' to allow this script + // to be tested with the Simpletest UI test runner. + // @see \Drupal\system\Tests\System\ScriptTest + if (!isset($_SERVER['argv']) || !is_array($_SERVER['argv'])) { + return; + } + -$core = dirname(__DIR__); -require_once $core . '/vendor/autoload.php'; -require_once $core . '/includes/bootstrap.inc'; +$autoloader = require_once __DIR__ . '/../vendor/autoload.php'; - require_once __DIR__ . '/../includes/bootstrap.inc'; - if (!drupal_is_cli()) { - exit; - } -drupal_bootstrap(DRUPAL_BOOTSTRAP_CONFIGURATION); +$request = Request::createFromGlobals(); +$kernel = new DrupalKernel('prod', $autoloader); +$kernel->boot($request); $timestamp = time(); $token = Crypt::hmacBase64($timestamp, Settings::get('hash_salt'));