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