@@ -93,19 +93,19 @@ discard block |
||
93 | 93 | if (\Safe\preg_match('/[A-Z]/', $key)) { |
94 | 94 | $parts = \Safe\preg_split('/(?=[A-Z])/', $key, -1, PREG_SPLIT_NO_EMPTY); |
95 | 95 | if (strtolower($parts[0]) === 'own') { |
96 | - $this->__meta['foreign_models']['otm'] = $this->createCollection($this->__meta['foreign_models']['otm'],$val); |
|
96 | + $this->__meta['foreign_models']['otm'] = $this->createCollection($this->__meta['foreign_models']['otm'], $val); |
|
97 | 97 | $this->__properties['all'][$key] = $val; |
98 | 98 | return; |
99 | 99 | } |
100 | 100 | if (strtolower($parts[0]) === 'shared') { |
101 | - $this->__meta['foreign_models']['mtm'] = $this->createCollection($this->__meta['foreign_models']['mtm'],$val); |
|
101 | + $this->__meta['foreign_models']['mtm'] = $this->createCollection($this->__meta['foreign_models']['mtm'], $val); |
|
102 | 102 | $this->__properties['all'][$key] = $val; |
103 | 103 | return; |
104 | 104 | } |
105 | 105 | } |
106 | 106 | if ($val instanceof Model) { |
107 | - if (isset($this->__properties['all'][$key . '_id'])) { |
|
108 | - unset($this->__properties['all'][$key . '_id']); |
|
107 | + if (isset($this->__properties['all'][$key.'_id'])) { |
|
108 | + unset($this->__properties['all'][$key.'_id']); |
|
109 | 109 | } |
110 | 110 | $this->__meta['foreign_models']['oto'] = $this->createCollection($this->__meta['foreign_models']['oto'], Collection::fromIterable([$val])); |
111 | 111 | $this->__properties['all'][$key] = $val; |
@@ -152,30 +152,30 @@ discard block |
||
152 | 152 | $parts = \Safe\preg_split('/(?=[A-Z])/', $key, -1, PREG_SPLIT_NO_EMPTY); |
153 | 153 | if (strtolower($parts[0]) === 'own') { |
154 | 154 | if (strtolower($parts[2]) === 'list') { |
155 | - $result = $this->connection->getRecordManager()->find(strtolower($parts[1]))->where($this->getName() . '_id = "' . $this->__meta['id'] . '"')->get(); |
|
155 | + $result = $this->connection->getRecordManager()->find(strtolower($parts[1]))->where($this->getName().'_id = "'.$this->__meta['id'].'"')->get(); |
|
156 | 156 | $this->set($key, $result); |
157 | 157 | return $result; |
158 | 158 | } |
159 | 159 | } |
160 | 160 | if (strtolower($parts[0]) === 'shared') { |
161 | 161 | if (strtolower($parts[2]) === 'list') { |
162 | - $rel_table = $this->connection->getTableManager()->tableExists($this->table . '_' . strtolower($parts[1])) ? $this->table . '_' . strtolower($parts[1]) : strtolower($parts[1]) . '_' . $this->table; |
|
163 | - $relations = $this->connection->getRecordManager()->find($rel_table)->where($this->getName() . '_id = "' . $this->__meta['id'] . '"')->get(); |
|
162 | + $rel_table = $this->connection->getTableManager()->tableExists($this->table.'_'.strtolower($parts[1])) ? $this->table.'_'.strtolower($parts[1]) : strtolower($parts[1]).'_'.$this->table; |
|
163 | + $relations = $this->connection->getRecordManager()->find($rel_table)->where($this->getName().'_id = "'.$this->__meta['id'].'"')->get(); |
|
164 | 164 | $rel_ids = ''; |
165 | 165 | foreach ($relations as $relation) { |
166 | - $key = strtolower($parts[1]) . '_id'; |
|
167 | - $rel_ids .= "'" . $relation->$key . "',"; |
|
166 | + $key = strtolower($parts[1]).'_id'; |
|
167 | + $rel_ids .= "'".$relation->$key."',"; |
|
168 | 168 | } |
169 | 169 | $rel_ids = substr($rel_ids, 0, -1); |
170 | - $result = $this->connection->getRecordManager()->find(strtolower($parts[1]))->where('id IN (' . $rel_ids . ')')->get(); |
|
170 | + $result = $this->connection->getRecordManager()->find(strtolower($parts[1]))->where('id IN ('.$rel_ids.')')->get(); |
|
171 | 171 | $this->set($key, $result); |
172 | 172 | return $result; |
173 | 173 | } |
174 | 174 | } |
175 | 175 | } |
176 | 176 | |
177 | - if (array_key_exists($key . '_id', $this->__properties['self'])) { |
|
178 | - $result = $this->connection->getRecordManager()->getById($key, $this->__properties['self'][$key . '_id']); |
|
177 | + if (array_key_exists($key.'_id', $this->__properties['self'])) { |
|
178 | + $result = $this->connection->getRecordManager()->getById($key, $this->__properties['self'][$key.'_id']); |
|
179 | 179 | $this->set($key, $result); |
180 | 180 | return $result; |
181 | 181 | } |
@@ -229,9 +229,9 @@ discard block |
||
229 | 229 | * @throws \Scrawler\Arca\Exception\InvalidModelException |
230 | 230 | * @return Collection |
231 | 231 | */ |
232 | - private function createCollection(?Collection $collection, array|Collection $models): Collection |
|
232 | + private function createCollection(?Collection $collection, array | Collection $models): Collection |
|
233 | 233 | { |
234 | - if(is_null($collection)){ |
|
234 | + if (is_null($collection)) { |
|
235 | 235 | $collection = Collection::fromIterable([]); |
236 | 236 | } |
237 | 237 | |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | */ |
319 | 319 | public function save(): mixed |
320 | 320 | { |
321 | - Event::dispatch('__arca.model.save.' . $this->connection->getConnectionId(), [$this]); |
|
321 | + Event::dispatch('__arca.model.save.'.$this->connection->getConnectionId(), [$this]); |
|
322 | 322 | |
323 | 323 | return $this->getId(); |
324 | 324 | } |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | */ |
344 | 344 | public function delete(): void |
345 | 345 | { |
346 | - Event::dispatch('__arca.model.delete.' . $this->connection->getConnectionId(), [$this]); |
|
346 | + Event::dispatch('__arca.model.delete.'.$this->connection->getConnectionId(), [$this]); |
|
347 | 347 | } |
348 | 348 | |
349 | 349 | /** |
@@ -8,7 +8,7 @@ |
||
8 | 8 | * @template TKey |
9 | 9 | * @template T |
10 | 10 | */ |
11 | -interface CollectionInterface extends IteratorAggregate,\Countable |
|
11 | +interface CollectionInterface extends IteratorAggregate, \Countable |
|
12 | 12 | { |
13 | 13 | /** |
14 | 14 | * @return string |