Allow IPv6 database hosts

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2018-04-18 14:47:04 +02:00
parent 44255faab3
commit 02388a3942
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
1 changed files with 7 additions and 6 deletions

View File

@ -193,13 +193,14 @@ class ConnectionFactory {
$connectionParams['path'] = $dataDir . '/' . $name . '.db';
} else {
$host = $this->config->getValue('dbhost', '');
if (strpos($host, ':')) {
// Host variable may carry a port or socket.
list($host, $portOrSocket) = explode(':', $host, 2);
if (ctype_digit($portOrSocket)) {
$connectionParams['port'] = $portOrSocket;
$matches = [];
if (preg_match('/^(.*):([^\]:]+)$/', $host, $matches)) {
// Host variable carries a port or socket.
$host = $matches[1];
if (is_numeric($matches[2])) {
$connectionParams['port'] = (int) $matches[2];
} else {
$connectionParams['unix_socket'] = $portOrSocket;
$connectionParams['unix_socket'] = $matches[2];
}
}
$connectionParams['host'] = $host;