Total Complexity | 5 |
Total Lines | 43 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | final class UiElementRegistry implements UiElementRegistryInterface |
||
10 | { |
||
11 | /** |
||
12 | * @var UiElementInterface[] |
||
13 | */ |
||
14 | private $uiElements = []; |
||
15 | |||
16 | /** |
||
17 | * @inheritDoc |
||
18 | */ |
||
19 | public function addUiElement(UiElementInterface $uiElement): void |
||
20 | { |
||
21 | Assert::keyNotExists($this->uiElements, $uiElement->getType(), 'UiElement with type "%s" is already registered.'); |
||
22 | |||
23 | $this->uiElements[$uiElement->getType()] = $uiElement; |
||
24 | } |
||
25 | |||
26 | /** |
||
27 | * @inheritDoc |
||
28 | */ |
||
29 | public function hasUiElement(string $type): bool |
||
30 | { |
||
31 | return array_key_exists($type, $this->uiElements); |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * @inheritDoc |
||
36 | */ |
||
37 | public function getUiElement(string $type): UiElementInterface |
||
38 | { |
||
39 | if (!$this->hasUiElement($type)) { |
||
40 | throw new UiElementNotFoundException($type); |
||
41 | } |
||
42 | |||
43 | return $this->uiElements[$type]; |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @inheritDoc |
||
48 | */ |
||
49 | public function getUiElements(): array |
||
52 | } |
||
53 | } |
||
54 |