You are here

final public static function Database::parseConnectionInfo in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Database/Database.php \Drupal\Core\Database\Database::parseConnectionInfo()

Process the configuration file for database information.

Parameters

array $info: The database connection information, as defined in settings.php. The structure of this array depends on the database driver it is connecting to.

1 call to Database::parseConnectionInfo()
Database::addConnectionInfo in core/lib/Drupal/Core/Database/Database.php
Adds database connection information for a given key/target.

File

core/lib/Drupal/Core/Database/Database.php, line 210

Class

Database
Primary front-controller for the database system.

Namespace

Drupal\Core\Database

Code

public static final function parseConnectionInfo(array $info) {

  // If there is no "driver" property, then we assume it's an array of
  // possible connections for this target. Pick one at random. That allows
  // us to have, for example, multiple replica servers.
  if (empty($info['driver'])) {
    $info = $info[mt_rand(0, count($info) - 1)];
  }

  // Parse the prefix information.
  // @todo in Drupal 10, fail hard if $info['prefix'] is an array.
  // @see https://www.drupal.org/project/drupal/issues/3124382
  if (!isset($info['prefix'])) {

    // Default to an empty prefix.
    $info['prefix'] = '';
  }
  elseif (is_array($info['prefix'])) {
    $prefix = $info['prefix']['default'] ?? '';
    unset($info['prefix']['default']);

    // If there are keys left besides the 'default' one, we are in a
    // multi-prefix scenario (for per-table prefixing, or migrations).
    // In that case, we put the non-default keys in a 'extra_prefix' key
    // to avoid mixing up with the normal 'prefix', which is a string since
    // Drupal 9.1.0.
    if (count($info['prefix'])) {
      $info['extra_prefix'] = $info['prefix'];
    }
    $info['prefix'] = $prefix;
  }

  // Fallback for Drupal 7 settings.php if namespace is not provided.
  if (empty($info['namespace'])) {
    $info['namespace'] = 'Drupal\\Core\\Database\\Driver\\' . $info['driver'];
  }
  return $info;
}