Parse port from host

This commit is contained in:
Aaron Piotrowski 2019-09-26 11:23:02 -05:00
parent fcd359de3e
commit 0445ac3562
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB
1 changed files with 7 additions and 1 deletions

View File

@ -5,6 +5,7 @@ namespace Amp\Sql;
abstract class ConnectionConfig
{
const KEY_MAP = [
'hostname' => 'host',
'username' => 'user',
'pass' => 'password',
'database' => 'db',
@ -32,7 +33,7 @@ abstract class ConnectionConfig
* @param string $connectionString
* @param string[] $keymap Map of alternative key names to canonical key names.
*
* @return array
* @return string[]
*/
protected static function parseConnectionString(string $connectionString, array $keymap = self::KEY_MAP): array
{
@ -54,6 +55,11 @@ abstract class ConnectionConfig
$values[$key] = $value;
}
if (\preg_match('/^(.+):(\d{1,5})$/', $values["host"] ?? "", $matches)) {
$values["host"] = $matches[1];
$values["port"] = $matches[2];
}
return $values;
}