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 | 91 | 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 | 91 | public function registerStyle(Style $style) |
|
49 | |||
50 | /** |
||
51 | * Returns whether the serialized style has already been registered. |
||
52 | * |
||
53 | * @param string $serializedStyle The serialized style |
||
54 | * @return bool |
||
55 | */ |
||
56 | 91 | protected function hasSerializedStyleAlreadyBeenRegistered(string $serializedStyle) |
|
61 | 91 | ||
62 | /** |
||
63 | * Returns the registered style associated to the given serialization. |
||
64 | * |
||
65 | * @param string $serializedStyle The serialized style from which the actual style should be fetched from |
||
66 | * @return Style |
||
67 | */ |
||
68 | protected function getStyleFromSerializedStyle($serializedStyle) |
||
74 | 91 | ||
75 | /** |
||
76 | * @return Style[] List of registered styles |
||
77 | */ |
||
78 | public function getRegisteredStyles() |
||
82 | 73 | ||
83 | /** |
||
84 | * @param int $styleId |
||
85 | * @return Style |
||
86 | */ |
||
87 | public function getStyleFromStyleId($styleId) |
||
91 | 7 | ||
92 | /** |
||
93 | * Serializes the style for future comparison with other styles. |
||
94 | * The ID is excluded from the comparison, as we only care about |
||
95 | * actual style properties. |
||
96 | * |
||
97 | * @param Style $style |
||
98 | * @return string The serialized style |
||
99 | */ |
||
100 | public function serialize(Style $style) |
||
112 | } |
||
113 |