aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Config/PresetManager.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Config/PresetManager.php')
-rw-r--r--lib/private/Config/PresetManager.php48
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/private/Config/PresetManager.php b/lib/private/Config/PresetManager.php
new file mode 100644
index 00000000000..d9c029d15c2
--- /dev/null
+++ b/lib/private/Config/PresetManager.php
@@ -0,0 +1,48 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+
+namespace OC\Config;
+
+use OCP\Config\Lexicon\Preset;
+use OCP\IConfig;
+
+/**
+ * tools to maintains configurations
+ */
+class PresetManager {
+ private const PRESET_CONFIGKEY = 'config_preset';
+
+ private ?Preset $configLexiconPreset = null;
+
+ public function __construct(
+ private readonly IConfig $config,
+ private readonly ConfigManager $configManager,
+ ) {
+ }
+
+ /**
+ * store in config.php the new preset
+ * refresh cached preset
+ */
+ public function setLexiconPreset(Preset $preset): void {
+ $this->config->setSystemValue(self::PRESET_CONFIGKEY, $preset->value);
+ $this->configLexiconPreset = $preset;
+ $this->configManager->clearConfigCaches();
+ }
+
+ /**
+ * returns currently selected Preset
+ */
+ public function getLexiconPreset(): Preset {
+ if ($this->configLexiconPreset === null) {
+ $this->configLexiconPreset = Preset::tryFrom($this->config->getSystemValueInt(self::PRESET_CONFIGKEY, 0)) ?? Preset::NONE;
+ }
+
+ return $this->configLexiconPreset;
+ }
+}