From dc14adf65521d30b80a182a35e79af12faed70c6 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Mon, 27 Apr 2026 15:08:20 -0400 Subject: [PATCH] refactor: Improve getDriverConfig() --- src/Horde.php | 44 +++++++++++++++++++------------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/src/Horde.php b/src/Horde.php index 0c650221..de631b05 100644 --- a/src/Horde.php +++ b/src/Horde.php @@ -597,41 +597,35 @@ public static function getDriverConfig(string|array $backend, ?string $type = 's { global $conf; - if ($type !== null) { + if ($type === null) { + $confType = []; + } else { $type = HordeString::lower($type); + $confType = $conf[$type] ?? []; } - if (is_array($backend)) { - $c = ArrayUtils::getElement($conf, $backend); - } elseif (isset($conf[$backend])) { - $c = $conf[$backend]; - } else { - $c = null; - } + $c = ArrayUtils::getElement($conf, $backend); - if ($c !== null && isset($c['params'])) { - $c['params']['umask'] = $conf['umask']; + if (is_array($c)) { + $params = $c['params'] ?? null; + if (is_array($params)) { + $params['umask'] = $conf['umask']; - $result = ($type !== null && isset($conf[$type])) - ? array_merge($conf[$type], $c['params']) - : $c['params']; + $result = array_merge($confType, $params); - if ((!isset($c['params']['driverconfig']) - || $c['params']['driverconfig'] != 'horde') - && $type !== null && $type === 'sql') { - if (($c['params']['protocol'] ?? null) === 'unix') { - unset($result['hostspec'], $result['port']); - } else { - unset($result['socket']); + if ($type === 'sql' && ($params['driverconfig'] ?? null) !== 'horde') { + if (($params['protocol'] ?? null) === 'unix') { + unset($result['hostspec'], $result['port']); + } else { + unset($result['socket']); + } } - } - return $result; + return $result; + } } - return ($type !== null && isset($conf[$type])) - ? $conf[$type] - : []; + return $confType; } /**