function Database::parseConnectionInfo

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

5 calls to Database::parseConnectionInfo()
Database::getConnectionInfo in includes/database/database.inc
Gets information on the specified database connection.
Database::openConnection in includes/database/database.inc
Opens a connection to the server specified by the given key and target.
Database::renameConnection in includes/database/database.inc
Rename a connection and its corresponding connection information.
Database::setActiveConnection in includes/database/database.inc
Sets the active connection to the specified key.
install_database_errors in includes/install.core.inc
Checks a database connection and returns any errors.

File

includes/database/database.inc, line 1622

Class

Database
Primary front-controller for the database system.

Code

public static final function parseConnectionInfo() {
    global $databases;
    $database_info = is_array($databases) ? $databases : array();
    foreach ($database_info as $index => $info) {
        foreach ($database_info[$index] as $target => $value) {
            // 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 slave servers.
            if (empty($value['driver'])) {
                $database_info[$index][$target] = $database_info[$index][$target][mt_rand(0, count($database_info[$index][$target]) - 1)];
            }
            // Parse the prefix information.
            if (!isset($database_info[$index][$target]['prefix'])) {
                // Default to an empty prefix.
                $database_info[$index][$target]['prefix'] = array(
                    'default' => '',
                );
            }
            elseif (!is_array($database_info[$index][$target]['prefix'])) {
                // Transform the flat form into an array form.
                $database_info[$index][$target]['prefix'] = array(
                    'default' => $database_info[$index][$target]['prefix'],
                );
            }
        }
    }
    if (!is_array(self::$databaseInfo)) {
        self::$databaseInfo = $database_info;
    }
    else {
        foreach ($database_info as $database_key => $database_values) {
            foreach ($database_values as $target => $target_values) {
                self::$databaseInfo[$database_key][$target] = $target_values;
            }
        }
    }
}

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