Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
| FieldDisplayBuildContext | |
100.00% |
8 / 8 |
|
100.00% |
6 / 6 |
6 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getVisitedNodes | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getResource | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getApieContext | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| createComponentFor | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| createChildContext | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace Apie\HtmlBuilders; |
| 3 | |
| 4 | use Apie\Core\Context\ApieContext; |
| 5 | use Apie\HtmlBuilders\Interfaces\ComponentInterface; |
| 6 | |
| 7 | final class FieldDisplayBuildContext |
| 8 | { |
| 9 | /** @var callable(mixed, FieldDisplayBuildContext): ComponentInterface */ |
| 10 | private $createDisplayComponentFor; |
| 11 | |
| 12 | /** @var array<int, string> */ |
| 13 | private array $visitedNodes = []; |
| 14 | |
| 15 | /** |
| 16 | * @param callable(mixed, FieldDisplayBuildContext): ComponentInterface $createDisplayComponentFor |
| 17 | */ |
| 18 | public function __construct( |
| 19 | callable $createDisplayComponentFor, |
| 20 | private ApieContext $context, |
| 21 | private mixed $resource |
| 22 | ) { |
| 23 | $this->createDisplayComponentFor = $createDisplayComponentFor; |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * @return array<int, string> |
| 28 | */ |
| 29 | public function getVisitedNodes(): array |
| 30 | { |
| 31 | return $this->visitedNodes; |
| 32 | } |
| 33 | |
| 34 | public function getResource(): mixed |
| 35 | { |
| 36 | return $this->resource; |
| 37 | } |
| 38 | |
| 39 | public function getApieContext(): ApieContext |
| 40 | { |
| 41 | return $this->context; |
| 42 | } |
| 43 | |
| 44 | public function createComponentFor(mixed $object): ComponentInterface |
| 45 | { |
| 46 | return ($this->createDisplayComponentFor)($object, $this); |
| 47 | } |
| 48 | |
| 49 | public function createChildContext(string $propertyName): self |
| 50 | { |
| 51 | $result = clone $this; |
| 52 | $result->visitedNodes[] = $propertyName; |
| 53 | |
| 54 | return $result; |
| 55 | } |
| 56 | } |