1 | <?php |
||
37 | abstract class AbstractLoader implements LoaderInterface |
||
38 | { |
||
39 | use ColumnsTrait; |
||
40 | |||
41 | /** |
||
42 | * Loading methods for data loaders. |
||
43 | */ |
||
44 | const INLOAD = 1; |
||
45 | const POSTLOAD = 2; |
||
46 | const JOIN = 3; |
||
47 | const LEFT_JOIN = 4; |
||
48 | |||
49 | /** |
||
50 | * Nested loaders. |
||
51 | * |
||
52 | * @var LoaderInterface[] |
||
53 | */ |
||
54 | protected $loaders = []; |
||
55 | |||
56 | /** |
||
57 | * Set of loaders with ability to JOIN it's data into parent SelectQuery. |
||
58 | * |
||
59 | * @var AbstractLoader[] |
||
60 | */ |
||
61 | protected $joiners = []; |
||
62 | |||
63 | /** |
||
64 | * @var string |
||
65 | */ |
||
66 | protected $class; |
||
67 | |||
68 | /** |
||
69 | * @invisible |
||
70 | * @var ORMInterface |
||
71 | */ |
||
72 | protected $orm; |
||
73 | |||
74 | /** |
||
75 | * Parent loader if any. |
||
76 | * |
||
77 | * @invisible |
||
78 | * @var AbstractLoader |
||
79 | */ |
||
80 | protected $parent; |
||
81 | |||
82 | /** |
||
83 | * Loader options, can be altered on RecordSelector level. |
||
84 | * |
||
85 | * @var array |
||
86 | */ |
||
87 | protected $options = []; |
||
88 | |||
89 | /** |
||
90 | * Relation schema. |
||
91 | * |
||
92 | * @var array |
||
93 | */ |
||
94 | protected $schema = []; |
||
95 | |||
96 | /** |
||
97 | * @param string $class |
||
98 | * @param array $schema Relation schema. |
||
99 | * @param ORMInterface $orm |
||
100 | */ |
||
101 | public function __construct(string $class, array $schema, ORMInterface $orm) |
||
107 | |||
108 | /** |
||
109 | * {@inheritdoc} |
||
110 | */ |
||
111 | public function withContext(LoaderInterface $parent, array $options = []): LoaderInterface |
||
139 | |||
140 | /** |
||
141 | * Pre-load data on inner relation or relation chain. Method automatically called by Selector, |
||
142 | * see load() method. |
||
143 | * |
||
144 | * Method support chain initiation via dot notation. Method will return already exists loader if |
||
145 | * such presented. |
||
146 | * |
||
147 | * @see RecordSelector::load() |
||
148 | * |
||
149 | * @param string $relation Relation name, or chain of relations separated by. |
||
150 | * @param array $options Loader options (to be applied to last chain element only). |
||
151 | * @param bool $join When set to true loaders will be forced into JOIN mode. |
||
152 | * |
||
153 | * @return LoaderInterface Must return loader for a requested relation. |
||
154 | * |
||
155 | * @throws LoaderException |
||
156 | */ |
||
157 | final public function loadRelation( |
||
197 | |||
198 | /** |
||
199 | * {@inheritdoc} |
||
200 | */ |
||
201 | final public function createNode(): AbstractNode |
||
212 | |||
213 | /** |
||
214 | * @param AbstractNode $node |
||
215 | */ |
||
216 | public function loadData(AbstractNode $node) |
||
223 | |||
224 | /** |
||
225 | * Ensure state of every nested loader. |
||
226 | */ |
||
227 | final public function __clone() |
||
239 | |||
240 | /** |
||
241 | * Destruct loader. |
||
242 | */ |
||
243 | final public function __destruct() |
||
248 | |||
249 | /** |
||
250 | * @param SelectQuery $query |
||
251 | * |
||
252 | * @return SelectQuery |
||
253 | */ |
||
254 | protected function configureQuery(SelectQuery $query): SelectQuery |
||
268 | |||
269 | /** |
||
270 | * Get database name associated with relation |
||
271 | * |
||
272 | * @return string |
||
273 | */ |
||
274 | protected function getDatabase(): string |
||
278 | |||
279 | /** |
||
280 | * Get table name associated with relation |
||
281 | * |
||
282 | * @return string |
||
283 | */ |
||
284 | protected function getTable(): string |
||
288 | |||
289 | /** |
||
290 | * @return AbstractNode |
||
291 | */ |
||
292 | abstract protected function initNode(): AbstractNode; |
||
293 | |||
294 | /** |
||
295 | * Joined table alias. |
||
296 | * |
||
297 | * @return string |
||
298 | */ |
||
299 | abstract protected function getAlias(): string; |
||
300 | |||
301 | /** |
||
302 | * list of columns to be loaded. |
||
303 | * |
||
304 | * @return array |
||
305 | */ |
||
306 | abstract protected function getColumns(): array; |
||
307 | |||
308 | /** |
||
309 | * Check if given relation is actually chain of relations. |
||
310 | * |
||
311 | * @param string $relation |
||
312 | * |
||
313 | * @return bool |
||
314 | */ |
||
315 | private function isChain(string $relation): bool |
||
319 | |||
320 | /** |
||
321 | * @see loadRelation() |
||
322 | * @see joinRelation() |
||
323 | * |
||
324 | * @param string $chain |
||
325 | * @param array $options Final loader options. |
||
326 | * @param bool $join See loadRelation(). |
||
327 | * |
||
328 | * @return LoaderInterface |
||
329 | * |
||
330 | * @throws LoaderException When one of chain elements is not actually chainable (let's say ODM |
||
331 | * loader). |
||
332 | */ |
||
333 | private function loadChain(string $chain, array $options, bool $join): LoaderInterface |
||
358 | } |
This check looks for access to methods that are not accessible from the current context.
If you need to make a method accessible to another context you can raise its visibility level in the defining class.