function url_to_connection_info in Acquia Cloud Site Factory Connector 8.2
Same name and namespace in other branches
- 8 acsf_init/lib/cloud_hooks/acquia/db_connect.php \url_to_connection_info()
Converts a URL to a database connection info array.
Array keys are gleaned from Database::convertDbUrlToConnectionInfo().
Parameters
string $url: The URL.
Return value
array The database connection info, or empty array if none found.
1 call to url_to_connection_info()
- get_db in acsf_init/
lib/ cloud_hooks/ acquia/ db_connect.php - Initiates a connection to a specified database.
File
- acsf_init/
lib/ cloud_hooks/ acquia/ db_connect.php, line 64 - This file provides helper functions for running Acquia Cloud hooks.
Code
function url_to_connection_info($url) {
$info = parse_url($url);
if (!isset($info['scheme'], $info['host'], $info['path'])) {
return [];
}
$info += [
'user' => '',
'pass' => '',
];
if ($info['path'][0] === '/') {
$info['path'] = substr($info['path'], 1);
}
$database = [
'driver' => $info['scheme'],
'username' => $info['user'],
'password' => $info['pass'],
'host' => $info['host'],
'database' => $info['path'],
];
if (isset($info['port'])) {
$database['port'] = $info['port'];
}
return $database;
}