Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Services
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 withDefaults
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Cosray\Field;
6
7use Cosray\Block\Registry as Blocks;
8use Cosray\Field\Control\Registry as Controls;
9use Cosray\Field\Schema\Registry;
10use Cosray\Node\Types;
11
12/**
13 * Shared services a field needs during initialization.
14 *
15 * Constructed once in the CMS plugin and container-bound so all
16 * hydration paths use the same registries.
17 */
18final class Services
19{
20    public readonly Blocks $blocks;
21    public readonly Controls $controls;
22
23    public function __construct(
24        public readonly Registry $schemas,
25        public readonly Types $types,
26        ?Blocks $blocks = null,
27        ?Controls $controls = null,
28    ) {
29        $this->blocks = $blocks ?? Blocks::withDefaults();
30        $this->controls = $controls ?? Controls::withDefaults();
31    }
32
33    public static function withDefaults(): self
34    {
35        return new self(Registry::withDefaults(), new Types());
36    }
37}