1 | <?php |
||
38 | abstract class AbstractLoader implements LoaderInterface |
||
39 | { |
||
40 | use ColumnsTrait; |
||
41 | |||
42 | /** |
||
43 | * Loading methods for data loaders. |
||
44 | */ |
||
45 | const INLOAD = 1; |
||
46 | const POSTLOAD = 2; |
||
47 | const JOIN = 3; |
||
48 | const LEFT_JOIN = 4; |
||
49 | |||
50 | /** |
||
51 | * Nested loaders. |
||
52 | * |
||
53 | * @var LoaderInterface[] |
||
54 | */ |
||
55 | protected $loaders = []; |
||
56 | |||
57 | /** |
||
58 | * Set of loaders with ability to JOIN it's data into parent SelectQuery. |
||
59 | * |
||
60 | * @var AbstractLoader[] |
||
61 | */ |
||
62 | protected $joiners = []; |
||
63 | |||
64 | /** |
||
65 | * @var string |
||
66 | */ |
||
67 | protected $class; |
||
68 | |||
69 | /** |
||
70 | * @invisible |
||
71 | * @var ORMInterface |
||
72 | */ |
||
73 | protected $orm; |
||
74 | |||
75 | /** |
||
76 | * Parent loader if any. |
||
77 | * |
||
78 | * @invisible |
||
79 | * @var AbstractLoader |
||
80 | */ |
||
81 | protected $parent; |
||
82 | |||
83 | /** |
||
84 | * Loader options, can be altered on RecordSelector level. |
||
85 | * |
||
86 | * @var array |
||
87 | */ |
||
88 | protected $options = []; |
||
89 | |||
90 | /** |
||
91 | * Relation schema. |
||
92 | * |
||
93 | * @var array |
||
94 | */ |
||
95 | protected $schema = []; |
||
96 | |||
97 | /** |
||
98 | * @param string $class |
||
99 | * @param array $schema Relation schema. |
||
100 | * @param ORMInterface $orm |
||
101 | */ |
||
102 | public function __construct(string $class, array $schema, ORMInterface $orm) |
||
108 | |||
109 | /** |
||
110 | * @return string |
||
111 | */ |
||
112 | public function getClass(): string |
||
116 | |||
117 | /** |
||
118 | * {@inheritdoc} |
||
119 | */ |
||
120 | public function withContext(LoaderInterface $parent, array $options = []): LoaderInterface |
||
148 | |||
149 | /** |
||
150 | * Pre-load data on inner relation or relation chain. Method automatically called by Selector, |
||
151 | * see load() method. |
||
152 | * |
||
153 | * Method support chain initiation via dot notation. Method will return already exists loader if |
||
154 | * such presented. |
||
155 | * |
||
156 | * @see RecordSelector::load() |
||
157 | * |
||
158 | * @param string $relation Relation name, or chain of relations separated by. |
||
159 | * @param array $options Loader options (to be applied to last chain element only). |
||
160 | * @param bool $join When set to true loaders will be forced into JOIN mode. |
||
161 | * |
||
162 | * @return LoaderInterface Must return loader for a requested relation. |
||
163 | * |
||
164 | * @throws LoaderException |
||
165 | */ |
||
166 | final public function loadRelation( |
||
206 | |||
207 | /** |
||
208 | * {@inheritdoc} |
||
209 | */ |
||
210 | final public function createNode(): AbstractNode |
||
221 | |||
222 | /** |
||
223 | * @param AbstractNode $node |
||
224 | */ |
||
225 | public function loadData(AbstractNode $node) |
||
232 | |||
233 | /** |
||
234 | * Ensure state of every nested loader. |
||
235 | */ |
||
236 | public function __clone() |
||
248 | |||
249 | /** |
||
250 | * Destruct loader. |
||
251 | */ |
||
252 | final public function __destruct() |
||
257 | |||
258 | /** |
||
259 | * @param SelectQuery $query |
||
260 | * |
||
261 | * @return SelectQuery |
||
262 | */ |
||
263 | protected function configureQuery(SelectQuery $query): SelectQuery |
||
277 | |||
278 | /** |
||
279 | * Get database name associated with relation |
||
280 | * |
||
281 | * @return string |
||
282 | */ |
||
283 | protected function getDatabase(): string |
||
287 | |||
288 | /** |
||
289 | * Get table name associated with relation |
||
290 | * |
||
291 | * @return string |
||
292 | */ |
||
293 | protected function getTable(): string |
||
297 | |||
298 | /** |
||
299 | * @return AbstractNode |
||
300 | */ |
||
301 | abstract protected function initNode(): AbstractNode; |
||
302 | |||
303 | /** |
||
304 | * Joined table alias. |
||
305 | * |
||
306 | * @return string |
||
307 | */ |
||
308 | abstract protected function getAlias(): string; |
||
309 | |||
310 | /** |
||
311 | * list of columns to be loaded. |
||
312 | * |
||
313 | * @return array |
||
314 | */ |
||
315 | abstract protected function getColumns(): array; |
||
316 | |||
317 | /** |
||
318 | * Check if given relation is actually chain of relations. |
||
319 | * |
||
320 | * @param string $relation |
||
321 | * |
||
322 | * @return bool |
||
323 | */ |
||
324 | private function isChain(string $relation): bool |
||
328 | |||
329 | /** |
||
330 | * @see loadRelation() |
||
331 | * @see joinRelation() |
||
332 | * |
||
333 | * @param string $chain |
||
334 | * @param array $options Final loader options. |
||
335 | * @param bool $join See loadRelation(). |
||
336 | * |
||
337 | * @return LoaderInterface |
||
338 | * |
||
339 | * @throws LoaderException When one of chain elements is not actually chainable (let's say ODM |
||
340 | * loader). |
||
341 | */ |
||
342 | private function loadChain(string $chain, array $options, bool $join): LoaderInterface |
||
367 | } |