diff --git a/core/includes/install.inc b/core/includes/install.inc index aa52ae0..5c5eaf2 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -6,6 +6,7 @@ */ use Drupal\Component\Utility\Unicode; +use Drupal\Core\Database\DatabaseDriverDiscovery; use Symfony\Component\HttpFoundation\RedirectResponse; use Drupal\Component\Utility\Crypt; use Drupal\Component\Utility\OpCodeCache; @@ -146,7 +147,7 @@ function drupal_install_profile_distribution_version() { * \Drupal\Core\Database\DatabaseDriverDiscovery component. */ function drupal_detect_database_types() { - $discovery = new \Drupal\Core\Database\DatabaseDriverDiscovery(); + $discovery = new DatabaseDriverDiscovery(); return $discovery->detectDatabaseTypes(); } @@ -160,7 +161,7 @@ function drupal_detect_database_types() { * \Drupal\Core\Database\DatabaseDriverDiscovery component. */ function drupal_get_database_types() { - $discovery = new \Drupal\Core\Database\DatabaseDriverDiscovery(); + $discovery = new DatabaseDriverDiscovery(); return $discovery->getDatabaseTypes(); } @@ -1086,6 +1087,6 @@ function install_profile_info($profile, $langcode = 'en') { * \Drupal\Core\Database\DatabaseDriverDiscovery component. */ function db_installer_object($driver) { - $discovery = new \Drupal\Core\Database\DatabaseDriverDiscovery(); + $discovery = new DatabaseDriverDiscovery(); return $discovery->getInstallerObject($driver); } diff --git a/core/lib/Drupal/Core/Database/DatabaseDriverDiscovery.php b/core/lib/Drupal/Core/Database/DatabaseDriverDiscovery.php index 2c81f13..0f5a9f2 100644 --- a/core/lib/Drupal/Core/Database/DatabaseDriverDiscovery.php +++ b/core/lib/Drupal/Core/Database/DatabaseDriverDiscovery.php @@ -16,13 +16,6 @@ class DatabaseDriverDiscovery { protected $drupalRoot; /** - * The Drupal function pattern. - * - * @var string - */ - protected $drupalFunctionPattern; - - /** * Available locations for drivers * * @var mixed[] @@ -33,8 +26,8 @@ class DatabaseDriverDiscovery { * Get an instance of DatabaseDriverDiscovery. */ public function __construct() { - $this->drupalRoot = DRUPAL_ROOT; - $this->drupalFunctionPattern = DRUPAL_PHP_FUNCTION_PATTERN; + // Hard-coded DRUPAL_ROOT (because bootstrap.inc is not accessible). + $this->drupalRoot = dirname(dirname(dirname(dirname(dirname(__DIR__))))); // See composer.json for discoverable namespaces. $this->discoveryLocations = [ 'Drupal\\Core\\Database\\Driver' => '/core/lib/Drupal/Core/Database/Driver', @@ -93,7 +86,7 @@ public function getDatabaseTypes() { * @return \Drupal\Core\Database\Install\Tasks * A class defining the requirements and tasks for installing the database. */ - function getInstallerObject($driver) { + public function getInstallerObject($driver) { $drivers = $this->discoverDatabaseDrivers(); return $drivers[$driver]['installer']; } @@ -106,7 +99,6 @@ public function discoverDatabaseDrivers() { $drivers = []; // The internal database driver name is any valid PHP identifier. - $mask = '/^' . $this->drupalFunctionPattern . '$/'; $files = []; foreach ($this->discoveryLocations as $namespace => $location) { if (is_dir($this->drupalRoot . $location)) { @@ -142,4 +134,4 @@ public function discoverDatabaseDrivers() { return $drivers; } -} \ No newline at end of file +} diff --git a/core/tests/Drupal/Tests/Core/Database/UrlConversionTest.php b/core/tests/Drupal/Tests/Core/Database/UrlConversionTest.php index 29a0c27..8b764ef 100644 --- a/core/tests/Drupal/Tests/Core/Database/UrlConversionTest.php +++ b/core/tests/Drupal/Tests/Core/Database/UrlConversionTest.php @@ -43,6 +43,7 @@ public function providerConvertDbUrlToConnectionInfo() { 'port' => 3306, 'username' => 'test_user', 'password' => 'test_pass', + 'namespace' => 'Drupal\Core\Database\Driver\mysql', ]; $root2 = '/var/www/d8'; $url2 = 'sqlite://test_user:test_pass@test_host:3306/test_database'; @@ -50,6 +51,7 @@ public function providerConvertDbUrlToConnectionInfo() { 'driver' => 'sqlite', 'database' => $root2 . '/test_database', 'prefix' => NULL, + 'namespace' => 'Drupal\Core\Database\Driver\sqlite', ]; return [ [$root1, $url1, $database_array1],