function drupal_get_database_types
Same name in other branches
- 7.x includes/install.inc \drupal_get_database_types()
- 9 core/includes/install.inc \drupal_get_database_types()
- 10 core/includes/install.inc \drupal_get_database_types()
Returns all supported database driver installer objects.
Return value
\Drupal\Core\Database\Install\Tasks[] An array of available database driver installer objects.
11 calls to drupal_get_database_types()
- CredentialForm::getDatabaseTypes in core/
modules/ migrate_drupal_ui/ src/ Form/ CredentialForm.php - Returns all supported database driver installer objects.
- drupal_detect_database_types in core/
includes/ install.inc - Detects all supported databases that are compiled into PHP.
- FunctionalTestSetupTrait::getDatabaseTypes in core/
lib/ Drupal/ Core/ Test/ FunctionalTestSetupTrait.php - Returns all supported database driver installer objects.
- IdConflictTest::testMigrateUpgradeExecute in core/
modules/ migrate_drupal_ui/ tests/ src/ Functional/ d6/ IdConflictTest.php - Tests ID Conflict form.
- IdConflictTest::testMigrateUpgradeExecute in core/
modules/ migrate_drupal_ui/ tests/ src/ Functional/ d7/ IdConflictTest.php - Tests ID Conflict form.
File
-
core/
includes/ install.inc, line 168
Code
function drupal_get_database_types() {
$databases = [];
$drivers = [];
// The internal database driver name is any valid PHP identifier.
$mask = ExtensionDiscovery::PHP_FUNCTION_PATTERN;
// Find drivers in the Drupal\Core and Drupal\Driver namespaces.
/** @var \Drupal\Core\File\FileSystemInterface $file_system */
$file_system = \Drupal::service('file_system');
$files = $file_system->scanDirectory(DRUPAL_ROOT . '/core/lib/Drupal/Core/Database/Driver', $mask, [
'recurse' => FALSE,
]);
if (is_dir(DRUPAL_ROOT . '/drivers/lib/Drupal/Driver/Database')) {
$files += $file_system->scanDirectory(DRUPAL_ROOT . '/drivers/lib/Drupal/Driver/Database/', $mask, [
'recurse' => FALSE,
]);
}
foreach ($files as $file) {
if (file_exists($file->uri . '/Install/Tasks.php')) {
// The namespace doesn't need to be added here, because
// db_installer_object() will find it.
$drivers[$file->filename] = NULL;
}
}
// Find drivers in Drupal module namespaces.
/** @var \Composer\Autoload\ClassLoader $class_loader */
$class_loader = \Drupal::service('class_loader');
// We cannot use the file cache because it does not always exist.
$extension_discovery = new ExtensionDiscovery(DRUPAL_ROOT, FALSE, []);
$modules = $extension_discovery->scan('module');
foreach ($modules as $module) {
$module_driver_path = DRUPAL_ROOT . '/' . $module->getPath() . '/src/Driver/Database';
if (is_dir($module_driver_path)) {
$driver_files = $file_system->scanDirectory($module_driver_path, $mask, [
'recurse' => FALSE,
]);
foreach ($driver_files as $driver_file) {
$tasks_file = $module_driver_path . '/' . $driver_file->filename . '/Install/Tasks.php';
if (file_exists($tasks_file)) {
$namespace = 'Drupal\\' . $module->getName() . '\\Driver\\Database\\' . $driver_file->filename;
// The namespace needs to be added for db_installer_object() to find
// it.
$drivers[$driver_file->filename] = $namespace;
// The directory needs to be added to the autoloader, because this is
// early in the installation process: the module hasn't been enabled
// yet and the database connection info array (including its 'autoload'
// key) hasn't been created yet.
$class_loader->addPsr4($namespace . '\\', $module->getPath() . '/src/Driver/Database/' . $driver_file->filename);
}
}
}
}
foreach ($drivers as $driver => $namespace) {
$installer = db_installer_object($driver, $namespace);
if ($installer->installable()) {
$databases[$driver] = $installer;
}
}
// Usability: unconditionally put the MySQL driver on top.
if (isset($databases['mysql'])) {
$mysql_database = $databases['mysql'];
unset($databases['mysql']);
$databases = [
'mysql' => $mysql_database,
] + $databases;
}
return $databases;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.