summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2018-04-19 12:49:36 +0200
committerJoas Schilling <coding@schilljs.com>2018-04-19 12:49:36 +0200
commit78ee3abb786eea385b3149279ba6d8903d8a7b1a (patch)
tree5dce50c8b8b27526e18d7c9cd5ce30bf9814f847 /lib
parent8f7a0af9515a6441b692719310c3e02832d9de65 (diff)
downloadnextcloud-server-78ee3abb786eea385b3149279ba6d8903d8a7b1a.tar.gz
nextcloud-server-78ee3abb786eea385b3149279ba6d8903d8a7b1a.zip
Move regex to a function and add tests
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/DB/ConnectionFactory.php35
1 files changed, 24 insertions, 11 deletions
diff --git a/lib/private/DB/ConnectionFactory.php b/lib/private/DB/ConnectionFactory.php
index f5b8a9d3c2f..9fc2ed42c33 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;
+ }
}