@@ -48,8 +48,8 @@ |
||
48 | 48 | public function getSchema(): Schema; |
49 | 49 | public function setSchema(Schema $schema): static; |
50 | 50 | public function table(string $table, bool $findRelations = false): TableQuery; |
51 | - public function getMapper(Table|string $table): MapperInterface; |
|
52 | - public function setMapper(Table|string $table, MapperInterface $mapper): static; |
|
51 | + public function getMapper(Table | string $table): MapperInterface; |
|
52 | + public function setMapper(Table | string $table, MapperInterface $mapper): static; |
|
53 | 53 | public function tableMapped( |
54 | 54 | string $table, |
55 | 55 | bool $findRelations = false, |
@@ -69,19 +69,19 @@ discard block |
||
69 | 69 | ]; |
70 | 70 | } |
71 | 71 | } |
72 | - $connection['type'] = isset($temp['scheme']) && strlen((string)$temp['scheme']) ? $temp['scheme'] : null; |
|
73 | - $connection['user'] = isset($temp['user']) && strlen((string)$temp['user']) ? $temp['user'] : null; |
|
74 | - $connection['pass'] = isset($temp['pass']) && strlen((string)$temp['pass']) ? $temp['pass'] : null; |
|
75 | - $connection['host'] = isset($temp['host']) && strlen((string)$temp['host']) ? $temp['host'] : null; |
|
76 | - $connection['name'] = isset($temp['path']) && strlen((string)$temp['path']) ? |
|
77 | - trim((string)$temp['path'], '/') : null; |
|
78 | - $connection['port'] = isset($temp['port']) && (int)$temp['port'] ? (int)$temp['port'] : null; |
|
79 | - if (isset($temp['query']) && strlen((string)$temp['query'])) { |
|
80 | - parse_str((string)$temp['query'], $connection['opts']); |
|
72 | + $connection['type'] = isset($temp['scheme']) && strlen((string) $temp['scheme']) ? $temp['scheme'] : null; |
|
73 | + $connection['user'] = isset($temp['user']) && strlen((string) $temp['user']) ? $temp['user'] : null; |
|
74 | + $connection['pass'] = isset($temp['pass']) && strlen((string) $temp['pass']) ? $temp['pass'] : null; |
|
75 | + $connection['host'] = isset($temp['host']) && strlen((string) $temp['host']) ? $temp['host'] : null; |
|
76 | + $connection['name'] = isset($temp['path']) && strlen((string) $temp['path']) ? |
|
77 | + trim((string) $temp['path'], '/') : null; |
|
78 | + $connection['port'] = isset($temp['port']) && (int) $temp['port'] ? (int) $temp['port'] : null; |
|
79 | + if (isset($temp['query']) && strlen((string) $temp['query'])) { |
|
80 | + parse_str((string) $temp['query'], $connection['opts']); |
|
81 | 81 | } |
82 | 82 | // create the driver |
83 | 83 | $connection['type'] = $aliases[$connection['type']] ?? $connection['type']; |
84 | - $tmp = '\\vakata\\database\\driver\\'.strtolower((string)$connection['type']).'\\Driver'; |
|
84 | + $tmp = '\\vakata\\database\\driver\\'.strtolower((string) $connection['type']).'\\Driver'; |
|
85 | 85 | if (!class_exists($tmp)) { |
86 | 86 | throw new DBException('Unknown DB backend'); |
87 | 87 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | $new = ''; |
120 | 120 | $par = array_values($par); |
121 | 121 | if (substr_count($sql, '?') === 2 && !is_array($par[0])) { |
122 | - $par = [ $par ]; |
|
122 | + $par = [$par]; |
|
123 | 123 | } |
124 | 124 | $parts = explode('??', $sql); |
125 | 125 | $index = 0; |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | $index += count($tmp) - 1; |
130 | 130 | if (isset($par[$index])) { |
131 | 131 | if (!is_array($par[$index])) { |
132 | - $par[$index] = [ $par[$index] ]; |
|
132 | + $par[$index] = [$par[$index]]; |
|
133 | 133 | } |
134 | 134 | $params = $par[$index]; |
135 | 135 | array_splice($par, $index, 1, $params); |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | $new .= implode(',', array_fill(0, count($params), '?')); |
138 | 138 | } |
139 | 139 | } |
140 | - return [ $new, $par ]; |
|
140 | + return [$new, $par]; |
|
141 | 141 | } |
142 | 142 | /** |
143 | 143 | * Run a query (prepare & execute). |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | ): Collection { |
187 | 187 | $coll = Collection::from($this->query($sql, $par, $buff)); |
188 | 188 | if (($keys = $this->driver->option('mode')) && in_array($keys, ['strtoupper', 'strtolower'])) { |
189 | - $coll->map(function ($v) use ($keys) { |
|
189 | + $coll->map(function($v) use ($keys) { |
|
190 | 190 | $new = []; |
191 | 191 | foreach ($v as $k => $vv) { |
192 | 192 | $new[call_user_func($keys, $k)] = $vv; |
@@ -195,18 +195,18 @@ discard block |
||
195 | 195 | }); |
196 | 196 | } |
197 | 197 | if ($key !== null) { |
198 | - $coll->mapKey(function ($v) use ($key) { |
|
198 | + $coll->mapKey(function($v) use ($key) { |
|
199 | 199 | return $v[$key]; |
200 | 200 | }); |
201 | 201 | } |
202 | 202 | if ($skip) { |
203 | - $coll->map(function ($v) use ($key) { |
|
203 | + $coll->map(function($v) use ($key) { |
|
204 | 204 | unset($v[$key]); |
205 | 205 | return $v; |
206 | 206 | }); |
207 | 207 | } |
208 | 208 | if ($opti) { |
209 | - $coll->map(function ($v) { |
|
209 | + $coll->map(function($v) { |
|
210 | 210 | return count($v) === 1 ? current($v) : $v; |
211 | 211 | }); |
212 | 212 | } |
@@ -323,8 +323,7 @@ discard block |
||
323 | 323 | public function definition(string $table, bool $detectRelations = true) : Table |
324 | 324 | { |
325 | 325 | return isset($this->schema) ? |
326 | - $this->schema->getTable($table) : |
|
327 | - $this->driver->table($table, $detectRelations); |
|
326 | + $this->schema->getTable($table) : $this->driver->table($table, $detectRelations); |
|
328 | 327 | } |
329 | 328 | |
330 | 329 | public function hasSchema(): bool |
@@ -369,7 +368,7 @@ discard block |
||
369 | 368 | { |
370 | 369 | return new TableQuery($this, $this->definition($table), $findRelations); |
371 | 370 | } |
372 | - public function getMapper(Table|string $table): MapperInterface |
|
371 | + public function getMapper(Table | string $table): MapperInterface |
|
373 | 372 | { |
374 | 373 | if (is_string($table)) { |
375 | 374 | $table = $this->definition($table); |
@@ -379,7 +378,7 @@ discard block |
||
379 | 378 | } |
380 | 379 | return $this->mappers[$table->getFullName()] = new Mapper($this, $table); |
381 | 380 | } |
382 | - public function setMapper(Table|string $table, MapperInterface $mapper): static |
|
381 | + public function setMapper(Table | string $table, MapperInterface $mapper): static |
|
383 | 382 | { |
384 | 383 | if (is_string($table)) { |
385 | 384 | $table = $this->definition($table); |
@@ -395,11 +394,10 @@ discard block |
||
395 | 394 | { |
396 | 395 | return new TableQueryMapped($this, $this->definition($table), $findRelations, $mapper); |
397 | 396 | } |
398 | - public function __call(string $method, array $args): TableQuery|TableQueryMapped |
|
397 | + public function __call(string $method, array $args): TableQuery | TableQueryMapped |
|
399 | 398 | { |
400 | 399 | return ($args[0] ?? false) ? |
401 | - $this->tableMapped($method, $args[1] ?? false, $args[2] ?? null) : |
|
402 | - $this->table($method, $args[1] ?? false); |
|
400 | + $this->tableMapped($method, $args[1] ?? false, $args[2] ?? null) : $this->table($method, $args[1] ?? false); |
|
403 | 401 | } |
404 | 402 | public function findRelation(string $start, string $end): array |
405 | 403 | { |
@@ -435,12 +433,12 @@ discard block |
||
435 | 433 | $relations[$t] = $w; |
436 | 434 | } |
437 | 435 | if (!isset($schema[$name])) { |
438 | - $schema[$name] = [ 'edges' => [] ]; |
|
436 | + $schema[$name] = ['edges' => []]; |
|
439 | 437 | } |
440 | 438 | foreach ($relations as $t => $w) { |
441 | 439 | $schema[$name]['edges'][$t] = $w; |
442 | 440 | if (!isset($schema[$t])) { |
443 | - $schema[$t] = [ 'edges' => [] ]; |
|
441 | + $schema[$t] = ['edges' => []]; |
|
444 | 442 | } |
445 | 443 | $schema[$t]['edges'][$name] = $w; |
446 | 444 | } |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | |
17 | 17 | public function __construct( |
18 | 18 | DBInterface $db, |
19 | - Table|string $table, |
|
19 | + Table | string $table, |
|
20 | 20 | bool $findRelations = false, |
21 | 21 | ?MapperInterface $mapper = null |
22 | 22 | ) { |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | public function iterator(array $fields = null, array $collectionKey = null): Collection |
32 | 32 | { |
33 | 33 | return Collection::from(parent::iterator($fields, $collectionKey)) |
34 | - ->map(function ($v) { |
|
34 | + ->map(function($v) { |
|
35 | 35 | return $this->mapper->entity($v); |
36 | 36 | }); |
37 | 37 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * @param class-string<T> $clss |
26 | 26 | * @return void |
27 | 27 | */ |
28 | - public function __construct(DBInterface $db, string|Table $table = '', string $clss = Entity::class) |
|
28 | + public function __construct(DBInterface $db, string | Table $table = '', string $clss = Entity::class) |
|
29 | 29 | { |
30 | 30 | $this->db = $db; |
31 | 31 | if (!$table) { |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | $lazy = []; |
113 | 113 | foreach ($this->table->getColumns() as $column) { |
114 | 114 | if (!array_key_exists($column, $temp)) { |
115 | - $lazy[$column] = function () use ($primary, $column) { |
|
115 | + $lazy[$column] = function() use ($primary, $column) { |
|
116 | 116 | $query = $this->db->table($this->table->getFullName()); |
117 | 117 | foreach ($primary as $k => $v) { |
118 | 118 | $query->filter($k, $v); |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | $relations = []; |
125 | 125 | foreach ($this->table->getRelations() as $name => $relation) { |
126 | 126 | $mapper = $this->db->getMapper($relation->table); |
127 | - $relations[$name] = function (bool $queryOnly = false) use ( |
|
127 | + $relations[$name] = function(bool $queryOnly = false) use ( |
|
128 | 128 | $name, |
129 | 129 | $relation, |
130 | 130 | $mapper, |
@@ -132,14 +132,14 @@ discard block |
||
132 | 132 | ) { |
133 | 133 | if (!$queryOnly && isset($data[$name])) { |
134 | 134 | return $relation->many ? |
135 | - array_map(function ($v) use ($mapper) { |
|
135 | + array_map(function($v) use ($mapper) { |
|
136 | 136 | return $mapper->entity($v); |
137 | 137 | }, $data[$name]) : |
138 | 138 | $mapper->entity($data[$name]); |
139 | 139 | } |
140 | 140 | $query = $this->db->tableMapped($relation->table->getFullName()); |
141 | 141 | if ($relation->sql) { |
142 | - $query->where($relation->sql, $relation->par?:[]); |
|
142 | + $query->where($relation->sql, $relation->par ?: []); |
|
143 | 143 | } |
144 | 144 | if ($relation->pivot) { |
145 | 145 | $nm = null; |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | ); |
160 | 160 | } |
161 | 161 | foreach ($this->table->getPrimaryKey() as $v) { |
162 | - $query->filter($nm . '.' . $v, $data[$v] ?? null); |
|
162 | + $query->filter($nm.'.'.$v, $data[$v] ?? null); |
|
163 | 163 | } |
164 | 164 | } else { |
165 | 165 | foreach ($relation->keymap as $k => $v) { |
@@ -170,8 +170,7 @@ discard block |
||
170 | 170 | return $query; |
171 | 171 | } |
172 | 172 | return $relation->many ? |
173 | - $query->iterator() : |
|
174 | - ($query[0] ?? null); |
|
173 | + $query->iterator() : ($query[0] ?? null); |
|
175 | 174 | }; |
176 | 175 | } |
177 | 176 | $entity = $this->instance($temp, $lazy, $relations); |