diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2024-02-07 12:22:02 -0100 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2024-02-07 12:24:57 -0100 |
commit | 2122a814198d1f6343f38f12e5c41a6b6c58d6a4 (patch) | |
tree | 241328279c4c581283791a25e5c0eeb49113e96a /lib | |
parent | 7891c052244e561b42fc865d7636db8bd896184f (diff) | |
download | nextcloud-server-2122a814198d1f6343f38f12e5c41a6b6c58d6a4.tar.gz nextcloud-server-2122a814198d1f6343f38f12e5c41a6b6c58d6a4.zip |
fix getAllValues() to filter values based on prefix
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/AppConfig.php | 11 | ||||
-rw-r--r-- | lib/public/IAppConfig.php | 6 |
2 files changed, 11 insertions, 6 deletions
diff --git a/lib/private/AppConfig.php b/lib/private/AppConfig.php index 60b0e77f7af..f42dddf663d 100644 --- a/lib/private/AppConfig.php +++ b/lib/private/AppConfig.php @@ -210,12 +210,17 @@ class AppConfig implements IAppConfig { * @return array<string, string> [configKey => configValue] * @since 29.0.0 */ - public function getAllValues(string $app, string $key = '', bool $filtered = false): array { - $this->assertParams($app, $key); + public function getAllValues(string $app, string $prefix = '', bool $filtered = false): array { + $this->assertParams($app, $prefix); // if we want to filter values, we need to get sensitivity $this->loadConfigAll(); // array_merge() will remove numeric keys (here config keys), so addition arrays instead - $values = ($this->fastCache[$app] ?? []) + ($this->lazyCache[$app] ?? []); + $values = array_filter( + (($this->fastCache[$app] ?? []) + ($this->lazyCache[$app] ?? [])), + function (string $key) use ($prefix): bool { + return str_starts_with($key, $prefix); // filter values based on $prefix + }, ARRAY_FILTER_USE_KEY + ); if (!$filtered) { return $values; diff --git a/lib/public/IAppConfig.php b/lib/public/IAppConfig.php index 9bdeb14b295..afcdf67f92c 100644 --- a/lib/public/IAppConfig.php +++ b/lib/public/IAppConfig.php @@ -137,13 +137,13 @@ interface IAppConfig { * **WARNING:** ignore lazy filtering, all config values are loaded from database * * @param string $app id of the app - * @param string $key config keys prefix to search, can be empty. + * @param string $prefix config keys prefix to search, can be empty. * @param bool $filtered filter sensitive config values * * @return array<string, string> [configKey => configValue] * @since 29.0.0 */ - public function getAllValues(string $app, string $key = '', bool $filtered = false): array; + public function getAllValues(string $app, string $prefix = '', bool $filtered = false): array; /** * List all apps storing a specific config key and its stored value. @@ -152,7 +152,7 @@ interface IAppConfig { * @param string $key config key * @param bool $lazy search within lazy loaded config * - * @return array<string, string> [appId => configValue] + * @return array<string, string|int|float|bool|array> [appId => configValue] * @since 29.0.0 */ public function searchValues(string $key, bool $lazy = false): array; |