Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
8 / 8 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
DataLayerByClass | |
100.00% |
8 / 8 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
offsetGet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setDefaultDataLayer | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
pickDataLayerFor | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | namespace Apie\Core\Datalayers\Grouped; |
3 | |
4 | use Apie\Core\Datalayers\ApieDatalayer; |
5 | use Apie\Core\Entities\EntityInterface; |
6 | use Apie\Core\Exceptions\ObjectIsImmutable; |
7 | use Apie\Core\Lists\ItemHashmap; |
8 | use ReflectionClass; |
9 | |
10 | final class DataLayerByClass extends ItemHashmap |
11 | { |
12 | private ApieDataLayer $defaultDataLayer; |
13 | |
14 | public function offsetGet(mixed $offset): ApieDatalayer |
15 | { |
16 | return parent::offsetGet($offset); |
17 | } |
18 | |
19 | public function setDefaultDataLayer(ApieDatalayer $defaultDataLayer): self |
20 | { |
21 | if (isset($this->defaultDataLayer)) { |
22 | throw new ObjectIsImmutable($this); |
23 | } |
24 | $this->mutable = false; |
25 | $this->defaultDataLayer = $defaultDataLayer; |
26 | return $this; |
27 | } |
28 | |
29 | /** |
30 | * @param ReflectionClass<EntityInterface> $class |
31 | */ |
32 | public function pickDataLayerFor(ReflectionClass $class): ApieDatalayer |
33 | { |
34 | $className = $class->name; |
35 | return $this[$className] ?? $this->defaultDataLayer; |
36 | } |
37 | } |