private static function parseDatabaseUrl(array $params)
{
if (!isset($params['url'])) {
return $params;
}
// (pdo_)?sqlite3?:///... => (pdo_)?sqlite3?://localhost/... or else the URL will be invalid
$url = preg_replace('#^((?:pdo_)?sqlite3?):///#', '$1://localhost/', $params['url']);
// PHP < 5.4.8 doesn't parse schemeless urls properly.
// See: https://php.net/parse-url#refsect1-function.parse-url-changelog
if (PHP_VERSION_ID < 50408 && strpos($url, '//') === 0) {
$url = parse_url('fake:' . $url);
unset($url['scheme']);
} else {
$url = parse_url($url);
}
if ($url === false) {
throw new DBALException('Malformed parameter "url".');
}
// If we have a connection URL, we have to unset the default PDO instance connection parameter (if any)
// as we cannot merge connection details from the URL into the PDO instance (URL takes precedence).
unset($params['pdo']);
$params = self::parseDatabaseUrlScheme($url, $params);
if (isset($url['host'])) {
$params['host'] = $url['host'];
}
if (isset($url['port'])) {
$params['port'] = $url['port'];
}
if (isset($url['user'])) {
$params['user'] = $url['user'];
}
if (isset($url['pass'])) {
$params['password'] = $url['pass'];
}
$params = self::parseDatabaseUrlPath($url, $params);
$params = self::parseDatabaseUrlQuery($url, $params);
return $params;
}