Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
13 / 13 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| Schemas | |
100.00% |
13 / 13 |
|
100.00% |
5 / 5 |
5 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| registry | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| of | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| nav | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Cosray\Collection; |
| 6 | |
| 7 | use Cosray\Collection\Schema\Registry; |
| 8 | use Cosray\NavMeta; |
| 9 | |
| 10 | class Schemas |
| 11 | { |
| 12 | /** @var array<class-string, Schema> */ |
| 13 | private array $cache = []; |
| 14 | |
| 15 | private readonly Registry $registry; |
| 16 | |
| 17 | public function __construct(?Registry $registry = null) |
| 18 | { |
| 19 | $this->registry = $registry ?? Registry::withDefaults(); |
| 20 | } |
| 21 | |
| 22 | public function registry(): Registry |
| 23 | { |
| 24 | return $this->registry; |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * @param class-string $class |
| 29 | */ |
| 30 | public function of(string $class): Schema |
| 31 | { |
| 32 | return $this->cache[$class] ??= new Schema($class, $this->registry); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * @param class-string $class |
| 37 | */ |
| 38 | public function get(string $class, string $key, mixed $default = null): mixed |
| 39 | { |
| 40 | return $this->of($class)->get($key, $default); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * @param class-string $class |
| 45 | */ |
| 46 | public function nav(string $class): NavMeta |
| 47 | { |
| 48 | $schema = $this->of($class); |
| 49 | |
| 50 | return new NavMeta( |
| 51 | label: $schema->label, |
| 52 | icon: $schema->icon, |
| 53 | badge: $schema->badge, |
| 54 | permission: $schema->permission, |
| 55 | hidden: $schema->hidden, |
| 56 | order: $schema->order, |
| 57 | ); |
| 58 | } |
| 59 | } |