1 | <?php |
||
17 | class InheritanceHelper |
||
18 | { |
||
19 | /** |
||
20 | * @var DocumentSchema |
||
21 | */ |
||
22 | private $schema; |
||
23 | |||
24 | /** |
||
25 | * All other registered schemas. |
||
26 | * |
||
27 | * @var SchemaInterface[] |
||
28 | */ |
||
29 | private $schemas = []; |
||
30 | |||
31 | /** |
||
32 | * @param DocumentSchema $schema |
||
33 | * @param SchemaInterface[] $schemas |
||
34 | */ |
||
35 | public function __construct(DocumentSchema $schema, array $schemas) |
||
40 | |||
41 | /** |
||
42 | * Compile information required to resolve class instance using given set of fields. Fields |
||
43 | * based definition will analyze unique fields in every child model to create association |
||
44 | * between model class and required set of fields. Only document from same collection will be |
||
45 | * involved in definition creation. Definition built only for child of first order. |
||
46 | * |
||
47 | * @return array|string |
||
48 | * |
||
49 | * @throws DefinitionException |
||
50 | */ |
||
51 | public function makeDefinition() |
||
107 | |||
108 | /** |
||
109 | * Get Document child classes. |
||
110 | * |
||
111 | * Example: |
||
112 | * Class A |
||
113 | * Class B extends A |
||
114 | * Class D extends A |
||
115 | * Class E extends D |
||
116 | * |
||
117 | * Result: B, D, E |
||
118 | * |
||
119 | * @see getPrimary() |
||
120 | * |
||
121 | * @param bool $sameCollection Find only children related to same collection as parent. |
||
122 | * @param bool $directChildren Only child extended directly from current document. |
||
123 | * |
||
124 | * @return DocumentSchema[] |
||
125 | */ |
||
126 | public function findChildren(bool $sameCollection = false, bool $directChildren = false) |
||
159 | |||
160 | /** |
||
161 | * Find primary class needed to represent model and model childs. |
||
162 | * |
||
163 | * @param bool $sameCollection Find only parent related to same collection as model. |
||
164 | * |
||
165 | * @return string |
||
166 | */ |
||
167 | public function findPrimary(bool $sameCollection = true): string |
||
188 | |||
189 | /** |
||
190 | * @return ReflectionEntity |
||
191 | */ |
||
192 | protected function getReflection(): ReflectionEntity |
||
196 | |||
197 | /** |
||
198 | * Check if both document schemas belongs to same collection. Documents without declared |
||
199 | * collection must be counted as documents from same collection. |
||
200 | * |
||
201 | * @param DocumentSchema $document |
||
202 | * |
||
203 | * @return bool |
||
204 | */ |
||
205 | protected function compareCollection(DocumentSchema $document) |
||
213 | |||
214 | /** |
||
215 | * Sort child documents in order or declared fields. |
||
216 | * |
||
217 | * @param DocumentSchema $childA |
||
218 | * @param DocumentSchema $childB |
||
219 | * |
||
220 | * @return int |
||
221 | */ |
||
222 | private function sortChildren(DocumentSchema $childA, DocumentSchema $childB) |
||
226 | } |