Skip to content

Commit 543b714

Browse files
committed
new tests
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent 4b8ad88 commit 543b714

3 files changed

Lines changed: 1360 additions & 10 deletions

File tree

lib/private/AppConfig.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,17 @@ public function isLazy(string $app, string $key): bool {
210210
* @return array<string, string> [configKey => configValue]
211211
* @since 29.0.0
212212
*/
213-
public function getAllValues(string $app, string $key = '', bool $filtered = false): array {
214-
$this->assertParams($app, $key);
213+
public function getAllValues(string $app, string $prefix = '', bool $filtered = false): array {
214+
$this->assertParams($app, $prefix);
215215
// if we want to filter values, we need to get sensitivity
216216
$this->loadConfigAll();
217217
// array_merge() will remove numeric keys (here config keys), so addition arrays instead
218-
$values = ($this->fastCache[$app] ?? []) + ($this->lazyCache[$app] ?? []);
218+
$values = array_filter(
219+
(($this->fastCache[$app] ?? []) + ($this->lazyCache[$app] ?? [])),
220+
function (string $key) use ($prefix): bool {
221+
return str_starts_with($key, $prefix); // filter values based on $prefix
222+
}, ARRAY_FILTER_USE_KEY
223+
);
219224

220225
if (!$filtered) {
221226
return $values;
@@ -836,10 +841,6 @@ public function updateType(string $app, string $key, int $type = self::VALUE_MIX
836841
$this->loadConfigAll();
837842
$lazy = $this->isLazy($app, $key);
838843

839-
if (!$this->hasKey($app, $key, $lazy)) {
840-
throw new AppConfigUnknownKeyException('Unknown config key');
841-
}
842-
843844
// type can only be one type
844845
if (!in_array($type, [self::VALUE_MIXED, self::VALUE_STRING, self::VALUE_INT, self::VALUE_FLOAT, self::VALUE_BOOL, self::VALUE_ARRAY])) {
845846
throw new AppConfigIncorrectTypeException('Unknown value type');

lib/public/IAppConfig.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,13 @@ public function isLazy(string $app, string $key): bool;
137137
* **WARNING:** ignore lazy filtering, all config values are loaded from database
138138
*
139139
* @param string $app id of the app
140-
* @param string $key config keys prefix to search, can be empty.
140+
* @param string $prefix config keys prefix to search, can be empty.
141141
* @param bool $filtered filter sensitive config values
142142
*
143143
* @return array<string, string> [configKey => configValue]
144144
* @since 29.0.0
145145
*/
146-
public function getAllValues(string $app, string $key = '', bool $filtered = false): array;
146+
public function getAllValues(string $app, string $prefix = '', bool $filtered = false): array;
147147

148148
/**
149149
* List all apps storing a specific config key and its stored value.
@@ -152,7 +152,7 @@ public function getAllValues(string $app, string $key = '', bool $filtered = fal
152152
* @param string $key config key
153153
* @param bool $lazy search within lazy loaded config
154154
*
155-
* @return array<string, string> [appId => configValue]
155+
* @return array<string, string|int|float|bool|array> [appId => configValue]
156156
* @since 29.0.0
157157
*/
158158
public function searchValues(string $key, bool $lazy = false): array;

0 commit comments

Comments
 (0)