diff options
author | Joas Schilling <coding@schilljs.com> | 2018-04-19 12:49:36 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2018-05-09 10:50:56 +0200 |
commit | 7bb44214a185c610120789c8014ccef454e7dba5 (patch) | |
tree | ce2b9fcce3ae5af0c60c8db576014d7f6ca04166 /lib/private | |
parent | 02388a39423ef403f677e810b1f20504693e7714 (diff) | |
download | nextcloud-server-7bb44214a185c610120789c8014ccef454e7dba5.tar.gz nextcloud-server-7bb44214a185c610120789c8014ccef454e7dba5.zip |
Move regex to a function and add tests
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/DB/ConnectionFactory.php | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/lib/private/DB/ConnectionFactory.php b/lib/private/DB/ConnectionFactory.php index bfa2cf5b7b4..3ce1dd3bc05 100644 --- a/lib/private/DB/ConnectionFactory.php +++ b/lib/private/DB/ConnectionFactory.php @@ -193,17 +193,7 @@ class ConnectionFactory { $connectionParams['path'] = $dataDir . '/' . $name . '.db'; } else { $host = $this->config->getValue('dbhost', ''); - $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'] = $matches[2]; - } - } - $connectionParams['host'] = $host; + $connectionParams = array_merge($connectionParams, $this->splitHostFromPortAndSocket($host)); $connectionParams['dbname'] = $name; } @@ -233,4 +223,27 @@ class ConnectionFactory { return $connectionParams; } + + /** + * @param string $host + * @return array + */ + protected function splitHostFromPortAndSocket($host): array { + $params = [ + 'host' => $host, + ]; + + $matches = []; + if (preg_match('/^(.*):([^\]:]+)$/', $host, $matches)) { + // Host variable carries a port or socket. + $params['host'] = $matches[1]; + if (is_numeric($matches[2])) { + $params['port'] = (int) $matches[2]; + } else { + $params['unix_socket'] = $matches[2]; + } + } + + return $params; + } } |