function Database::parseConnectionInfo

Same name in other branches
  1. 7.x includes/database/database.inc \Database::parseConnectionInfo()
  2. 9 core/lib/Drupal/Core/Database/Database.php \Drupal\Core\Database\Database::parseConnectionInfo()
  3. 8.9.x core/lib/Drupal/Core/Database/Database.php \Drupal\Core\Database\Database::parseConnectionInfo()
  4. 11.x 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 232

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)];
    }
    // Prefix information, default to an empty prefix.
    $info['prefix'] = $info['prefix'] ?? '';
    // 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']) || str_starts_with($info['namespace'], 'Drupal\\Core\\Database\\Driver\\')) {
        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;
        }
    }
    return $info;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.