|
14 | 14 | use NCU\Config\Lexicon\ConfigLexiconEntry; |
15 | 15 | use NCU\Config\Lexicon\ConfigLexiconStrictness; |
16 | 16 | use NCU\Config\Lexicon\IConfigLexicon; |
| 17 | +use NCU\Config\Lexicon\Preset; |
17 | 18 | use OC\AppFramework\Bootstrap\Coordinator; |
18 | 19 | use OC\Config\ConfigManager; |
19 | 20 | use OCP\DB\Exception as DBException; |
@@ -64,12 +65,13 @@ class AppConfig implements IAppConfig { |
64 | 65 | /** @var array<string, array{entries: array<string, ConfigLexiconEntry>, aliases: array<string, string>, strictness: ConfigLexiconStrictness}> ['app_id' => ['strictness' => ConfigLexiconStrictness, 'entries' => ['config_key' => ConfigLexiconEntry[]]] */ |
65 | 66 | private array $configLexiconDetails = []; |
66 | 67 | private bool $ignoreLexiconAliases = false; |
67 | | - |
| 68 | + private ?Preset $configLexiconPreset = null; |
68 | 69 | /** @var ?array<string, string> */ |
69 | 70 | private ?array $appVersionsCache = null; |
70 | 71 |
|
71 | 72 | public function __construct( |
72 | 73 | protected IDBConnection $connection, |
| 74 | + protected IConfig $config, |
73 | 75 | protected LoggerInterface $logger, |
74 | 76 | protected ICrypto $crypto, |
75 | 77 | ) { |
@@ -438,9 +440,17 @@ private function getTypedValue( |
438 | 440 | ): string { |
439 | 441 | $this->assertParams($app, $key, valueType: $type); |
440 | 442 | $origKey = $key; |
441 | | - if (!$this->matchAndApplyLexiconDefinition($app, $key, $lazy, $type, $default)) { |
442 | | - return $default; // returns default if strictness of lexicon is set to WARNING (block and report) |
| 443 | + $matched = $this->matchAndApplyLexiconDefinition($app, $key, $lazy, $type, $default); |
| 444 | + if ($default === null) { |
| 445 | + // there is no logical reason for it to be null |
| 446 | + throw new \Exception('default cannot be null'); |
| 447 | + } |
| 448 | + |
| 449 | + // returns default if strictness of lexicon is set to WARNING (block and report) |
| 450 | + if (!$matched) { |
| 451 | + return $default; |
443 | 452 | } |
| 453 | + |
444 | 454 | $this->loadConfig($app, $lazy); |
445 | 455 |
|
446 | 456 | /** |
@@ -1146,7 +1156,8 @@ public function deleteApp(string $app): void { |
1146 | 1156 | */ |
1147 | 1157 | public function clearCache(bool $reload = false): void { |
1148 | 1158 | $this->lazyLoaded = $this->fastLoaded = false; |
1149 | | - $this->lazyCache = $this->fastCache = $this->valueTypes = []; |
| 1159 | + $this->lazyCache = $this->fastCache = $this->valueTypes = $this->configLexiconDetails = []; |
| 1160 | + $this->configLexiconPreset = null; |
1150 | 1161 |
|
1151 | 1162 | if (!$reload) { |
1152 | 1163 | return; |
@@ -1592,7 +1603,7 @@ private function matchAndApplyLexiconDefinition( |
1592 | 1603 | string &$key, |
1593 | 1604 | ?bool &$lazy = null, |
1594 | 1605 | int &$type = self::VALUE_MIXED, |
1595 | | - string &$default = '', |
| 1606 | + ?string &$default = null, |
1596 | 1607 | ): bool { |
1597 | 1608 | if (in_array($key, |
1598 | 1609 | [ |
@@ -1629,7 +1640,11 @@ private function matchAndApplyLexiconDefinition( |
1629 | 1640 | } |
1630 | 1641 |
|
1631 | 1642 | $lazy = $configValue->isLazy(); |
1632 | | - $default = $configValue->getDefault() ?? $default; // default from Lexicon got priority |
| 1643 | + // only look for default if needed, default from Lexicon got priority |
| 1644 | + if ($default !== null) { |
| 1645 | + $default = $configValue->getDefault($this->getLexiconPreset()) ?? $default; |
| 1646 | + } |
| 1647 | + |
1633 | 1648 | if ($configValue->isFlagged(self::FLAG_SENSITIVE)) { |
1634 | 1649 | $type |= self::VALUE_SENSITIVE; |
1635 | 1650 | } |
@@ -1715,6 +1730,14 @@ public function ignoreLexiconAliases(bool $ignore): void { |
1715 | 1730 | $this->ignoreLexiconAliases = $ignore; |
1716 | 1731 | } |
1717 | 1732 |
|
| 1733 | + private function getLexiconPreset(): Preset { |
| 1734 | + if ($this->configLexiconPreset === null) { |
| 1735 | + $this->configLexiconPreset = Preset::tryFrom($this->config->getSystemValueInt(ConfigManager::PRESET_CONFIGKEY, 0)) ?? Preset::NONE; |
| 1736 | + } |
| 1737 | + |
| 1738 | + return $this->configLexiconPreset; |
| 1739 | + } |
| 1740 | + |
1718 | 1741 | /** |
1719 | 1742 | * Returns the installed versions of all apps |
1720 | 1743 | * |
|
0 commit comments