1 | <?php |
||
20 | class ManyToManyRelation extends AbstractRelation implements \IteratorAggregate |
||
21 | { |
||
22 | use MatchTrait; |
||
23 | |||
24 | /** |
||
25 | * @var bool |
||
26 | */ |
||
27 | private $autoload = true; |
||
28 | |||
29 | /** |
||
30 | * @var \SplObjectStorage |
||
31 | */ |
||
32 | private $pivotData; |
||
33 | |||
34 | /** |
||
35 | * @var RecordInterface[] |
||
36 | */ |
||
37 | private $linked = []; |
||
38 | |||
39 | /** |
||
40 | * @var RecordInterface[] |
||
41 | */ |
||
42 | private $unlinked = []; |
||
43 | |||
44 | /** |
||
45 | * {@inheritdoc} |
||
46 | */ |
||
47 | public function withContext( |
||
60 | |||
61 | /** |
||
62 | * Partial selections will not be autoloaded. |
||
63 | * |
||
64 | * Example: |
||
65 | * |
||
66 | * $post = $this->findPost(); //no comments |
||
67 | * $post->tags->partial(true); |
||
68 | * assert($post->tags->count() == 0); //never loaded |
||
69 | * |
||
70 | * $post->comments->add($comment); |
||
71 | * |
||
72 | * @param bool $partial |
||
73 | * |
||
74 | * @return ManyToManyRelation |
||
75 | */ |
||
76 | public function partial(bool $partial = true): self |
||
82 | |||
83 | /** |
||
84 | * @return bool |
||
85 | */ |
||
86 | public function isPartial(): bool |
||
90 | |||
91 | /** |
||
92 | * {@inheritdoc} |
||
93 | */ |
||
94 | public function setRelated($value) |
||
107 | |||
108 | /** |
||
109 | * @return $this |
||
110 | */ |
||
111 | public function getRelated() |
||
115 | |||
116 | /** |
||
117 | * Iterate over linked instances, will force pre-loading unless partial. |
||
118 | * |
||
119 | * @return \ArrayIterator |
||
120 | */ |
||
121 | public function getIterator() |
||
125 | |||
126 | /** |
||
127 | * Get all unlinked records. |
||
128 | * |
||
129 | * @return \ArrayIterator |
||
130 | */ |
||
131 | public function getUnlinked() |
||
135 | |||
136 | /** |
||
137 | * todo: write docs |
||
138 | * |
||
139 | * @param array $records |
||
140 | * @param array $pivotData |
||
141 | * @param bool $force |
||
142 | */ |
||
143 | public function sync(array $records, array $pivotData = [], bool $force = true) |
||
150 | |||
151 | public function setPivot($record, array $pivotData) |
||
155 | |||
156 | public function getPivot($record) |
||
160 | |||
161 | public function link($record, array $pivotData = []) |
||
168 | |||
169 | public function unlink($record) |
||
172 | |||
173 | public function has($query) |
||
177 | |||
178 | public function matchOne($query) |
||
181 | |||
182 | public function matchMultiple($query) |
||
186 | |||
187 | public function queueCommands(ContextualCommandInterface $command): CommandInterface |
||
191 | |||
192 | /** |
||
193 | * Load related records from database. |
||
194 | * |
||
195 | * @param bool $autoload |
||
196 | * |
||
197 | * @return self |
||
198 | * |
||
199 | * @throws SelectorException |
||
200 | * @throws QueryException (needs wrapping) |
||
201 | */ |
||
202 | protected function loadData(bool $autoload = true): self |
||
221 | |||
222 | /** |
||
223 | * Init relations and populate pivot map. |
||
224 | * |
||
225 | * @return ManyToManyRelation |
||
226 | */ |
||
227 | private function initInstances(): self |
||
249 | } |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.