1 | <?php |
||
20 | class DocumentRegistry |
||
21 | { |
||
22 | /** |
||
23 | * @var array |
||
24 | */ |
||
25 | private $documentMap = []; |
||
26 | |||
27 | /** |
||
28 | * @var array |
||
29 | */ |
||
30 | private $documentNodeMap = []; |
||
31 | |||
32 | /** |
||
33 | * @var array |
||
34 | */ |
||
35 | private $nodeMap = []; |
||
36 | |||
37 | /** |
||
38 | * @var array |
||
39 | */ |
||
40 | private $nodeDocumentMap = []; |
||
41 | |||
42 | /** |
||
43 | * @var array |
||
44 | */ |
||
45 | private $documentLocaleMap = []; |
||
46 | |||
47 | /** |
||
48 | * @var array |
||
49 | */ |
||
50 | private $originalLocaleMap = []; |
||
51 | |||
52 | /** |
||
53 | * @var string |
||
54 | */ |
||
55 | private $defaultLocale; |
||
56 | |||
57 | /** |
||
58 | * @var array |
||
59 | */ |
||
60 | private $hydrationState = []; |
||
61 | |||
62 | /** |
||
63 | * @param $defaultLocale |
||
64 | */ |
||
65 | public function __construct($defaultLocale) |
||
69 | |||
70 | /** |
||
71 | * Register a document. |
||
72 | * |
||
73 | * @param mixed $document |
||
74 | * @param NodeInterface $node |
||
75 | * @param NodeInterface $node |
||
76 | * @param null|string $locale |
||
77 | * |
||
78 | * @throws DocumentManagerException |
||
79 | */ |
||
80 | public function registerDocument($document, NodeInterface $node, $locale = null) |
||
98 | |||
99 | /** |
||
100 | * Update the locale of the given document and store the originally |
||
101 | * requested locale. |
||
102 | * |
||
103 | * The originally requested locale should be reset when a HYDRATE event |
||
104 | * is caused by the user (and not internally when loading dependencies). |
||
105 | * |
||
106 | * @param object $document |
||
107 | * @param string $locale |
||
108 | * @param null|string $originalLocale |
||
109 | */ |
||
110 | public function updateLocale($document, $locale, $originalLocale = null) |
||
116 | |||
117 | /** |
||
118 | * Return true if the document is managed. |
||
119 | * |
||
120 | * @param object $document |
||
121 | * |
||
122 | * @return bool |
||
123 | */ |
||
124 | public function hasDocument($document) |
||
130 | |||
131 | /** |
||
132 | * Return true if the node is managed. |
||
133 | * |
||
134 | * @param NodeInterface $node |
||
135 | * |
||
136 | * @return bool |
||
137 | */ |
||
138 | public function hasNode(NodeInterface $node) |
||
142 | |||
143 | /** |
||
144 | * Clear the registry (detach all documents). |
||
145 | */ |
||
146 | public function clear() |
||
156 | |||
157 | /** |
||
158 | * Remove all references to the given document and its |
||
159 | * associated node. |
||
160 | * |
||
161 | * @param object $document |
||
162 | */ |
||
163 | public function deregisterDocument($document) |
||
179 | |||
180 | /** |
||
181 | * Return the node for the given managed document. |
||
182 | * |
||
183 | * @param object $document |
||
184 | * |
||
185 | * @throws \RuntimeException If the node is not managed |
||
186 | * |
||
187 | * @return NodeInterface |
||
188 | */ |
||
189 | public function getNodeForDocument($document) |
||
196 | |||
197 | /** |
||
198 | * Return the current locale for the given document. |
||
199 | * |
||
200 | * @param object $document |
||
201 | * |
||
202 | * @return string |
||
203 | */ |
||
204 | public function getLocaleForDocument($document) |
||
211 | |||
212 | /** |
||
213 | * Return the original locale for the document. |
||
214 | * |
||
215 | * @param object $document |
||
216 | * |
||
217 | * @return string |
||
218 | */ |
||
219 | public function getOriginalLocaleForDocument($document) |
||
230 | |||
231 | /** |
||
232 | * Return the document for the given managed node. |
||
233 | * |
||
234 | * @param NodeInterface $node |
||
235 | * |
||
236 | * @throws \RuntimeException If the node is not managed |
||
237 | */ |
||
238 | public function getDocumentForNode(NodeInterface $node) |
||
245 | |||
246 | /** |
||
247 | * Return the default locale. |
||
248 | * |
||
249 | * @return string |
||
250 | */ |
||
251 | public function getDefaultLocale() |
||
255 | |||
256 | /** |
||
257 | * @param object $document |
||
258 | */ |
||
259 | private function assertDocumentExists($document) |
||
270 | |||
271 | /** |
||
272 | * @param mixed $identifier |
||
273 | */ |
||
274 | private function assertNodeExists($identifier) |
||
283 | |||
284 | /** |
||
285 | * Get the spl object hash for the given object. |
||
286 | * |
||
287 | * @param object $document |
||
288 | * |
||
289 | * @return string |
||
290 | */ |
||
291 | private function getObjectIdentifier($document) |
||
295 | |||
296 | /** |
||
297 | * Ensure that the document is not already registered and that the node |
||
298 | * has a UUID. |
||
299 | * |
||
300 | * @param object $document |
||
301 | * @param NodeInterface $node |
||
302 | * @param string $oid |
||
303 | * @param string $uuid |
||
304 | * |
||
305 | * @throws DocumentManagerException |
||
306 | */ |
||
307 | private function validateDocumentRegistration($document, NodeInterface $node, $oid, $uuid) |
||
329 | |||
330 | /** |
||
331 | * Register that the document has been hydrated and that it should |
||
332 | * not be hydrated again. |
||
333 | * |
||
334 | * @param object $document |
||
335 | */ |
||
336 | public function markDocumentAsHydrated($document) |
||
341 | |||
342 | /** |
||
343 | * Unmark the document as being hydrated. It will then be |
||
344 | * rehydrated the next time a HYDRATE event is fired for ot. |
||
345 | * |
||
346 | * @param object $document |
||
347 | */ |
||
348 | public function unmarkDocumentAsHydrated($document) |
||
353 | |||
354 | /** |
||
355 | * Return true if the document is a candidate for hydration/re-hydration. |
||
356 | * |
||
357 | * @param object $document |
||
358 | * |
||
359 | * @return bool |
||
360 | */ |
||
361 | public function isHydrated($document) |
||
371 | } |
||
372 |