|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Monsieur Biz' Rich Editor plugin for Sylius. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Monsieur Biz <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace MonsieurBiz\SyliusRichEditorPlugin\UiElement; |
|
15
|
|
|
|
|
16
|
|
|
use MonsieurBiz\SyliusRichEditorPlugin\Exception\UiElementNotFoundException; |
|
17
|
|
|
use Webmozart\Assert\Assert; |
|
18
|
|
|
|
|
19
|
|
|
final class Registry implements RegistryInterface |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var UiElementInterface[] |
|
23
|
|
|
*/ |
|
24
|
|
|
private array $uiElements = []; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* {@inheritdoc} |
|
28
|
|
|
*/ |
|
29
|
|
|
public function addUiElement(UiElementInterface $uiElement): void |
|
30
|
|
|
{ |
|
31
|
|
|
Assert::keyNotExists($this->uiElements, $uiElement->getCode(), 'UiElement with code "%s" is already registered.'); |
|
32
|
|
|
|
|
33
|
|
|
$this->uiElements[$uiElement->getCode()] = $uiElement; |
|
34
|
|
|
if (null !== $uiElement->getAlias()) { |
|
35
|
|
|
$this->uiElements[$uiElement->getAlias()] = clone $uiElement; |
|
36
|
|
|
$uiElement->ignore(); |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* {@inheritdoc} |
|
42
|
|
|
*/ |
|
43
|
|
|
public function hasUiElement(string $code): bool |
|
44
|
|
|
{ |
|
45
|
|
|
return \array_key_exists($code, $this->uiElements); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* {@inheritdoc} |
|
50
|
|
|
*/ |
|
51
|
|
|
public function getUiElement(string $code): UiElementInterface |
|
52
|
|
|
{ |
|
53
|
|
|
if (!$this->hasUiElement($code)) { |
|
54
|
|
|
throw new UiElementNotFoundException($code); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
return $this->uiElements[$code]; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* {@inheritdoc} |
|
62
|
|
|
*/ |
|
63
|
|
|
public function getUiElements(): array |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->uiElements; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* {@inheritdoc} |
|
70
|
|
|
*/ |
|
71
|
|
|
public function jsonSerialize() |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->uiElements; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|