drupal_get_database_types

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.

File

core/includes/install.inc, line 160
API functions for installing modules and themes.

Code

function drupal_get_database_types() {
  $databases = array();
  $drivers = array();

  // The internal database driver name is any valid PHP identifier.
  $mask = '/^' . DRUPAL_PHP_FUNCTION_PATTERN . '$/';
  $files = file_scan_directory(DRUPAL_ROOT . '/core/lib/Drupal/Core/Database/Driver', $mask, array('recurse' => FALSE));
  if (is_dir(DRUPAL_ROOT . '/drivers/lib/Drupal/Driver/Database')) {
    $files += file_scan_directory(DRUPAL_ROOT . '/drivers/lib/Drupal/Driver/Database/', $mask, array('recurse' => FALSE));
  }
  foreach ($files as $file) {
    if (file_exists($file->uri . '/Install/Tasks.php')) {
      $drivers[$file->filename] = $file->uri;
    }
  }
  foreach ($drivers as $driver => $file) {
    $installer = db_installer_object($driver);
    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 = array('mysql' => $mysql_database) + $databases;
  }

  return $databases;
}
doc_Drupal
2016-10-29 09:03:13
Comments
Leave a Comment

Please login to continue.