function Connection::createConnectionOptionsFromUrl
Same name in this branch
- 11.x core/modules/sqlite/src/Driver/Database/sqlite/Connection.php \Drupal\sqlite\Driver\Database\sqlite\Connection::createConnectionOptionsFromUrl()
Same name in other branches
- 9 core/modules/sqlite/src/Driver/Database/sqlite/Connection.php \Drupal\sqlite\Driver\Database\sqlite\Connection::createConnectionOptionsFromUrl()
- 9 core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection::createConnectionOptionsFromUrl()
- 8.9.x core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php \Drupal\Core\Database\Driver\sqlite\Connection::createConnectionOptionsFromUrl()
- 8.9.x core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection::createConnectionOptionsFromUrl()
- 10 core/modules/sqlite/src/Driver/Database/sqlite/Connection.php \Drupal\sqlite\Driver\Database\sqlite\Connection::createConnectionOptionsFromUrl()
- 10 core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection::createConnectionOptionsFromUrl()
Creates an array of database connection options from a URL.
@internal This method should only be called from \Drupal\Core\Database\Database::convertDbUrlToConnectionInfo().
Parameters
string $url: The URL.
string $root: (deprecated) The root directory of the Drupal installation. Some database drivers, like for example SQLite, need this information.
Return value
array The connection options.
Throws
\InvalidArgumentException Exception thrown when the provided URL does not meet the minimum requirements.
See also
\Drupal\Core\Database\Database::convertDbUrlToConnectionInfo()
1 call to Connection::createConnectionOptionsFromUrl()
- Connection::createConnectionOptionsFromUrl in core/
modules/ sqlite/ src/ Driver/ Database/ sqlite/ Connection.php - Creates an array of database connection options from a URL.
1 method overrides Connection::createConnectionOptionsFromUrl()
- Connection::createConnectionOptionsFromUrl in core/
modules/ sqlite/ src/ Driver/ Database/ sqlite/ Connection.php - Creates an array of database connection options from a URL.
File
-
core/
lib/ Drupal/ Core/ Database/ Connection.php, line 1334
Class
- Connection
- Base Database API class.
Namespace
Drupal\Core\DatabaseCode
public static function createConnectionOptionsFromUrl($url, $root) {
if ($root !== NULL) {
@trigger_error("Passing the \$root value to " . __METHOD__ . "() is deprecated in drupal:11.2.0 and will be removed in drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3511287", E_USER_DEPRECATED);
}
$url_components = parse_url($url);
if (!isset($url_components['scheme'], $url_components['host'], $url_components['path'])) {
throw new \InvalidArgumentException("The database connection URL '{$url}' is invalid. The minimum requirement is: 'driver://host/database'");
}
$url_components += [
'user' => '',
'pass' => '',
'fragment' => '',
];
// Remove leading slash from the URL path.
if ($url_components['path'][0] === '/') {
$url_components['path'] = substr($url_components['path'], 1);
}
// Use reflection to get the namespace of the class being called.
$reflector = new \ReflectionClass(static::class);
$database = [
'driver' => $url_components['scheme'],
'username' => $url_components['user'],
'password' => $url_components['pass'],
'host' => $url_components['host'],
'database' => $url_components['path'],
'namespace' => $reflector->getNamespaceName(),
];
if (isset($url_components['port'])) {
$database['port'] = $url_components['port'];
}
if (!empty($url_components['fragment'])) {
$database['prefix'] = $url_components['fragment'];
}
return $database;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.