You are here

public static function Database::getConnectionInfoAsUrl in Zircon Profile 8

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

Gets database connection info as a URL.

Parameters

string $key: (Optional) The database connection key.

Return value

string The connection info as a URL.

1 call to Database::getConnectionInfoAsUrl()
simpletest_phpunit_run_command in core/modules/simpletest/simpletest.module
Executes the PHPUnit command.

File

core/lib/Drupal/Core/Database/Database.php, line 504
Contains \Drupal\Core\Database\Database.

Class

Database
Primary front-controller for the database system.

Namespace

Drupal\Core\Database

Code

public static function getConnectionInfoAsUrl($key = 'default') {
  $db_info = static::getConnectionInfo($key);
  if ($db_info['default']['driver'] == 'sqlite') {
    $db_url = 'sqlite://localhost/' . $db_info['default']['database'];
  }
  else {
    $user = '';
    if ($db_info['default']['username']) {
      $user = $db_info['default']['username'];
      if ($db_info['default']['password']) {
        $user .= ':' . $db_info['default']['password'];
      }
      $user .= '@';
    }
    $db_url = $db_info['default']['driver'] . '://' . $user . $db_info['default']['host'];
    if (isset($db_info['default']['port'])) {
      $db_url .= ':' . $db_info['default']['port'];
    }
    $db_url .= '/' . $db_info['default']['database'];
  }
  if ($db_info['default']['prefix']['default']) {
    $db_url .= '#' . $db_info['default']['prefix']['default'];
  }
  return $db_url;
}