Browse Source

feat(lexicon): better numeric conversion

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/52832/head
Maxence Lange 5 months ago
parent
commit
d860cfd1cb
  1. 1
      lib/private/AppConfig.php
  2. 4
      lib/private/Config/ConfigManager.php
  3. 1
      lib/private/Config/UserConfig.php

1
lib/private/AppConfig.php

@ -480,6 +480,7 @@ class AppConfig implements IAppConfig {
// in case the key was modified while running matchAndApplyLexiconDefinition() we are
// interested to check options in case a modification of the value is needed
// ie inverting value from previous key when using lexicon option RENAME_INVERT_BOOLEAN
if ($origKey !== $key && $type === self::VALUE_BOOL) {
$configManager = Server::get(ConfigManager::class);
$value = ($configManager->convertToBool($value, $this->getLexiconEntry($app, $key))) ? '1' : '0';

4
lib/private/Config/ConfigManager.php

@ -205,7 +205,7 @@ class ConfigManager {
}
public function convertToInt(string $value): int {
if ($value !== ((string)((int)$value))) {
if (!is_numeric($value) || (float)$value <> (int)$value) {
throw new TypeConflictException('Value is not an integer');
}
@ -213,7 +213,7 @@ class ConfigManager {
}
public function convertToFloat(string $value): float {
if ($value !== ((string)((float)$value))) {
if (!is_numeric($value)) {
throw new TypeConflictException('Value is not a float');
}

1
lib/private/Config/UserConfig.php

@ -760,6 +760,7 @@ class UserConfig implements IUserConfig {
// in case the key was modified while running matchAndApplyLexiconDefinition() we are
// interested to check options in case a modification of the value is needed
// ie inverting value from previous key when using lexicon option RENAME_INVERT_BOOLEAN
if ($origKey !== $key && $type === ValueType::BOOL) {
$configManager = Server::get(ConfigManager::class);
$value = ($configManager->convertToBool($value, $this->getLexiconEntry($app, $key))) ? '1' : '0';

Loading…
Cancel
Save