@@ -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 | } |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | $lazy = []; |
| 81 | 81 | foreach ($this->table->getColumns() as $column) { |
| 82 | 82 | if (!array_key_exists($column, $temp)) { |
| 83 | - $lazy[$column] = function () use ($primary, $column) { |
|
| 83 | + $lazy[$column] = function() use ($primary, $column) { |
|
| 84 | 84 | $query = $this->db->table($this->table->getFullName()); |
| 85 | 85 | foreach ($primary as $k => $v) { |
| 86 | 86 | $query->filter($k, $v); |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | $relations = []; |
| 93 | 93 | foreach ($this->table->getRelations() as $name => $relation) { |
| 94 | 94 | $mapper = $this->db->getMapper($relation->table); |
| 95 | - $relations[$name] = function (bool $queryOnly = false) use ( |
|
| 95 | + $relations[$name] = function(bool $queryOnly = false) use ( |
|
| 96 | 96 | $name, |
| 97 | 97 | $relation, |
| 98 | 98 | $mapper, |
@@ -100,14 +100,14 @@ discard block |
||
| 100 | 100 | ) { |
| 101 | 101 | if (!$queryOnly && isset($data[$name])) { |
| 102 | 102 | return $relation->many ? |
| 103 | - array_map(function ($v) use ($mapper) { |
|
| 103 | + array_map(function($v) use ($mapper) { |
|
| 104 | 104 | return $mapper->entity($v); |
| 105 | 105 | }, $data[$name]) : |
| 106 | 106 | $mapper->entity($data[$name]); |
| 107 | 107 | } |
| 108 | 108 | $query = $this->db->tableMapped($relation->table->getFullName()); |
| 109 | 109 | if ($relation->sql) { |
| 110 | - $query->where($relation->sql, $relation->par?:[]); |
|
| 110 | + $query->where($relation->sql, $relation->par ?: []); |
|
| 111 | 111 | } |
| 112 | 112 | if ($relation->pivot) { |
| 113 | 113 | $nm = null; |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | ); |
| 128 | 128 | } |
| 129 | 129 | foreach ($this->table->getPrimaryKey() as $v) { |
| 130 | - $query->filter($nm . '.' . $v, $data[$v] ?? null); |
|
| 130 | + $query->filter($nm.'.'.$v, $data[$v] ?? null); |
|
| 131 | 131 | } |
| 132 | 132 | } else { |
| 133 | 133 | foreach ($relation->keymap as $k => $v) { |
@@ -138,8 +138,7 @@ discard block |
||
| 138 | 138 | return $query; |
| 139 | 139 | } |
| 140 | 140 | return $relation->many ? |
| 141 | - $query->iterator() : |
|
| 142 | - ($query[0] ?? null); |
|
| 141 | + $query->iterator() : ($query[0] ?? null); |
|
| 143 | 142 | }; |
| 144 | 143 | } |
| 145 | 144 | $entity = $this->instance($temp, $lazy, $relations); |