1 | <?php |
||
11 | class StyleRegistry |
||
12 | { |
||
13 | /** @var array [SERIALIZED_STYLE] => [STYLE_ID] mapping table, keeping track of the registered styles */ |
||
14 | protected $serializedStyleToStyleIdMappingTable = []; |
||
15 | |||
16 | /** @var array [STYLE_ID] => [STYLE] mapping table, keeping track of the registered styles */ |
||
17 | protected $styleIdToStyleMappingTable = []; |
||
18 | |||
19 | /** |
||
20 | * @param Style $defaultStyle |
||
21 | */ |
||
22 | 92 | public function __construct(Style $defaultStyle) |
|
27 | |||
28 | /** |
||
29 | * Registers the given style as a used style. |
||
30 | * Duplicate styles won't be registered more than once. |
||
31 | * |
||
32 | * @param Style $style The style to be registered |
||
33 | * @return Style The registered style, updated with an internal ID. |
||
34 | */ |
||
35 | 92 | public function registerStyle(Style $style) |
|
49 | |||
50 | /** |
||
51 | * Returns whether the given style has already been registered. |
||
52 | * |
||
53 | * @param Style $style |
||
54 | * @return bool |
||
55 | */ |
||
56 | protected function hasStyleAlreadyBeenRegistered(Style $style) |
||
62 | |||
63 | /** |
||
64 | * Returns whether the serialized style has already been registered. |
||
65 | * |
||
66 | * @param string $serializedStyle The serialized style |
||
67 | * @return bool |
||
68 | */ |
||
69 | 92 | protected function hasSerializedStyleAlreadyBeenRegistered(string $serializedStyle) |
|
74 | |||
75 | /** |
||
76 | * Returns the registered style associated to the given serialization. |
||
77 | * |
||
78 | * @param string $serializedStyle The serialized style from which the actual style should be fetched from |
||
79 | * @return Style |
||
80 | */ |
||
81 | 92 | protected function getStyleFromSerializedStyle($serializedStyle) |
|
87 | |||
88 | /** |
||
89 | * @return Style[] List of registered styles |
||
90 | */ |
||
91 | 73 | public function getRegisteredStyles() |
|
95 | |||
96 | /** |
||
97 | * @param int $styleId |
||
98 | * @return Style |
||
99 | */ |
||
100 | 7 | public function getStyleFromStyleId($styleId) |
|
104 | |||
105 | /** |
||
106 | * Serializes the style for future comparison with other styles. |
||
107 | * The ID is excluded from the comparison, as we only care about |
||
108 | * actual style properties. |
||
109 | * |
||
110 | * @param Style $style |
||
111 | * @return string The serialized style |
||
112 | */ |
||
113 | 92 | public function serialize(Style $style) |
|
126 | } |
||
127 |