1 | <?php |
||
21 | abstract class RelationLoader extends AbstractLoader |
||
22 | { |
||
23 | use ColumnsTrait; |
||
24 | |||
25 | /** |
||
26 | * Used to create unique set of aliases for loaded relations. |
||
27 | * |
||
28 | * @var int |
||
29 | */ |
||
30 | private static $countLevels = 0; |
||
31 | |||
32 | /** |
||
33 | * Name of relation loader associated with. |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $relation; |
||
38 | |||
39 | /** |
||
40 | * Default set of relation options. Child implementation might defined their of default options. |
||
41 | * |
||
42 | * @var array |
||
43 | */ |
||
44 | protected $options = [ |
||
45 | //Load method, see QueryLoader constants |
||
46 | 'method' => null, |
||
47 | |||
48 | //When true all loader columns will be minified (only for loading) |
||
49 | 'minify' => true, |
||
50 | |||
51 | //Table alias |
||
52 | 'alias' => null, |
||
53 | |||
54 | //Alias used by another relation |
||
55 | 'using' => null, |
||
56 | |||
57 | //Where conditions (if any) |
||
58 | 'where' => null, |
||
59 | ]; |
||
60 | |||
61 | /** |
||
62 | * @param string $class |
||
63 | * @param string $relation |
||
64 | * @param array $schema |
||
65 | * @param ORMInterface $orm |
||
66 | */ |
||
67 | public function __construct(string $class, string $relation, array $schema, ORMInterface $orm) |
||
75 | |||
76 | /** |
||
77 | * {@inheritdoc} |
||
78 | */ |
||
79 | public function withContext(LoaderInterface $parent, array $options = []): LoaderInterface |
||
103 | |||
104 | /** |
||
105 | * Indicated that loaded must generate JOIN statement. |
||
106 | * |
||
107 | * @return bool |
||
108 | */ |
||
109 | public function isJoined(): bool |
||
117 | |||
118 | /** |
||
119 | * Indication that loader want to load data. |
||
120 | * |
||
121 | * @return bool |
||
122 | */ |
||
123 | public function isLoaded(): bool |
||
127 | |||
128 | /** |
||
129 | * {@inheritdoc} |
||
130 | */ |
||
131 | public function loadData(AbstractNode $node) |
||
159 | |||
160 | /** |
||
161 | * Configure query with conditions, joins and columns. |
||
162 | * |
||
163 | * @param SelectQuery $query |
||
164 | * @param bool $loadColumns |
||
165 | * @param array $outerKeys Set of OUTER_KEY values collected by parent loader. |
||
166 | * |
||
167 | * @return SelectQuery |
||
168 | */ |
||
169 | protected function configureQuery(SelectQuery $query, bool $loadColumns = true, array $outerKeys = []): SelectQuery |
||
183 | |||
184 | /** |
||
185 | * Relation table alias. |
||
186 | * |
||
187 | * @return string |
||
188 | */ |
||
189 | protected function getAlias(): string |
||
202 | |||
203 | /** |
||
204 | * Relation columns. |
||
205 | * |
||
206 | * @return array |
||
207 | */ |
||
208 | protected function getColumns(): array |
||
212 | |||
213 | /** |
||
214 | * Get load method. |
||
215 | * |
||
216 | * @return int |
||
217 | */ |
||
218 | protected function getMethod(): int |
||
222 | |||
223 | /** |
||
224 | * Generate sql identifier using loader alias and value from relation definition. Key name to be |
||
225 | * fetched from schema. |
||
226 | * |
||
227 | * Example: |
||
228 | * $this->getKey(Record::OUTER_KEY); |
||
229 | * |
||
230 | * @param string $key |
||
231 | * |
||
232 | * @return string|null |
||
233 | */ |
||
234 | protected function localKey($key) |
||
242 | |||
243 | /** |
||
244 | * Get parent identifier based on relation configuration key. |
||
245 | * |
||
246 | * @param $key |
||
247 | * |
||
248 | * @return string |
||
249 | */ |
||
250 | protected function parentKey($key): string |
||
254 | |||
255 | /** |
||
256 | * Ensure table alias. |
||
257 | * |
||
258 | * @param AbstractLoader $parent |
||
259 | */ |
||
260 | protected function ensureAlias(AbstractLoader $parent) |
||
273 | |||
274 | /** |
||
275 | * Create relation specific select query. |
||
276 | * |
||
277 | * @return SelectQuery |
||
278 | */ |
||
279 | protected function createQuery(): SelectQuery |
||
285 | } |