mirror of
https://github.com/Vateron-Media/XC_VM.git
synced 2026-10-18 12:02:57 +02:00
Move the last two Core/Config classes into XcVm\Core\Config. SettingsManager
has the largest fan-out of the whole migration (referenced by ~224 files).
- Namespace SettingsManager (self-contained singleton, no class deps) and
SettingsRepository (\FileCache:: qualified).
- Add 'use XcVm\Core\Config\SettingsManager;' to 224 referencing files and
'use ...\SettingsRepository;' to 12 — call sites (SettingsManager::get(), etc.)
unchanged. Done with a token-based inserter (after namespace/declare/<?php,
idempotent, same-namespace files skipped).
- ToolsCommand::processRecaptcha: drop dead class_exists('SettingsManager') +
method_exists guard (always autoloadable now) → call SettingsManager::clearCache()
directly. This was the only string-literal class reference.
Core/Config is now fully namespaced (ConfigReader, DomainResolver, SettingsManager,
SettingsRepository); the procedural constant files (AppConfig/Binaries/Paths)
remain global by design.
Verified: php -l clean (226 files); PHPStan no errors (baseline unchanged — it is
line-independent so the added use-lines don't disturb it); PHPUnit 295/295; all
Config FQCNs resolve via Composer; sample Public referrers lint-clean.
64 lines
1.5 KiB
PHP
64 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace XcVm\Core\Config;
|
|
|
|
/**
|
|
* SettingsManager — singleton-хранилище настроек приложения.
|
|
*
|
|
* Entry points вызывают set(), потребители — getAll() или get().
|
|
*
|
|
* @package XC_VM_Core_Config
|
|
* @author Divarion_D <https://github.com/Divarion-D>
|
|
* @copyright 2025-2026 Vateron Media
|
|
* @link https://github.com/Vateron-Media/XC_VM
|
|
* @license AGPL-3.0 https://www.gnu.org/licenses/agpl-3.0.html
|
|
*/
|
|
|
|
class SettingsManager {
|
|
/** @var array */
|
|
private static $settings = array();
|
|
|
|
/**
|
|
* Сохраняет весь массив настроек.
|
|
*/
|
|
public static function set(array $settings): void {
|
|
self::$settings = $settings;
|
|
}
|
|
|
|
/**
|
|
* Возвращает весь массив настроек.
|
|
*/
|
|
public static function getAll(): array {
|
|
return self::$settings;
|
|
}
|
|
|
|
/**
|
|
* Возвращает значение по ключу.
|
|
*
|
|
* @param string $key
|
|
* @param mixed $default
|
|
* @return mixed
|
|
*/
|
|
public static function get(string $key, $default = null) {
|
|
return self::$settings[$key] ?? $default;
|
|
}
|
|
|
|
/**
|
|
* Обновляет отдельный ключ настроек.
|
|
*/
|
|
public static function update(string $key, $value): void {
|
|
self::$settings[$key] = $value;
|
|
}
|
|
|
|
/**
|
|
* Delete the cached settings file so the next read reloads from source.
|
|
*
|
|
* @return void
|
|
*/
|
|
public static function clearCache() {
|
|
if (file_exists(CACHE_TMP_PATH . 'settings')) {
|
|
unlink(CACHE_TMP_PATH . 'settings');
|
|
}
|
|
}
|
|
}
|