1 | <?php |
||
13 | class StyleRegistry |
||
14 | { |
||
15 | /** @var array [SERIALIZED_STYLE] => [STYLE_ID] mapping table, keeping track of the registered styles */ |
||
16 | protected $serializedStyleToStyleIdMappingTable = []; |
||
17 | |||
18 | /** @var array [STYLE_ID] => [STYLE] mapping table, keeping track of the registered styles */ |
||
19 | protected $styleIdToStyleMappingTable = []; |
||
20 | |||
21 | /** |
||
22 | * @param Style $defaultStyle |
||
23 | */ |
||
24 | 99 | public function __construct(Style $defaultStyle) |
|
29 | |||
30 | /** |
||
31 | * Registers the given style as a used style. |
||
32 | * Duplicate styles won't be registered more than once. |
||
33 | * |
||
34 | * @param Style $style The style to be registered |
||
35 | * @return Style The registered style, updated with an internal ID. |
||
36 | */ |
||
37 | 99 | public function registerStyle(Style $style) |
|
51 | |||
52 | /** |
||
53 | * Returns whether the given style has already been registered. |
||
54 | * |
||
55 | * @param Style $style |
||
56 | * @return bool |
||
57 | */ |
||
58 | 99 | protected function hasStyleAlreadyBeenRegistered(Style $style) |
|
65 | |||
66 | /** |
||
67 | * Returns the registered style associated to the given serialization. |
||
68 | * |
||
69 | * @param string $serializedStyle The serialized style from which the actual style should be fetched from |
||
70 | * @return Style |
||
71 | */ |
||
72 | 99 | protected function getStyleFromSerializedStyle($serializedStyle) |
|
77 | |||
78 | /** |
||
79 | * @return Style[] List of registered styles |
||
80 | */ |
||
81 | 70 | public function getRegisteredStyles() |
|
85 | |||
86 | /** |
||
87 | * @param int $styleId |
||
88 | * @return Style |
||
89 | */ |
||
90 | 6 | public function getStyleFromStyleId($styleId) |
|
94 | |||
95 | /** |
||
96 | * Serializes the style for future comparison with other styles. |
||
97 | * The ID is excluded from the comparison, as we only care about |
||
98 | * actual style properties. |
||
99 | * |
||
100 | * @param Style $style |
||
101 | * @return string The serialized style |
||
102 | */ |
||
103 | 99 | public function serialize(Style $style) |
|
115 | } |
||
116 |