Skip to content

Commit

Permalink
Parse port from host
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Sep 26, 2019
1 parent fcd359d commit 0445ac3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/ConnectionConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
abstract class ConnectionConfig
{
const KEY_MAP = [
'hostname' => 'host',
'username' => 'user',
'pass' => 'password',
'database' => 'db',
Expand Down Expand Up @@ -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
{
Expand All @@ -54,6 +55,11 @@ protected static function parseConnectionString(string $connectionString, array
$values[$key] = $value;
}

if (\preg_match('/^(.+):(\d{1,5})$/', $values["host"] ?? "", $matches)) {
$values["host"] = $matches[1];
$values["port"] = $matches[2];
}

return $values;
}

Expand Down

0 comments on commit 0445ac3

Please sign in to comment.