public static function Settings::initialize in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Site/Settings.php \Drupal\Core\Site\Settings::initialize()
- 9 core/lib/Drupal/Core/Site/Settings.php \Drupal\Core\Site\Settings::initialize()
Bootstraps settings.php and the Settings singleton.
Parameters
string $app_root: The app root.
string $site_path: The current site path.
\Composer\Autoload\ClassLoader $class_loader: The class loader that is used for this request. Passed by reference and exposed to the local scope of settings.php, so as to allow it to be decorated.
See also
15 calls to Settings::initialize()
- db-tools.php in core/
scripts/ db-tools.php - A command line application to import a database generation script.
- DrupalKernel::initializeSettings in core/
lib/ Drupal/ Core/ DrupalKernel.php - Locate site path and initialize settings singleton.
- dump-database-d8-mysql.php in core/
scripts/ dump-database-d8-mysql.php - A command line application to dump a database to a generation script.
- FunctionalTestSetupTrait::initSettings in core/
lib/ Drupal/ Core/ Test/ FunctionalTestSetupTrait.php - Initialize settings created during install.
- FunctionalTestSetupTrait::prepareSettings in core/
lib/ Drupal/ Core/ Test/ FunctionalTestSetupTrait.php - Prepares site settings and services before installation.
File
- core/
lib/ Drupal/ Core/ Site/ Settings.php, line 132
Class
- Settings
- Read only settings that are initialized with the class.
Namespace
Drupal\Core\SiteCode
public static function initialize($app_root, $site_path, &$class_loader) {
// Export these settings.php variables to the global namespace.
global $config;
$settings = [];
$config = [];
$databases = [];
if (is_readable($app_root . '/' . $site_path . '/settings.php')) {
require $app_root . '/' . $site_path . '/settings.php';
}
self::handleDeprecations($settings);
// Initialize databases.
foreach ($databases as $key => $targets) {
foreach ($targets as $target => $info) {
// Backwards compatibility layer for Drupal 8 style database connection
// arrays. Those have the wrong 'namespace' key set, or not set at all
// for core supported database drivers.
if (empty($info['namespace']) || strpos($info['namespace'], 'Drupal\\Core\\Database\\Driver\\') === 0) {
switch (strtolower($info['driver'])) {
case 'mysql':
$info['namespace'] = 'Drupal\\mysql\\Driver\\Database\\mysql';
break;
case 'pgsql':
$info['namespace'] = 'Drupal\\pgsql\\Driver\\Database\\pgsql';
break;
case 'sqlite':
$info['namespace'] = 'Drupal\\sqlite\\Driver\\Database\\sqlite';
break;
}
}
// Backwards compatibility layer for Drupal 8 style database connection
// arrays. Those do not have the 'autoload' key set for core database
// drivers.
if (empty($info['autoload'])) {
switch (trim($info['namespace'], '\\')) {
case "Drupal\\mysql\\Driver\\Database\\mysql":
$info['autoload'] = "core/modules/mysql/src/Driver/Database/mysql/";
break;
case "Drupal\\pgsql\\Driver\\Database\\pgsql":
$info['autoload'] = "core/modules/pgsql/src/Driver/Database/pgsql/";
break;
case "Drupal\\sqlite\\Driver\\Database\\sqlite":
$info['autoload'] = "core/modules/sqlite/src/Driver/Database/sqlite/";
break;
}
}
Database::addConnectionInfo($key, $target, $info);
// If the database driver is provided by a module, then its code may
// need to be instantiated prior to when the module's root namespace
// is added to the autoloader, because that happens during service
// container initialization but the container definition is likely in
// the database. Therefore, allow the connection info to specify an
// autoload directory for the driver.
if (isset($info['autoload'])) {
$class_loader
->addPsr4($info['namespace'] . '\\', $app_root . '/' . $info['autoload']);
}
}
}
// Initialize Settings.
new Settings($settings);
}