@@ -69,18 +69,18 @@ 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']) ? trim((string)$temp['path'], '/') : null; |
|
| 77 | - $connection['port'] = isset($temp['port']) && (int)$temp['port'] ? (int)$temp['port'] : null; |
|
| 78 | - if (isset($temp['query']) && strlen((string)$temp['query'])) { |
|
| 79 | - 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']) ? trim((string) $temp['path'], '/') : null; |
|
| 77 | + $connection['port'] = isset($temp['port']) && (int) $temp['port'] ? (int) $temp['port'] : null; |
|
| 78 | + if (isset($temp['query']) && strlen((string) $temp['query'])) { |
|
| 79 | + parse_str((string) $temp['query'], $connection['opts']); |
|
| 80 | 80 | } |
| 81 | 81 | // create the driver |
| 82 | 82 | $connection['type'] = $aliases[$connection['type']] ?? $connection['type']; |
| 83 | - $tmp = '\\vakata\\database\\driver\\'.strtolower((string)$connection['type']).'\\Driver'; |
|
| 83 | + $tmp = '\\vakata\\database\\driver\\'.strtolower((string) $connection['type']).'\\Driver'; |
|
| 84 | 84 | if (!class_exists($tmp)) { |
| 85 | 85 | throw new DBException('Unknown DB backend'); |
| 86 | 86 | } |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | $new = ''; |
| 119 | 119 | $par = array_values($par); |
| 120 | 120 | if (substr_count($sql, '?') === 2 && !is_array($par[0])) { |
| 121 | - $par = [ $par ]; |
|
| 121 | + $par = [$par]; |
|
| 122 | 122 | } |
| 123 | 123 | $parts = explode('??', $sql); |
| 124 | 124 | $index = 0; |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | $index += count($tmp) - 1; |
| 129 | 129 | if (isset($par[$index])) { |
| 130 | 130 | if (!is_array($par[$index])) { |
| 131 | - $par[$index] = [ $par[$index] ]; |
|
| 131 | + $par[$index] = [$par[$index]]; |
|
| 132 | 132 | } |
| 133 | 133 | $params = $par[$index]; |
| 134 | 134 | array_splice($par, $index, 1, $params); |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | $new .= implode(',', array_fill(0, count($params), '?')); |
| 137 | 137 | } |
| 138 | 138 | } |
| 139 | - return [ $new, $par ]; |
|
| 139 | + return [$new, $par]; |
|
| 140 | 140 | } |
| 141 | 141 | /** |
| 142 | 142 | * Run a query (prepare & execute). |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | ): Collection { |
| 186 | 186 | $coll = Collection::from($this->query($sql, $par, $buff)); |
| 187 | 187 | if (($keys = $this->driver->option('mode')) && in_array($keys, ['strtoupper', 'strtolower'])) { |
| 188 | - $coll->map(function ($v) use ($keys) { |
|
| 188 | + $coll->map(function($v) use ($keys) { |
|
| 189 | 189 | $new = []; |
| 190 | 190 | foreach ($v as $k => $vv) { |
| 191 | 191 | $new[call_user_func($keys, $k)] = $vv; |
@@ -194,18 +194,18 @@ discard block |
||
| 194 | 194 | }); |
| 195 | 195 | } |
| 196 | 196 | if ($key !== null) { |
| 197 | - $coll->mapKey(function ($v) use ($key) { |
|
| 197 | + $coll->mapKey(function($v) use ($key) { |
|
| 198 | 198 | return $v[$key]; |
| 199 | 199 | }); |
| 200 | 200 | } |
| 201 | 201 | if ($skip) { |
| 202 | - $coll->map(function ($v) use ($key) { |
|
| 202 | + $coll->map(function($v) use ($key) { |
|
| 203 | 203 | unset($v[$key]); |
| 204 | 204 | return $v; |
| 205 | 205 | }); |
| 206 | 206 | } |
| 207 | 207 | if ($opti) { |
| 208 | - $coll->map(function ($v) { |
|
| 208 | + $coll->map(function($v) { |
|
| 209 | 209 | return count($v) === 1 ? current($v) : $v; |
| 210 | 210 | }); |
| 211 | 211 | } |
@@ -300,8 +300,7 @@ discard block |
||
| 300 | 300 | public function definition(string $table, bool $detectRelations = true) : Table |
| 301 | 301 | { |
| 302 | 302 | return isset($this->tables[$table]) ? |
| 303 | - $this->tables[$table] : |
|
| 304 | - $this->driver->table($table, $detectRelations); |
|
| 303 | + $this->tables[$table] : $this->driver->table($table, $detectRelations); |
|
| 305 | 304 | } |
| 306 | 305 | /** |
| 307 | 306 | * Parse all tables from the database. |
@@ -318,13 +317,13 @@ discard block |
||
| 318 | 317 | */ |
| 319 | 318 | public function getSchema(bool $asPlainArray = true): array |
| 320 | 319 | { |
| 321 | - return !$asPlainArray ? $this->tables : array_map(function ($table) { |
|
| 320 | + return !$asPlainArray ? $this->tables : array_map(function($table) { |
|
| 322 | 321 | return [ |
| 323 | 322 | 'name' => $table->getName(), |
| 324 | 323 | 'schema' => $table->getSchema(), |
| 325 | 324 | 'pkey' => $table->getPrimaryKey(), |
| 326 | 325 | 'comment' => $table->getComment(), |
| 327 | - 'columns' => array_map(function ($column) { |
|
| 326 | + 'columns' => array_map(function($column) { |
|
| 328 | 327 | return [ |
| 329 | 328 | 'name' => $column->getName(), |
| 330 | 329 | 'type' => $column->getType(), |
@@ -335,9 +334,9 @@ discard block |
||
| 335 | 334 | 'nullable' => $column->isNullable() |
| 336 | 335 | ]; |
| 337 | 336 | }, $table->getFullColumns()), |
| 338 | - 'relations' => array_map(function ($rel) { |
|
| 337 | + 'relations' => array_map(function($rel) { |
|
| 339 | 338 | $relation = clone $rel; |
| 340 | - $relation = (array)$relation; |
|
| 339 | + $relation = (array) $relation; |
|
| 341 | 340 | $relation['table'] = $rel->table->getName(); |
| 342 | 341 | if ($rel->pivot) { |
| 343 | 342 | $relation['pivot'] = $rel->pivot->getName(); |
@@ -394,8 +393,7 @@ discard block |
||
| 394 | 393 | public function table(string $table, bool $mapped = false, bool $findRelations = false): TableQuery |
| 395 | 394 | { |
| 396 | 395 | return $mapped ? |
| 397 | - new TableQueryMapped($this, $this->definition($table), $findRelations) : |
|
| 398 | - new TableQuery($this, $this->definition($table), $findRelations); |
|
| 396 | + new TableQueryMapped($this, $this->definition($table), $findRelations) : new TableQuery($this, $this->definition($table), $findRelations); |
|
| 399 | 397 | } |
| 400 | 398 | public function __call(string $method, array $args): TableQuery |
| 401 | 399 | { |
@@ -432,12 +430,12 @@ discard block |
||
| 432 | 430 | $relations[$t] = $w; |
| 433 | 431 | } |
| 434 | 432 | if (!isset($schema[$name])) { |
| 435 | - $schema[$name] = [ 'edges' => [] ]; |
|
| 433 | + $schema[$name] = ['edges' => []]; |
|
| 436 | 434 | } |
| 437 | 435 | foreach ($relations as $t => $w) { |
| 438 | 436 | $schema[$name]['edges'][$t] = $w; |
| 439 | 437 | if (!isset($schema[$t])) { |
| 440 | - $schema[$t] = [ 'edges' => [] ]; |
|
| 438 | + $schema[$t] = ['edges' => []]; |
|
| 441 | 439 | } |
| 442 | 440 | $schema[$t]['edges'][$name] = $w; |
| 443 | 441 | } |
@@ -57,8 +57,8 @@ |
||
| 57 | 57 | } |
| 58 | 58 | public function next(): void |
| 59 | 59 | { |
| 60 | - $this->fetched ++; |
|
| 61 | - $this->last = $this->statement->fetch(\PDO::FETCH_ASSOC)?:null; |
|
| 60 | + $this->fetched++; |
|
| 61 | + $this->last = $this->statement->fetch(\PDO::FETCH_ASSOC) ?: null; |
|
| 62 | 62 | } |
| 63 | 63 | public function valid(): bool |
| 64 | 64 | { |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | } |
| 24 | 24 | public function affected() : int |
| 25 | 25 | { |
| 26 | - return (int)\oci_num_rows($this->statement); |
|
| 26 | + return (int) \oci_num_rows($this->statement); |
|
| 27 | 27 | } |
| 28 | 28 | public function insertID(string $sequence = null): mixed |
| 29 | 29 | { |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | public function count(): int |
| 38 | 38 | { |
| 39 | - return (int)\oci_num_rows($this->statement); |
|
| 39 | + return (int) \oci_num_rows($this->statement); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | public function key(): mixed |
@@ -64,8 +64,8 @@ discard block |
||
| 64 | 64 | } |
| 65 | 65 | public function next(): void |
| 66 | 66 | { |
| 67 | - $this->fetched ++; |
|
| 68 | - $this->last = \oci_fetch_array($this->statement, \OCI_ASSOC + \OCI_RETURN_NULLS + \OCI_RETURN_LOBS)?:null; |
|
| 67 | + $this->fetched++; |
|
| 68 | + $this->last = \oci_fetch_array($this->statement, \OCI_ASSOC +\OCI_RETURN_NULLS +\OCI_RETURN_LOBS) ?: null; |
|
| 69 | 69 | } |
| 70 | 70 | public function valid(): bool |
| 71 | 71 | { |
@@ -70,14 +70,14 @@ |
||
| 70 | 70 | if ($log) { |
| 71 | 71 | $tm = microtime(true); |
| 72 | 72 | } |
| 73 | - $res = \oci_execute(\oci_parse($this->lnk, $sql)?:throw new \Exception()); |
|
| 73 | + $res = \oci_execute(\oci_parse($this->lnk, $sql) ?: throw new \Exception()); |
|
| 74 | 74 | if ($log) { |
| 75 | 75 | $tm = microtime(true) - $tm; |
| 76 | - if ($tm >= (float)$this->option('log_slow', 0)) { |
|
| 76 | + if ($tm >= (float) $this->option('log_slow', 0)) { |
|
| 77 | 77 | @file_put_contents( |
| 78 | 78 | $log, |
| 79 | - '--' . date('Y-m-d H:i:s') . ' ' . sprintf('%01.6f', $tm) . "s\r\n" . |
|
| 80 | - $sql . "\r\n" . |
|
| 79 | + '--'.date('Y-m-d H:i:s').' '.sprintf('%01.6f', $tm)."s\r\n". |
|
| 80 | + $sql."\r\n". |
|
| 81 | 81 | "\r\n", |
| 82 | 82 | FILE_APPEND |
| 83 | 83 | ); |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | if ($temp) { |
| 33 | 33 | $temp = $temp->fetch_fields(); |
| 34 | 34 | if ($temp) { |
| 35 | - $columns = array_map(function ($v) { |
|
| 35 | + $columns = array_map(function($v) { |
|
| 36 | 36 | return $v->name; |
| 37 | 37 | }, $temp); |
| 38 | 38 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | } |
| 54 | 54 | public function affected() : int |
| 55 | 55 | { |
| 56 | - return (int)$this->statement->affected_rows; |
|
| 56 | + return (int) $this->statement->affected_rows; |
|
| 57 | 57 | } |
| 58 | 58 | public function insertID(string $sequence = null): mixed |
| 59 | 59 | { |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | } |
| 76 | 76 | public function current(): mixed |
| 77 | 77 | { |
| 78 | - return $this->nativeDriver ? $this->last : array_map(function ($v) { |
|
| 78 | + return $this->nativeDriver ? $this->last : array_map(function($v) { |
|
| 79 | 79 | return $v; |
| 80 | 80 | }, $this->row); |
| 81 | 81 | } |
@@ -94,8 +94,8 @@ discard block |
||
| 94 | 94 | } |
| 95 | 95 | public function next(): void |
| 96 | 96 | { |
| 97 | - $this->fetched ++; |
|
| 98 | - $this->last = $this->nativeDriver ? ($this->result->fetch_assoc()?:null) : $this->statement->fetch(); |
|
| 97 | + $this->fetched++; |
|
| 98 | + $this->last = $this->nativeDriver ? ($this->result->fetch_assoc() ?: null) : $this->statement->fetch(); |
|
| 99 | 99 | } |
| 100 | 100 | public function valid(): bool |
| 101 | 101 | { |
@@ -27,8 +27,8 @@ discard block |
||
| 27 | 27 | $table = $temp[1]; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - if (isset($tables[$schema . '.' . $table])) { |
|
| 31 | - return $tables[$schema . '.' . $table]; |
|
| 30 | + if (isset($tables[$schema.'.'.$table])) { |
|
| 31 | + return $tables[$schema.'.'.$table]; |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | static $comments = []; |
@@ -36,10 +36,10 @@ discard block |
||
| 36 | 36 | $comments[$schema] = Collection::from( |
| 37 | 37 | $this->query( |
| 38 | 38 | "SELECT TABLE_NAME, TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ?", |
| 39 | - [ $schema ] |
|
| 39 | + [$schema] |
|
| 40 | 40 | ) |
| 41 | 41 | ) |
| 42 | - ->mapKey(function (array $v): string { |
|
| 42 | + ->mapKey(function(array $v): string { |
|
| 43 | 43 | return $v['TABLE_NAME']; |
| 44 | 44 | }) |
| 45 | 45 | ->pluck('TABLE_COMMENT') |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | WHERE |
| 60 | 60 | (TABLE_SCHEMA = ? OR REFERENCED_TABLE_SCHEMA = ?) AND |
| 61 | 61 | TABLE_NAME IS NOT NULL AND REFERENCED_TABLE_NAME IS NOT NULL", |
| 62 | - [ $main, $main ] |
|
| 62 | + [$main, $main] |
|
| 63 | 63 | ) |
| 64 | 64 | )->toArray(); |
| 65 | 65 | foreach ($col as $row) { |
@@ -69,8 +69,8 @@ discard block |
||
| 69 | 69 | if ($row['REFERENCED_TABLE_SCHEMA'] !== $main) { |
| 70 | 70 | $additional[] = $row['REFERENCED_TABLE_SCHEMA']; |
| 71 | 71 | } |
| 72 | - $relationsT[$row['TABLE_SCHEMA'] . '.' . $row['TABLE_NAME']][] = $row; |
|
| 73 | - $relationsR[$row['REFERENCED_TABLE_SCHEMA'] . '.' . $row['REFERENCED_TABLE_NAME']][] = $row; |
|
| 72 | + $relationsT[$row['TABLE_SCHEMA'].'.'.$row['TABLE_NAME']][] = $row; |
|
| 73 | + $relationsR[$row['REFERENCED_TABLE_SCHEMA'].'.'.$row['REFERENCED_TABLE_NAME']][] = $row; |
|
| 74 | 74 | } |
| 75 | 75 | foreach (array_filter(array_unique($additional)) as $s) { |
| 76 | 76 | $col = Collection::from( |
@@ -80,12 +80,12 @@ discard block |
||
| 80 | 80 | WHERE |
| 81 | 81 | TABLE_SCHEMA = ? AND REFERENCED_TABLE_SCHEMA = ? AND |
| 82 | 82 | TABLE_NAME IS NOT NULL AND REFERENCED_TABLE_NAME IS NOT NULL", |
| 83 | - [ $s, $s ] |
|
| 83 | + [$s, $s] |
|
| 84 | 84 | ) |
| 85 | 85 | )->toArray(); |
| 86 | 86 | foreach ($col as $row) { |
| 87 | - $relationsT[$row['TABLE_SCHEMA'] . '.' . $row['TABLE_NAME']][] = $row; |
|
| 88 | - $relationsR[$row['REFERENCED_TABLE_SCHEMA'] . '.' . $row['REFERENCED_TABLE_NAME']][] = $row; |
|
| 87 | + $relationsT[$row['TABLE_SCHEMA'].'.'.$row['TABLE_NAME']][] = $row; |
|
| 88 | + $relationsR[$row['REFERENCED_TABLE_SCHEMA'].'.'.$row['REFERENCED_TABLE_NAME']][] = $row; |
|
| 89 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | } |
@@ -94,14 +94,14 @@ discard block |
||
| 94 | 94 | if (!count($columns)) { |
| 95 | 95 | throw new DBException('Table not found by name'); |
| 96 | 96 | } |
| 97 | - $tables[$schema . '.' . $table] = $definition = (new Table($table, $schema)) |
|
| 97 | + $tables[$schema.'.'.$table] = $definition = (new Table($table, $schema)) |
|
| 98 | 98 | ->addColumns( |
| 99 | 99 | $columns |
| 100 | 100 | ->clone() |
| 101 | - ->mapKey(function (array $v): string { |
|
| 101 | + ->mapKey(function(array $v): string { |
|
| 102 | 102 | return $v['Field']; |
| 103 | 103 | }) |
| 104 | - ->map(function (array $v): array { |
|
| 104 | + ->map(function(array $v): array { |
|
| 105 | 105 | $v['length'] = null; |
| 106 | 106 | if (!isset($v['Type'])) { |
| 107 | 107 | return $v; |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | default: |
| 124 | 124 | if (strpos($type, 'char') !== false && strpos($type, '(') !== false) { |
| 125 | 125 | // extract length from varchar |
| 126 | - $v['length'] = (int)explode(')', explode('(', $type)[1])[0]; |
|
| 126 | + $v['length'] = (int) explode(')', explode('(', $type)[1])[0]; |
|
| 127 | 127 | $v['length'] = $v['length'] > 0 ? $v['length'] : null; |
| 128 | 128 | } |
| 129 | 129 | break; |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | ->setPrimaryKey( |
| 136 | 136 | $columns |
| 137 | 137 | ->clone() |
| 138 | - ->filter(function (array $v): bool { |
|
| 138 | + ->filter(function(array $v): bool { |
|
| 139 | 139 | return $v['Key'] === 'PRI'; |
| 140 | 140 | }) |
| 141 | 141 | ->pluck('Field') |
@@ -149,8 +149,8 @@ discard block |
||
| 149 | 149 | // assuming current table is on the "one" end having "many" records in the referencing table |
| 150 | 150 | // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected) |
| 151 | 151 | $relations = []; |
| 152 | - foreach ($relationsR[$schema . '.' . $table] ?? [] as $relation) { |
|
| 153 | - $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_SCHEMA'] . '.' . $relation['TABLE_NAME']; |
|
| 152 | + foreach ($relationsR[$schema.'.'.$table] ?? [] as $relation) { |
|
| 153 | + $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_SCHEMA'].'.'.$relation['TABLE_NAME']; |
|
| 154 | 154 | $relations[$relation['CONSTRAINT_NAME']]['keymap'][$relation['REFERENCED_COLUMN_NAME']] = |
| 155 | 155 | $relation['COLUMN_NAME']; |
| 156 | 156 | } |
@@ -166,10 +166,10 @@ discard block |
||
| 166 | 166 | $usedcol = []; |
| 167 | 167 | if (count($columns)) { |
| 168 | 168 | foreach (Collection::from($relationsT[$data['table']] ?? []) |
| 169 | - ->filter(function (array $v) use ($columns): bool { |
|
| 169 | + ->filter(function(array $v) use ($columns): bool { |
|
| 170 | 170 | return in_array($v['COLUMN_NAME'], $columns); |
| 171 | 171 | }) |
| 172 | - ->map(function (array $v): array { |
|
| 172 | + ->map(function(array $v): array { |
|
| 173 | 173 | $new = []; |
| 174 | 174 | foreach ($v as $kk => $vv) { |
| 175 | 175 | $new[strtoupper($kk)] = $vv; |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | return $new; |
| 178 | 178 | }) as $relation |
| 179 | 179 | ) { |
| 180 | - $foreign[$relation['CONSTRAINT_NAME']]['table'] = $relation['REFERENCED_TABLE_SCHEMA'] . '.' . $relation['REFERENCED_TABLE_NAME']; |
|
| 180 | + $foreign[$relation['CONSTRAINT_NAME']]['table'] = $relation['REFERENCED_TABLE_SCHEMA'].'.'.$relation['REFERENCED_TABLE_NAME']; |
|
| 181 | 181 | $foreign[$relation['CONSTRAINT_NAME']]['keymap'][$relation['COLUMN_NAME']] = |
| 182 | 182 | $relation['REFERENCED_COLUMN_NAME']; |
| 183 | 183 | $usedcol[] = $relation['COLUMN_NAME']; |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | $orig = $relname; |
| 194 | 194 | $cntr = 1; |
| 195 | 195 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
| 196 | - $relname = $orig . '_' . (++ $cntr); |
|
| 196 | + $relname = $orig.'_'.(++$cntr); |
|
| 197 | 197 | } |
| 198 | 198 | $definition->addRelation( |
| 199 | 199 | new TableRelation( |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | $orig = $relname; |
| 215 | 215 | $cntr = 1; |
| 216 | 216 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
| 217 | - $relname = $orig . '_' . (++ $cntr); |
|
| 217 | + $relname = $orig.'_'.(++$cntr); |
|
| 218 | 218 | } |
| 219 | 219 | $definition->addRelation( |
| 220 | 220 | new TableRelation( |
@@ -230,8 +230,8 @@ discard block |
||
| 230 | 230 | // assuming current table is linked to "one" record in the referenced table |
| 231 | 231 | // resulting in a "belongsTo" relationship |
| 232 | 232 | $relations = []; |
| 233 | - foreach (Collection::from($relationsT[$schema . '.' . $table] ?? []) |
|
| 234 | - ->map(function (array $v): array { |
|
| 233 | + foreach (Collection::from($relationsT[$schema.'.'.$table] ?? []) |
|
| 234 | + ->map(function(array $v): array { |
|
| 235 | 235 | $new = []; |
| 236 | 236 | foreach ($v as $kk => $vv) { |
| 237 | 237 | $new[strtoupper($kk)] = $vv; |
@@ -239,7 +239,7 @@ discard block |
||
| 239 | 239 | return $new; |
| 240 | 240 | }) as $relation |
| 241 | 241 | ) { |
| 242 | - $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['REFERENCED_TABLE_SCHEMA'] . '.' . $relation['REFERENCED_TABLE_NAME']; |
|
| 242 | + $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['REFERENCED_TABLE_SCHEMA'].'.'.$relation['REFERENCED_TABLE_NAME']; |
|
| 243 | 243 | $relations[$relation['CONSTRAINT_NAME']]['keymap'][$relation['COLUMN_NAME']] = |
| 244 | 244 | $relation['REFERENCED_COLUMN_NAME']; |
| 245 | 245 | } |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | $orig = $relname; |
| 253 | 253 | $cntr = 1; |
| 254 | 254 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
| 255 | - $relname = $orig . '_' . (++ $cntr); |
|
| 255 | + $relname = $orig.'_'.(++$cntr); |
|
| 256 | 256 | } |
| 257 | 257 | $definition->addRelation( |
| 258 | 258 | new TableRelation( |
@@ -273,23 +273,23 @@ discard block |
||
| 273 | 273 | "SELECT table_name FROM information_schema.tables where table_schema = ?", |
| 274 | 274 | [$this->connection['opts']['schema'] ?? $this->connection['name']] |
| 275 | 275 | )) |
| 276 | - ->map(function (array $v): array { |
|
| 276 | + ->map(function(array $v): array { |
|
| 277 | 277 | $new = []; |
| 278 | 278 | foreach ($v as $kk => $vv) { |
| 279 | 279 | $new[strtoupper($kk)] = $vv; |
| 280 | 280 | } |
| 281 | 281 | return $new; |
| 282 | 282 | }) |
| 283 | - ->mapKey(function (array $v): string { |
|
| 283 | + ->mapKey(function(array $v): string { |
|
| 284 | 284 | return $v['TABLE_NAME']; |
| 285 | 285 | }) |
| 286 | 286 | ->pluck('TABLE_NAME') |
| 287 | - ->map(function (string $v): Table { |
|
| 287 | + ->map(function(string $v): Table { |
|
| 288 | 288 | return $this->table($v); |
| 289 | 289 | }) |
| 290 | 290 | ->toArray(); |
| 291 | 291 | foreach (array_keys($tables) as $k) { |
| 292 | - $tables[($this->connection['opts']['schema'] ?? $this->connection['name']) . '.' . $k] = &$tables[$k]; |
|
| 292 | + $tables[($this->connection['opts']['schema'] ?? $this->connection['name']).'.'.$k] = &$tables[$k]; |
|
| 293 | 293 | } |
| 294 | 294 | return $tables; |
| 295 | 295 | } |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | foreach ($lng as $index) { |
| 78 | 78 | if (is_resource($data[$index]) && get_resource_type($data[$index]) === 'stream') { |
| 79 | 79 | while (!feof($data[$index])) { |
| 80 | - $this->statement->send_long_data($index, (string)fread($data[$index], $lds)); |
|
| 80 | + $this->statement->send_long_data($index, (string) fread($data[$index], $lds)); |
|
| 81 | 81 | } |
| 82 | 82 | } else { |
| 83 | 83 | $data[$index] = str_split($data[$index], $lds); |
@@ -92,24 +92,24 @@ discard block |
||
| 92 | 92 | $tm = microtime(true); |
| 93 | 93 | } |
| 94 | 94 | if (!$this->statement->execute()) { |
| 95 | - if ($log && (int)$this->driver->option('log_errors', 1)) { |
|
| 95 | + if ($log && (int) $this->driver->option('log_errors', 1)) { |
|
| 96 | 96 | @file_put_contents( |
| 97 | 97 | $log, |
| 98 | - '--' . date('Y-m-d H:i:s') . ' ERROR: ' . $this->statement->error . "\r\n" . |
|
| 99 | - $this->sql . "\r\n" . |
|
| 98 | + '--'.date('Y-m-d H:i:s').' ERROR: '.$this->statement->error."\r\n". |
|
| 99 | + $this->sql."\r\n". |
|
| 100 | 100 | "\r\n", |
| 101 | 101 | FILE_APPEND |
| 102 | 102 | ); |
| 103 | 103 | } |
| 104 | - throw new DBException('Prepared execute error: ' . $this->statement->error); |
|
| 104 | + throw new DBException('Prepared execute error: '.$this->statement->error); |
|
| 105 | 105 | } |
| 106 | 106 | if ($log) { |
| 107 | 107 | $tm = microtime(true) - $tm; |
| 108 | - if ($tm >= (float)$this->driver->option('log_slow', 0)) { |
|
| 108 | + if ($tm >= (float) $this->driver->option('log_slow', 0)) { |
|
| 109 | 109 | @file_put_contents( |
| 110 | 110 | $log, |
| 111 | - '--' . date('Y-m-d H:i:s') . ' ' . sprintf('%01.6f', $tm) . "s\r\n" . |
|
| 112 | - $this->sql . "\r\n" . |
|
| 111 | + '--'.date('Y-m-d H:i:s').' '.sprintf('%01.6f', $tm)."s\r\n". |
|
| 112 | + $this->sql."\r\n". |
|
| 113 | 113 | "\r\n", |
| 114 | 114 | FILE_APPEND |
| 115 | 115 | ); |
@@ -57,8 +57,8 @@ |
||
| 57 | 57 | } |
| 58 | 58 | public function next(): void |
| 59 | 59 | { |
| 60 | - $this->fetched ++; |
|
| 61 | - $this->last = $this->result->fetch_assoc()?:null; |
|
| 60 | + $this->fetched++; |
|
| 61 | + $this->last = $this->result->fetch_assoc() ?: null; |
|
| 62 | 62 | } |
| 63 | 63 | public function valid(): bool |
| 64 | 64 | { |
@@ -40,23 +40,23 @@ |
||
| 40 | 40 | break; |
| 41 | 41 | case 'array': |
| 42 | 42 | $par = implode(',', $par); |
| 43 | - $par = "'" . $this->lnk->escape_string($par) . "'"; |
|
| 43 | + $par = "'".$this->lnk->escape_string($par)."'"; |
|
| 44 | 44 | break; |
| 45 | 45 | case 'object': |
| 46 | 46 | $par = serialize($par); |
| 47 | - $par = "'" . $this->lnk->escape_string($par) . "'"; |
|
| 47 | + $par = "'".$this->lnk->escape_string($par)."'"; |
|
| 48 | 48 | break; |
| 49 | 49 | case 'resource': |
| 50 | 50 | if (is_resource($par) && get_resource_type($par) === 'stream') { |
| 51 | 51 | $par = stream_get_contents($par); |
| 52 | - $par = "'" . $this->lnk->escape_string($par) . "'"; |
|
| 52 | + $par = "'".$this->lnk->escape_string($par)."'"; |
|
| 53 | 53 | } else { |
| 54 | 54 | $par = serialize($par); |
| 55 | - $par = "'" . $this->lnk->escape_string($par) . "'"; |
|
| 55 | + $par = "'".$this->lnk->escape_string($par)."'"; |
|
| 56 | 56 | } |
| 57 | 57 | break; |
| 58 | 58 | default: |
| 59 | - $par = "'" . $this->lnk->escape_string((string)$par) . "'"; |
|
| 59 | + $par = "'".$this->lnk->escape_string((string) $par)."'"; |
|
| 60 | 60 | break; |
| 61 | 61 | } |
| 62 | 62 | $sql .= $par; |