@@ -1,7 +1,7 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | namespace Scrawler\Arca\Traits\Model; |
4 | -trait ArrayAccess{ |
|
4 | +trait ArrayAccess { |
|
5 | 5 | public function offsetSet($offset, $value): void { |
6 | 6 | if (is_null($offset)) { |
7 | 7 | throw new \Exception("Offset cannot be null"); |
@@ -5,10 +5,10 @@ |
||
5 | 5 | use Scrawler\Arca\Collection; |
6 | 6 | |
7 | 7 | trait Iterator{ |
8 | - /** |
|
9 | - * Get all properties in array form |
|
10 | - * @return array<mixed> |
|
11 | - */ |
|
8 | + /** |
|
9 | + * Get all properties in array form |
|
10 | + * @return array<mixed> |
|
11 | + */ |
|
12 | 12 | public function toArray(): array |
13 | 13 | { |
14 | 14 | $props = $this->getProperties(); |
@@ -4,7 +4,7 @@ |
||
4 | 4 | use Scrawler\Arca\Model; |
5 | 5 | use Scrawler\Arca\Collection; |
6 | 6 | |
7 | -trait Iterator{ |
|
7 | +trait Iterator { |
|
8 | 8 | /** |
9 | 9 | * Get all properties in array form |
10 | 10 | * @return array<mixed> |
@@ -2,7 +2,7 @@ |
||
2 | 2 | |
3 | 3 | namespace Scrawler\Arca\Traits\Model; |
4 | 4 | |
5 | -trait Serializable{ |
|
5 | +trait Serializable { |
|
6 | 6 | |
7 | 7 | /** |
8 | 8 | * @return array<mixed> |
@@ -4,11 +4,11 @@ discard block |
||
4 | 4 | use Scrawler\Arca\Model; |
5 | 5 | trait Setter{ |
6 | 6 | |
7 | - /** |
|
8 | - * Set all properties of model via array |
|
9 | - * @param array<mixed> $properties |
|
10 | - * @return Model |
|
11 | - */ |
|
7 | + /** |
|
8 | + * Set all properties of model via array |
|
9 | + * @param array<mixed> $properties |
|
10 | + * @return Model |
|
11 | + */ |
|
12 | 12 | public function setProperties(array $properties): Model |
13 | 13 | { |
14 | 14 | foreach ($properties as $key => $value) { |
@@ -17,11 +17,11 @@ discard block |
||
17 | 17 | return $this; |
18 | 18 | } |
19 | 19 | |
20 | - /** |
|
21 | - * Set all properties of model loaded via database |
|
22 | - * @param array<mixed> $properties |
|
23 | - * @return Model |
|
24 | - */ |
|
20 | + /** |
|
21 | + * Set all properties of model loaded via database |
|
22 | + * @param array<mixed> $properties |
|
23 | + * @return Model |
|
24 | + */ |
|
25 | 25 | public function setLoadedProperties(array $properties): Model |
26 | 26 | { |
27 | 27 | $this->__properties['all'] = $properties; |
@@ -33,10 +33,10 @@ discard block |
||
33 | 33 | return $this; |
34 | 34 | } |
35 | 35 | |
36 | - /** |
|
37 | - * call when model is loaded from database |
|
38 | - * @return Model |
|
39 | - */ |
|
36 | + /** |
|
37 | + * call when model is loaded from database |
|
38 | + * @return Model |
|
39 | + */ |
|
40 | 40 | public function setLoaded(): Model |
41 | 41 | { |
42 | 42 | $this->__meta['is_loaded'] = true; |
@@ -2,7 +2,7 @@ |
||
2 | 2 | |
3 | 3 | namespace Scrawler\Arca\Traits\Model; |
4 | 4 | use Scrawler\Arca\Model; |
5 | -trait Setter{ |
|
5 | +trait Setter { |
|
6 | 6 | |
7 | 7 | /** |
8 | 8 | * Set all properties of model via array |
@@ -94,19 +94,19 @@ discard block |
||
94 | 94 | if (\Safe\preg_match('/[A-Z]/', $key)) { |
95 | 95 | $parts = \Safe\preg_split('/(?=[A-Z])/', $key, -1, PREG_SPLIT_NO_EMPTY); |
96 | 96 | if (strtolower($parts[0]) === 'own') { |
97 | - $this->__meta['foreign_models']['otm'] = $this->createCollection($this->__meta['foreign_models']['otm'],$val); |
|
97 | + $this->__meta['foreign_models']['otm'] = $this->createCollection($this->__meta['foreign_models']['otm'], $val); |
|
98 | 98 | $this->__properties['all'][$key] = $val; |
99 | 99 | return; |
100 | 100 | } |
101 | 101 | if (strtolower($parts[0]) === 'shared') { |
102 | - $this->__meta['foreign_models']['mtm'] = $this->createCollection($this->__meta['foreign_models']['mtm'],$val); |
|
102 | + $this->__meta['foreign_models']['mtm'] = $this->createCollection($this->__meta['foreign_models']['mtm'], $val); |
|
103 | 103 | $this->__properties['all'][$key] = $val; |
104 | 104 | return; |
105 | 105 | } |
106 | 106 | } |
107 | 107 | if ($val instanceof Model) { |
108 | - if (isset($this->__properties['all'][$key . '_id'])) { |
|
109 | - unset($this->__properties['all'][$key . '_id']); |
|
108 | + if (isset($this->__properties['all'][$key.'_id'])) { |
|
109 | + unset($this->__properties['all'][$key.'_id']); |
|
110 | 110 | } |
111 | 111 | $this->__meta['foreign_models']['oto'] = $this->createCollection($this->__meta['foreign_models']['oto'], Collection::fromIterable([$val])); |
112 | 112 | $this->__properties['all'][$key] = $val; |
@@ -153,30 +153,30 @@ discard block |
||
153 | 153 | $parts = \Safe\preg_split('/(?=[A-Z])/', $key, -1, PREG_SPLIT_NO_EMPTY); |
154 | 154 | if (strtolower($parts[0]) == 'own') { |
155 | 155 | if (strtolower($parts[2]) == 'list') { |
156 | - $result = $this->connection->getRecordManager()->find(strtolower($parts[1]))->where($this->getName() . '_id = "' . $this->__meta['id'] . '"')->get(); |
|
156 | + $result = $this->connection->getRecordManager()->find(strtolower($parts[1]))->where($this->getName().'_id = "'.$this->__meta['id'].'"')->get(); |
|
157 | 157 | $this->set($key, $result); |
158 | 158 | return $result; |
159 | 159 | } |
160 | 160 | } |
161 | 161 | if (strtolower($parts[0]) == 'shared') { |
162 | 162 | if (strtolower($parts[2]) == 'list') { |
163 | - $rel_table = $this->connection->getTableManager()->tableExists($this->table . '_' . strtolower($parts[1])) ? $this->table . '_' . strtolower($parts[1]) : strtolower($parts[1]) . '_' . $this->table; |
|
164 | - $relations = $this->connection->getRecordManager()->find($rel_table)->where($this->getName() . '_id = "' . $this->__meta['id'] . '"')->get(); |
|
163 | + $rel_table = $this->connection->getTableManager()->tableExists($this->table.'_'.strtolower($parts[1])) ? $this->table.'_'.strtolower($parts[1]) : strtolower($parts[1]).'_'.$this->table; |
|
164 | + $relations = $this->connection->getRecordManager()->find($rel_table)->where($this->getName().'_id = "'.$this->__meta['id'].'"')->get(); |
|
165 | 165 | $rel_ids = ''; |
166 | 166 | foreach ($relations as $relation) { |
167 | - $key = strtolower($parts[1]) . '_id'; |
|
168 | - $rel_ids .= "'" . $relation->$key . "',"; |
|
167 | + $key = strtolower($parts[1]).'_id'; |
|
168 | + $rel_ids .= "'".$relation->$key."',"; |
|
169 | 169 | } |
170 | 170 | $rel_ids = substr($rel_ids, 0, -1); |
171 | - $result = $this->connection->getRecordManager()->find(strtolower($parts[1]))->where('id IN (' . $rel_ids . ')')->get(); |
|
171 | + $result = $this->connection->getRecordManager()->find(strtolower($parts[1]))->where('id IN ('.$rel_ids.')')->get(); |
|
172 | 172 | $this->set($key, $result); |
173 | 173 | return $result; |
174 | 174 | } |
175 | 175 | } |
176 | 176 | } |
177 | 177 | |
178 | - if (array_key_exists($key . '_id', $this->__properties['self'])) { |
|
179 | - $result = $this->connection->getRecordManager()->getById($key, $this->__properties['self'][$key . '_id']); |
|
178 | + if (array_key_exists($key.'_id', $this->__properties['self'])) { |
|
179 | + $result = $this->connection->getRecordManager()->getById($key, $this->__properties['self'][$key.'_id']); |
|
180 | 180 | $this->set($key, $result); |
181 | 181 | return $result; |
182 | 182 | } |
@@ -230,9 +230,9 @@ discard block |
||
230 | 230 | * @throws \Scrawler\Arca\Exception\InvalidModelException |
231 | 231 | * @return Collection |
232 | 232 | */ |
233 | - private function createCollection(?Collection $collection, array|Collection $models): Collection |
|
233 | + private function createCollection(?Collection $collection, array | Collection $models): Collection |
|
234 | 234 | { |
235 | - if(is_null($collection)){ |
|
235 | + if (is_null($collection)) { |
|
236 | 236 | $collection = Collection::fromIterable([]); |
237 | 237 | } |
238 | 238 | |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | */ |
320 | 320 | public function save(): mixed |
321 | 321 | { |
322 | - Event::dispatch('__arca.model.save.' . $this->connection->getConnectionId(), [$this]); |
|
322 | + Event::dispatch('__arca.model.save.'.$this->connection->getConnectionId(), [$this]); |
|
323 | 323 | |
324 | 324 | return $this->getId(); |
325 | 325 | } |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | */ |
345 | 345 | public function delete(): void |
346 | 346 | { |
347 | - Event::dispatch('__arca.model.delete.' . $this->connection->getConnectionId(), [$this]); |
|
347 | + Event::dispatch('__arca.model.delete.'.$this->connection->getConnectionId(), [$this]); |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | /** |