Implements the Settings foundation workspace controls. Includes: - Settings foundation UI/controls scoped to workspace context - Related onboarding/consent flow adjustments as included in branch history Testing: - `vendor/bin/sail artisan test --compact --no-ansi --filter=SettingsFoundation` Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #119
62 lines
1.5 KiB
PHP
62 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Support\Settings;
|
|
|
|
final class SettingsRegistry
|
|
{
|
|
/**
|
|
* @var array<string, SettingDefinition>
|
|
*/
|
|
private array $definitions;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->definitions = [];
|
|
|
|
$this->register(new SettingDefinition(
|
|
domain: 'backup',
|
|
key: 'retention_keep_last_default',
|
|
type: 'int',
|
|
systemDefault: 30,
|
|
rules: ['required', 'integer', 'min:1', 'max:3650'],
|
|
normalizer: static fn (mixed $value): int => (int) $value,
|
|
));
|
|
}
|
|
|
|
/**
|
|
* @return array<string, SettingDefinition>
|
|
*/
|
|
public function all(): array
|
|
{
|
|
return $this->definitions;
|
|
}
|
|
|
|
public function find(string $domain, string $key): ?SettingDefinition
|
|
{
|
|
return $this->definitions[$this->cacheKey($domain, $key)] ?? null;
|
|
}
|
|
|
|
public function require(string $domain, string $key): SettingDefinition
|
|
{
|
|
$definition = $this->find($domain, $key);
|
|
|
|
if ($definition instanceof SettingDefinition) {
|
|
return $definition;
|
|
}
|
|
|
|
throw new \InvalidArgumentException(sprintf('Unknown setting key: %s.%s', $domain, $key));
|
|
}
|
|
|
|
private function register(SettingDefinition $definition): void
|
|
{
|
|
$this->definitions[$this->cacheKey($definition->domain, $definition->key)] = $definition;
|
|
}
|
|
|
|
private function cacheKey(string $domain, string $key): string
|
|
{
|
|
return $domain.'.'.$key;
|
|
}
|
|
}
|