37 lines
715 B
PHP
37 lines
715 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Support\Settings;
|
|
|
|
use Closure;
|
|
|
|
final readonly class SettingDefinition
|
|
{
|
|
/**
|
|
* @param array<int, string> $rules
|
|
*/
|
|
public function __construct(
|
|
public string $domain,
|
|
public string $key,
|
|
public string $type,
|
|
public mixed $systemDefault,
|
|
public array $rules,
|
|
private ?Closure $normalizer = null,
|
|
) {}
|
|
|
|
public function dotKey(): string
|
|
{
|
|
return $this->domain.'.'.$this->key;
|
|
}
|
|
|
|
public function normalize(mixed $value): mixed
|
|
{
|
|
if ($this->normalizer instanceof Closure) {
|
|
return ($this->normalizer)($value);
|
|
}
|
|
|
|
return $value;
|
|
}
|
|
}
|