@@ -74,19 +74,19 @@ discard block |
||
| 74 | 74 | ]; |
| 75 | 75 | } |
| 76 | 76 | } |
| 77 | - $connection['type'] = isset($temp['scheme']) && strlen((string)$temp['scheme']) ? $temp['scheme'] : null; |
|
| 78 | - $connection['user'] = isset($temp['user']) && strlen((string)$temp['user']) ? $temp['user'] : null; |
|
| 79 | - $connection['pass'] = isset($temp['pass']) && strlen((string)$temp['pass']) ? $temp['pass'] : null; |
|
| 80 | - $connection['host'] = isset($temp['host']) && strlen((string)$temp['host']) ? $temp['host'] : null; |
|
| 81 | - $connection['name'] = isset($temp['path']) && strlen((string)$temp['path']) ? |
|
| 82 | - trim((string)$temp['path'], '/') : null; |
|
| 83 | - $connection['port'] = isset($temp['port']) && (int)$temp['port'] ? (int)$temp['port'] : null; |
|
| 84 | - if (isset($temp['query']) && strlen((string)$temp['query'])) { |
|
| 85 | - parse_str((string)$temp['query'], $connection['opts']); |
|
| 77 | + $connection['type'] = isset($temp['scheme']) && strlen((string) $temp['scheme']) ? $temp['scheme'] : null; |
|
| 78 | + $connection['user'] = isset($temp['user']) && strlen((string) $temp['user']) ? $temp['user'] : null; |
|
| 79 | + $connection['pass'] = isset($temp['pass']) && strlen((string) $temp['pass']) ? $temp['pass'] : null; |
|
| 80 | + $connection['host'] = isset($temp['host']) && strlen((string) $temp['host']) ? $temp['host'] : null; |
|
| 81 | + $connection['name'] = isset($temp['path']) && strlen((string) $temp['path']) ? |
|
| 82 | + trim((string) $temp['path'], '/') : null; |
|
| 83 | + $connection['port'] = isset($temp['port']) && (int) $temp['port'] ? (int) $temp['port'] : null; |
|
| 84 | + if (isset($temp['query']) && strlen((string) $temp['query'])) { |
|
| 85 | + parse_str((string) $temp['query'], $connection['opts']); |
|
| 86 | 86 | } |
| 87 | 87 | // create the driver |
| 88 | 88 | $connection['type'] = $aliases[$connection['type']] ?? $connection['type']; |
| 89 | - $tmp = '\\vakata\\database\\driver\\'.strtolower((string)$connection['type']).'\\Driver'; |
|
| 89 | + $tmp = '\\vakata\\database\\driver\\'.strtolower((string) $connection['type']).'\\Driver'; |
|
| 90 | 90 | if (!class_exists($tmp)) { |
| 91 | 91 | throw new DBException('Unknown DB backend'); |
| 92 | 92 | } |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | $map = []; |
| 131 | 131 | $sql = preg_replace_callback( |
| 132 | 132 | '((?<!:)\:[a-z_][a-z0-9_]+)i', |
| 133 | - function ($matches) use (&$map, $par) { |
|
| 133 | + function($matches) use (&$map, $par) { |
|
| 134 | 134 | $key = substr($matches[0], 1); |
| 135 | 135 | $map[] = $key; |
| 136 | 136 | return isset($par) && isset($par[$key]) && is_array($par[$key]) ? '??' : '?'; |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | $new = ''; |
| 148 | 148 | $par = array_values($par); |
| 149 | 149 | if (substr_count($sql, '?') === 2 && !is_array($par[0])) { |
| 150 | - $par = [ $par ]; |
|
| 150 | + $par = [$par]; |
|
| 151 | 151 | } |
| 152 | 152 | $parts = explode('??', $sql); |
| 153 | 153 | $index = 0; |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | $index += count($tmp) - 1; |
| 158 | 158 | if (isset($par[$index])) { |
| 159 | 159 | if (!is_array($par[$index])) { |
| 160 | - $par[$index] = [ $par[$index] ]; |
|
| 160 | + $par[$index] = [$par[$index]]; |
|
| 161 | 161 | } |
| 162 | 162 | $params = $par[$index]; |
| 163 | 163 | array_splice($par, $index, 1, $params); |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | $new .= implode(',', array_fill(0, count($params), '?')); |
| 166 | 166 | } |
| 167 | 167 | } |
| 168 | - return [ $new, $par ]; |
|
| 168 | + return [$new, $par]; |
|
| 169 | 169 | } |
| 170 | 170 | /** |
| 171 | 171 | * Run a query (prepare & execute). |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | $sql = $tmp['sql']; |
| 183 | 183 | $ord = []; |
| 184 | 184 | foreach ($tmp['map'] as $key) { |
| 185 | - $ord[] = $par[$key] ?? throw new DBException('Missing param ' . $key); |
|
| 185 | + $ord[] = $par[$key] ?? throw new DBException('Missing param '.$key); |
|
| 186 | 186 | } |
| 187 | 187 | $par = $ord; |
| 188 | 188 | } |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | ): Collection { |
| 224 | 224 | $coll = Collection::from($this->query($sql, $par, $buff)); |
| 225 | 225 | if (($keys = $this->driver->option('mode')) && in_array($keys, ['strtoupper', 'strtolower'])) { |
| 226 | - $coll->map(function ($v) use ($keys) { |
|
| 226 | + $coll->map(function($v) use ($keys) { |
|
| 227 | 227 | $new = []; |
| 228 | 228 | foreach ($v as $k => $vv) { |
| 229 | 229 | $new[call_user_func($keys, $k)] = $vv; |
@@ -232,18 +232,18 @@ discard block |
||
| 232 | 232 | }); |
| 233 | 233 | } |
| 234 | 234 | if ($key !== null) { |
| 235 | - $coll->mapKey(function ($v) use ($key): int|string { |
|
| 235 | + $coll->mapKey(function($v) use ($key): int | string { |
|
| 236 | 236 | return $v[$key]; |
| 237 | 237 | }); |
| 238 | 238 | } |
| 239 | 239 | if ($skip) { |
| 240 | - $coll->map(function ($v) use ($key) { |
|
| 240 | + $coll->map(function($v) use ($key) { |
|
| 241 | 241 | unset($v[$key]); |
| 242 | 242 | return $v; |
| 243 | 243 | }); |
| 244 | 244 | } |
| 245 | 245 | if ($opti) { |
| 246 | - $coll->map(function ($v) { |
|
| 246 | + $coll->map(function($v) { |
|
| 247 | 247 | return count($v) === 1 ? current($v) : $v; |
| 248 | 248 | }); |
| 249 | 249 | } |
@@ -360,8 +360,7 @@ discard block |
||
| 360 | 360 | public function definition(string $table, bool $detectRelations = true) : Table |
| 361 | 361 | { |
| 362 | 362 | return isset($this->schema) ? |
| 363 | - $this->schema->getTable($table) : |
|
| 364 | - $this->driver->table($table, $detectRelations); |
|
| 363 | + $this->schema->getTable($table) : $this->driver->table($table, $detectRelations); |
|
| 365 | 364 | } |
| 366 | 365 | |
| 367 | 366 | public function hasSchema(): bool |
@@ -471,11 +470,11 @@ discard block |
||
| 471 | 470 | * @param class-string<T>|Table|string $table |
| 472 | 471 | * @return ($table is class-string ? MapperInterface<T> : MapperInterface<Entity>) |
| 473 | 472 | */ |
| 474 | - public function getMapper(Table|string $table): MapperInterface |
|
| 473 | + public function getMapper(Table | string $table): MapperInterface |
|
| 475 | 474 | { |
| 476 | 475 | if (is_string($table)) { |
| 477 | - if (isset($this->mappers['::' . $table])) { |
|
| 478 | - return $this->mappers['::' . $table]; |
|
| 476 | + if (isset($this->mappers['::'.$table])) { |
|
| 477 | + return $this->mappers['::'.$table]; |
|
| 479 | 478 | } |
| 480 | 479 | $table = $this->definition($table); |
| 481 | 480 | } |
@@ -484,14 +483,14 @@ discard block |
||
| 484 | 483 | } |
| 485 | 484 | return $this->mappers[$table->getFullName()] = new Mapper($this, $table); |
| 486 | 485 | } |
| 487 | - public function setMapper(Table|string $table, MapperInterface $mapper, ?string $class = null): static |
|
| 486 | + public function setMapper(Table | string $table, MapperInterface $mapper, ?string $class = null): static |
|
| 488 | 487 | { |
| 489 | 488 | if (is_string($table)) { |
| 490 | 489 | $table = $this->definition($table); |
| 491 | 490 | } |
| 492 | 491 | $this->mappers[$table->getFullName()] = $mapper; |
| 493 | 492 | if (isset($class)) { |
| 494 | - $this->mappers['::' . $class] = $mapper; |
|
| 493 | + $this->mappers['::'.$class] = $mapper; |
|
| 495 | 494 | } |
| 496 | 495 | return $this; |
| 497 | 496 | } |
@@ -507,11 +506,10 @@ discard block |
||
| 507 | 506 | ): TableQueryMapped { |
| 508 | 507 | return new TableQueryMapped($this, $this->definition($table), $findRelations, $mapper); |
| 509 | 508 | } |
| 510 | - public function __call(string $method, array $args): TableQuery|TableQueryMapped |
|
| 509 | + public function __call(string $method, array $args): TableQuery | TableQueryMapped |
|
| 511 | 510 | { |
| 512 | 511 | return ($args[0] ?? false) ? |
| 513 | - $this->tableMapped($method, $args[1] ?? false, $args[2] ?? null) : |
|
| 514 | - $this->table($method, $args[1] ?? false); |
|
| 512 | + $this->tableMapped($method, $args[1] ?? false, $args[2] ?? null) : $this->table($method, $args[1] ?? false); |
|
| 515 | 513 | } |
| 516 | 514 | public function findRelation(string $start, string $end): array |
| 517 | 515 | { |
@@ -547,12 +545,12 @@ discard block |
||
| 547 | 545 | $relations[$t] = $w; |
| 548 | 546 | } |
| 549 | 547 | if (!isset($schema[$name])) { |
| 550 | - $schema[$name] = [ 'edges' => [] ]; |
|
| 548 | + $schema[$name] = ['edges' => []]; |
|
| 551 | 549 | } |
| 552 | 550 | foreach ($relations as $t => $w) { |
| 553 | 551 | $schema[$name]['edges'][$t] = $w; |
| 554 | 552 | if (!isset($schema[$t])) { |
| 555 | - $schema[$t] = [ 'edges' => [] ]; |
|
| 553 | + $schema[$t] = ['edges' => []]; |
|
| 556 | 554 | } |
| 557 | 555 | $schema[$t]['edges'][$name] = $w; |
| 558 | 556 | } |