Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
85.71% |
6 / 7 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Panel | |
85.71% |
6 / 7 |
|
50.00% |
1 / 2 |
5.07 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| strings | |
83.33% |
5 / 6 |
|
0.00% |
0 / 1 |
4.07 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Cosray\Config; |
| 6 | |
| 7 | final class Panel |
| 8 | { |
| 9 | /** @var list<non-empty-string>|null */ |
| 10 | private ?array $themeCache = null; |
| 11 | |
| 12 | public function __construct( |
| 13 | private readonly \Cosray\Config $config, |
| 14 | ) {} |
| 15 | |
| 16 | public string $path { |
| 17 | get => $this->config->get('panel.path'); |
| 18 | } |
| 19 | |
| 20 | /** @var list<non-empty-string> */ |
| 21 | public array $theme { |
| 22 | get => $this->themeCache ??= self::strings($this->config->get('panel.theme')); |
| 23 | } |
| 24 | |
| 25 | public ?string $logo { |
| 26 | get => $this->config->get('panel.logo'); |
| 27 | } |
| 28 | |
| 29 | public bool $dashboard { |
| 30 | get => $this->config->get('panel.dashboard'); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Origins that may frame the panel and its embedded editor, like |
| 35 | * `https://admin.example.com`. |
| 36 | * |
| 37 | * @var list<string> |
| 38 | */ |
| 39 | public array $embed { |
| 40 | get => array_values(array_filter( |
| 41 | (array) $this->config->get('panel.embed'), |
| 42 | static fn(mixed $origin): bool => is_string($origin) && preg_match('#^https?://[^/\s]+$#i', $origin) === 1, |
| 43 | )); |
| 44 | } |
| 45 | |
| 46 | /** Default panel UI language; NULL negotiates from the browser. */ |
| 47 | public ?string $locale { |
| 48 | get => $this->config->get('panel.locale'); |
| 49 | } |
| 50 | |
| 51 | /** @return list<non-empty-string> */ |
| 52 | private static function strings(mixed $value): array |
| 53 | { |
| 54 | if ($value === null) { |
| 55 | return []; |
| 56 | } |
| 57 | |
| 58 | if (is_string($value)) { |
| 59 | $value = trim($value); |
| 60 | |
| 61 | return $value === '' ? [] : [$value]; |
| 62 | } |
| 63 | |
| 64 | return array_values($value); |
| 65 | } |
| 66 | } |