Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IAppConfig] new tests #43370

Merged
merged 6 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions lib/private/AppConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,18 +204,23 @@ public function isLazy(string $app, string $key): bool {
* @inheritDoc
*
* @param string $app id of the app
* @param string $key config keys prefix to search
* @param string $prefix config keys prefix to search
* @param bool $filtered TRUE to hide sensitive config values. Value are replaced by {@see IConfig::SENSITIVE_VALUE}
*
* @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 {
ArtificialOwl marked this conversation as resolved.
Show resolved Hide resolved
$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;
Expand Down Expand Up @@ -839,10 +844,6 @@ public function updateType(string $app, string $key, int $type = self::VALUE_MIX
$this->loadConfigAll();
$lazy = $this->isLazy($app, $key);

if (!$this->hasKey($app, $key, $lazy)) {
ArtificialOwl marked this conversation as resolved.
Show resolved Hide resolved
throw new AppConfigUnknownKeyException('Unknown config key');
}

// type can only be one type
if (!in_array($type, [self::VALUE_MIXED, self::VALUE_STRING, self::VALUE_INT, self::VALUE_FLOAT, self::VALUE_BOOL, self::VALUE_ARRAY])) {
throw new AppConfigIncorrectTypeException('Unknown value type');
Expand Down Expand Up @@ -1305,7 +1306,7 @@ public function setValue($app, $key, $value) {
* @param string|false $key
*
* @return array|false
* @deprecated 29.0.0 use getAllValues()
* @deprecated 29.0.0 use {@see getAllValues()}
*/
public function getValues($app, $key) {
if (($app !== false) === ($key !== false)) {
Expand All @@ -1326,7 +1327,7 @@ public function getValues($app, $key) {
* @param string $app
*
* @return array
* @deprecated 29.0.0 use getAllValues()
* @deprecated 29.0.0 use {@see getAllValues()}
*/
public function getFilteredValues($app) {
return $this->getAllValues($app, filtered: true);
Expand Down
6 changes: 3 additions & 3 deletions lib/public/IAppConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ public function isLazy(string $app, string $key): bool;
* **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.
Expand All @@ -152,7 +152,7 @@ public function getAllValues(string $app, string $key = '', bool $filtered = fal
* @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;
Expand Down
Loading
Loading