3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Core\Config\Model;
24 use Friendica\Core\Config\Capability\IManageConfigValues;
25 use Friendica\Core\Config\Util\ConfigFileManager;
26 use Friendica\Core\Config\ValueObject\Cache;
29 * Configuration model, which manages the whole system configuration
31 class Config implements IManageConfigValues
36 protected $configCache;
38 /** @var ConfigFileManager */
39 protected $configFileManager;
42 * @param ConfigFileManager $configFileManager The configuration file manager to save back configs
43 * @param Cache $configCache The configuration cache (based on the config-files)
45 public function __construct(ConfigFileManager $configFileManager, Cache $configCache)
47 $this->configFileManager = $configFileManager;
48 $this->configCache = $configCache;
54 public function getCache(): Cache
56 return $this->configCache;
59 public function save()
61 $this->configFileManager->saveData($this->configCache);
64 public function load(string $cat = 'config')
66 $configCache = new Cache();
68 $this->configFileManager->setupCache($configCache, $_SERVER);
69 $this->configCache = $configCache;
72 public function get(string $cat, string $key, $default_value = null, bool $refresh = false)
74 return $this->configCache->get($cat, $key) ?? $default_value;
77 public function set(string $cat, string $key, $value, bool $autosave = true): bool
79 $stored = $this->configCache->set($cat, $key, $value, Cache::SOURCE_DATA);
81 if ($stored && $autosave) {
88 public function delete(string $cat, string $key, bool $autosave = true): bool
90 $removed = $this->configCache->delete($cat, $key);
92 if ($removed && $autosave) {