@@ -29,8 +29,8 @@ discard block |
||
| 29 | 29 | $table = $temp[1]; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - if (isset($tables[$schema . '.' . $table])) { |
|
| 33 | - return $tables[$schema . '.' . $table]; |
|
| 32 | + if (isset($tables[$schema.'.'.$table])) { |
|
| 33 | + return $tables[$schema.'.'.$table]; |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | static $relationsT = null; |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | (kc.table_schema = ? OR ct.table_schema = ?) AND |
| 62 | 62 | kc.table_name IS NOT NULL AND |
| 63 | 63 | kc.position_in_unique_constraint IS NOT NULL", |
| 64 | - [ $catalog, $main, $main ] |
|
| 64 | + [$catalog, $main, $main] |
|
| 65 | 65 | ) |
| 66 | 66 | )->toArray(); |
| 67 | 67 | foreach ($col as $row) { |
@@ -71,8 +71,8 @@ discard block |
||
| 71 | 71 | if ($row['referenced_table_schema'] !== $main) { |
| 72 | 72 | $additional[] = $row['referenced_table_schema']; |
| 73 | 73 | } |
| 74 | - $relationsT[$row['table_schema'] . '.' . $row['table_name']][] = $row; |
|
| 75 | - $relationsR[$row['referenced_table_schema'] . '.' . $row['referenced_table_name']][] = $row; |
|
| 74 | + $relationsT[$row['table_schema'].'.'.$row['table_name']][] = $row; |
|
| 75 | + $relationsR[$row['referenced_table_schema'].'.'.$row['referenced_table_name']][] = $row; |
|
| 76 | 76 | } |
| 77 | 77 | foreach (array_filter(array_unique($additional)) as $s) { |
| 78 | 78 | $col = Collection::from( |
@@ -97,12 +97,12 @@ discard block |
||
| 97 | 97 | (kc.table_schema = ? AND ct.table_schema = ?) AND |
| 98 | 98 | kc.table_name IS NOT NULL AND |
| 99 | 99 | kc.position_in_unique_constraint IS NOT NULL", |
| 100 | - [ $catalog, $s, $s ] |
|
| 100 | + [$catalog, $s, $s] |
|
| 101 | 101 | ) |
| 102 | 102 | )->toArray(); |
| 103 | 103 | foreach ($col as $row) { |
| 104 | - $relationsT[$row['table_schema'] . '.' . $row['table_name']][] = $row; |
|
| 105 | - $relationsR[$row['referenced_table_schema'] . '.' . $row['referenced_table_name']][] = $row; |
|
| 104 | + $relationsT[$row['table_schema'].'.'.$row['table_name']][] = $row; |
|
| 105 | + $relationsR[$row['referenced_table_schema'].'.'.$row['referenced_table_name']][] = $row; |
|
| 106 | 106 | } |
| 107 | 107 | } |
| 108 | 108 | } |
@@ -114,12 +114,12 @@ discard block |
||
| 114 | 114 | ->query( |
| 115 | 115 | "SELECT * FROM information_schema.columns |
| 116 | 116 | WHERE table_name = ? AND table_schema = ? AND table_catalog = ?", |
| 117 | - [ $table, $schema, $catalog ] |
|
| 117 | + [$table, $schema, $catalog] |
|
| 118 | 118 | )) |
| 119 | - ->mapKey(function ($v): string { |
|
| 119 | + ->mapKey(function($v): string { |
|
| 120 | 120 | return $v['column_name']; |
| 121 | 121 | }) |
| 122 | - ->map(function ($v) { |
|
| 122 | + ->map(function($v) { |
|
| 123 | 123 | $v['length'] = null; |
| 124 | 124 | if (!isset($v['data_type'])) { |
| 125 | 125 | return $v; |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | switch ($v['data_type']) { |
| 128 | 128 | case 'character': |
| 129 | 129 | case 'character varying': |
| 130 | - $v['length'] = (int)$v['character_maximum_length']; |
|
| 130 | + $v['length'] = (int) $v['character_maximum_length']; |
|
| 131 | 131 | break; |
| 132 | 132 | } |
| 133 | 133 | $v['hidden'] = $v['is_identity'] !== 'YES' && $v['is_generated'] === 'ALWAYS'; |
@@ -135,13 +135,13 @@ discard block |
||
| 135 | 135 | }) |
| 136 | 136 | ->toArray(); |
| 137 | 137 | if (!count($columns)) { |
| 138 | - throw new DBException('Table not found by name: ' . implode('.', [$schema,$table])); |
|
| 138 | + throw new DBException('Table not found by name: '.implode('.', [$schema, $table])); |
|
| 139 | 139 | } |
| 140 | 140 | $pkname = Collection::from($this |
| 141 | 141 | ->query( |
| 142 | 142 | "SELECT constraint_name FROM information_schema.table_constraints |
| 143 | 143 | WHERE table_name = ? AND constraint_type = ? AND table_schema = ? AND table_catalog = ?", |
| 144 | - [ $table, 'PRIMARY KEY', $schema, $catalog ] |
|
| 144 | + [$table, 'PRIMARY KEY', $schema, $catalog] |
|
| 145 | 145 | )) |
| 146 | 146 | ->pluck('constraint_name') |
| 147 | 147 | ->value(); |
@@ -151,32 +151,32 @@ discard block |
||
| 151 | 151 | ->query( |
| 152 | 152 | "SELECT column_name FROM information_schema.constraint_column_usage |
| 153 | 153 | WHERE table_name = ? AND constraint_name = ? AND table_schema = ? AND table_catalog = ?", |
| 154 | - [ $table, $pkname, $schema, $catalog ] |
|
| 154 | + [$table, $pkname, $schema, $catalog] |
|
| 155 | 155 | )) |
| 156 | 156 | ->pluck('column_name') |
| 157 | 157 | ->toArray(); |
| 158 | 158 | } |
| 159 | - $tables[$schema . '.' .$table] = $definition = (new Table($table, $schema)) |
|
| 159 | + $tables[$schema.'.'.$table] = $definition = (new Table($table, $schema)) |
|
| 160 | 160 | ->addColumns($columns) |
| 161 | 161 | ->setPrimaryKey($primary) |
| 162 | 162 | ->setComment(''); |
| 163 | 163 | |
| 164 | 164 | if ($detectRelations) { |
| 165 | 165 | $duplicated = []; |
| 166 | - foreach ($relationsT[$schema . '.' . $table] ?? [] as $relation) { |
|
| 167 | - $t = $relation['referenced_table_schema'] . '.' . $relation['referenced_table_name']; |
|
| 166 | + foreach ($relationsT[$schema.'.'.$table] ?? [] as $relation) { |
|
| 167 | + $t = $relation['referenced_table_schema'].'.'.$relation['referenced_table_name']; |
|
| 168 | 168 | $duplicated[$t] = isset($duplicated[$t]); |
| 169 | 169 | } |
| 170 | - foreach ($relationsR[$schema . '.' . $table] ?? [] as $relation) { |
|
| 171 | - $t = $relation['table_schema'] . '.' . $relation['table_name']; |
|
| 170 | + foreach ($relationsR[$schema.'.'.$table] ?? [] as $relation) { |
|
| 171 | + $t = $relation['table_schema'].'.'.$relation['table_name']; |
|
| 172 | 172 | $duplicated[$t] = isset($duplicated[$t]); |
| 173 | 173 | } |
| 174 | 174 | // pivot relations where the current table is referenced |
| 175 | 175 | // assuming current table is on the "one" end having "many" records in the referencing table |
| 176 | 176 | // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected) |
| 177 | 177 | $relations = []; |
| 178 | - foreach ($relationsR[$schema . '.' . $table] ?? [] as $relation) { |
|
| 179 | - $relations[$relation['constraint_name']]['table'] = $relation['table_schema'] . '.' . |
|
| 178 | + foreach ($relationsR[$schema.'.'.$table] ?? [] as $relation) { |
|
| 179 | + $relations[$relation['constraint_name']]['table'] = $relation['table_schema'].'.'. |
|
| 180 | 180 | $relation['table_name']; |
| 181 | 181 | $relations[$relation['constraint_name']]['keymap'][$relation['referenced_column_name']] = |
| 182 | 182 | $relation['column_name']; |
@@ -193,11 +193,11 @@ discard block |
||
| 193 | 193 | $usedcol = []; |
| 194 | 194 | if (count($columns)) { |
| 195 | 195 | foreach (Collection::from($relationsT[$data['table']] ?? []) |
| 196 | - ->filter(function ($v) use ($columns) { |
|
| 196 | + ->filter(function($v) use ($columns) { |
|
| 197 | 197 | return in_array($v['column_name'], $columns); |
| 198 | 198 | }) as $relation |
| 199 | 199 | ) { |
| 200 | - $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' . |
|
| 200 | + $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'. |
|
| 201 | 201 | $relation['referenced_table_name']; |
| 202 | 202 | $foreign[$relation['constraint_name']]['keymap'][$relation['column_name']] = |
| 203 | 203 | $relation['referenced_column_name']; |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | $definition->getName() == $relname || |
| 218 | 218 | $definition->getColumn($relname) |
| 219 | 219 | ) { |
| 220 | - $relname = $orig . '_' . (++ $cntr); |
|
| 220 | + $relname = $orig.'_'.(++$cntr); |
|
| 221 | 221 | } |
| 222 | 222 | $definition->addRelation( |
| 223 | 223 | new TableRelation( |
@@ -239,8 +239,8 @@ discard block |
||
| 239 | 239 | // assuming current table is linked to "one" record in the referenced table |
| 240 | 240 | // resulting in a "belongsTo" relationship |
| 241 | 241 | $relations = []; |
| 242 | - foreach ($relationsT[$schema . '.' . $table] ?? [] as $relation) { |
|
| 243 | - $relations[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' . |
|
| 242 | + foreach ($relationsT[$schema.'.'.$table] ?? [] as $relation) { |
|
| 243 | + $relations[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'. |
|
| 244 | 244 | $relation['referenced_table_name']; |
| 245 | 245 | $relations[$relation['constraint_name']]['keymap'][$relation['column_name']] = |
| 246 | 246 | $relation['referenced_column_name']; |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | $definition->getName() == $relname || |
| 257 | 257 | $definition->getColumn($relname) |
| 258 | 258 | ) { |
| 259 | - $relname = array_keys($data['keymap'])[0] . '_' . $relname; |
|
| 259 | + $relname = array_keys($data['keymap'])[0].'_'.$relname; |
|
| 260 | 260 | } |
| 261 | 261 | $orig = $relname; |
| 262 | 262 | $cntr = 1; |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | $definition->getName() == $relname || |
| 265 | 265 | $definition->getColumn($relname) |
| 266 | 266 | ) { |
| 267 | - $relname = $orig . '_' . (++ $cntr); |
|
| 267 | + $relname = $orig.'_'.(++$cntr); |
|
| 268 | 268 | } |
| 269 | 269 | $definition->addRelation( |
| 270 | 270 | new TableRelation( |
@@ -280,8 +280,8 @@ discard block |
||
| 280 | 280 | // assuming current table is on the "one" end having "many" records in the referencing table |
| 281 | 281 | // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected) |
| 282 | 282 | $relations = []; |
| 283 | - foreach ($relationsR[$schema . '.' . $table] ?? [] as $relation) { |
|
| 284 | - $relations[$relation['constraint_name']]['table'] = $relation['table_schema'] . '.' . |
|
| 283 | + foreach ($relationsR[$schema.'.'.$table] ?? [] as $relation) { |
|
| 284 | + $relations[$relation['constraint_name']]['table'] = $relation['table_schema'].'.'. |
|
| 285 | 285 | $relation['table_name']; |
| 286 | 286 | $relations[$relation['constraint_name']]['keymap'][$relation['referenced_column_name']] = |
| 287 | 287 | $relation['column_name']; |
@@ -298,11 +298,11 @@ discard block |
||
| 298 | 298 | $usedcol = []; |
| 299 | 299 | if (count($columns)) { |
| 300 | 300 | foreach (Collection::from($relationsT[$data['table']] ?? []) |
| 301 | - ->filter(function ($v) use ($columns) { |
|
| 301 | + ->filter(function($v) use ($columns) { |
|
| 302 | 302 | return in_array($v['column_name'], $columns); |
| 303 | 303 | }) as $relation |
| 304 | 304 | ) { |
| 305 | - $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' . |
|
| 305 | + $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'. |
|
| 306 | 306 | $relation['referenced_table_name']; |
| 307 | 307 | $foreign[$relation['constraint_name']]['keymap'][$relation['column_name']] = |
| 308 | 308 | $relation['referenced_column_name']; |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | $definition->getName() == $relname || |
| 321 | 321 | $definition->getColumn($relname) |
| 322 | 322 | ) { |
| 323 | - $relname .= '_' . array_values($data['keymap'])[0]; |
|
| 323 | + $relname .= '_'.array_values($data['keymap'])[0]; |
|
| 324 | 324 | } |
| 325 | 325 | $orig = $relname; |
| 326 | 326 | $cntr = 1; |
@@ -328,7 +328,7 @@ discard block |
||
| 328 | 328 | $definition->getName() == $relname || |
| 329 | 329 | $definition->getColumn($relname) |
| 330 | 330 | ) { |
| 331 | - $relname = $orig . '_' . (++ $cntr); |
|
| 331 | + $relname = $orig.'_'.(++$cntr); |
|
| 332 | 332 | } |
| 333 | 333 | $definition->addRelation( |
| 334 | 334 | new TableRelation( |
@@ -378,20 +378,20 @@ discard block |
||
| 378 | 378 | attr.attnum > 0 |
| 379 | 379 | order by |
| 380 | 380 | attr.attnum", |
| 381 | - [ $table, $schema ] |
|
| 381 | + [$table, $schema] |
|
| 382 | 382 | )) |
| 383 | - ->mapKey(function ($v): string { |
|
| 383 | + ->mapKey(function($v): string { |
|
| 384 | 384 | return $v['column_name']; |
| 385 | 385 | }) |
| 386 | - ->map(function ($v) { |
|
| 386 | + ->map(function($v) { |
|
| 387 | 387 | $v['length'] = null; |
| 388 | 388 | return $v; |
| 389 | 389 | }) |
| 390 | 390 | ->toArray(); |
| 391 | 391 | if (!count($columns)) { |
| 392 | - throw new DBException('View not found by name: ' . implode('.', [$schema,$table])); |
|
| 392 | + throw new DBException('View not found by name: '.implode('.', [$schema, $table])); |
|
| 393 | 393 | } |
| 394 | - $tables[$schema . '.' .$table] = $definition = (new Table($table, $schema)) |
|
| 394 | + $tables[$schema.'.'.$table] = $definition = (new Table($table, $schema)) |
|
| 395 | 395 | ->addColumns($columns) |
| 396 | 396 | ->setComment(''); |
| 397 | 397 | return $definition; |
@@ -401,13 +401,13 @@ discard block |
||
| 401 | 401 | $tables = Collection::from($this |
| 402 | 402 | ->query( |
| 403 | 403 | "SELECT table_name FROM information_schema.tables where table_schema = ? AND table_catalog = ?", |
| 404 | - [ $this->connection['opts']['schema'] ?? 'public', $this->connection['name'] ] |
|
| 404 | + [$this->connection['opts']['schema'] ?? 'public', $this->connection['name']] |
|
| 405 | 405 | )) |
| 406 | - ->mapKey(function ($v) { |
|
| 406 | + ->mapKey(function($v) { |
|
| 407 | 407 | return strtolower($v['table_name']); |
| 408 | 408 | }) |
| 409 | 409 | ->pluck('table_name') |
| 410 | - ->map(function ($v) { |
|
| 410 | + ->map(function($v) { |
|
| 411 | 411 | return $this->table($v)->toLowerCase(); |
| 412 | 412 | }) |
| 413 | 413 | ->toArray(); |
@@ -418,19 +418,19 @@ discard block |
||
| 418 | 418 | FROM pg_catalog.pg_class cls |
| 419 | 419 | join pg_catalog.pg_namespace as ns on ns.oid = cls.relnamespace |
| 420 | 420 | WHERE cls.relkind = 'm' and ns.nspname = ?", |
| 421 | - [ $this->connection['opts']['schema'] ?? 'public' ] |
|
| 421 | + [$this->connection['opts']['schema'] ?? 'public'] |
|
| 422 | 422 | )) |
| 423 | - ->mapKey(function ($v) { |
|
| 423 | + ->mapKey(function($v) { |
|
| 424 | 424 | return strtolower($v['table_name']); |
| 425 | 425 | }) |
| 426 | 426 | ->pluck('table_name') |
| 427 | - ->map(function ($v) { |
|
| 427 | + ->map(function($v) { |
|
| 428 | 428 | return $this->view($v)->toLowerCase(); |
| 429 | 429 | }) |
| 430 | 430 | ->toArray(); |
| 431 | 431 | $tables = array_merge($views, $tables); |
| 432 | 432 | foreach (array_keys($tables) as $k) { |
| 433 | - $tables[($this->connection['opts']['schema'] ?? 'public') . '.' . $k] = &$tables[$k]; |
|
| 433 | + $tables[($this->connection['opts']['schema'] ?? 'public').'.'.$k] = &$tables[$k]; |
|
| 434 | 434 | } |
| 435 | 435 | return $tables; |
| 436 | 436 | } |
@@ -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 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | } |
| 52 | 52 | public function affected() : int |
| 53 | 53 | { |
| 54 | - return (int)$this->statement->affected_rows; |
|
| 54 | + return (int) $this->statement->affected_rows; |
|
| 55 | 55 | } |
| 56 | 56 | public function insertID(?string $sequence = null): mixed |
| 57 | 57 | { |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | } |
| 74 | 74 | public function current(): mixed |
| 75 | 75 | { |
| 76 | - return $this->nativeDriver ? $this->last : array_map(function ($v) { |
|
| 76 | + return $this->nativeDriver ? $this->last : array_map(function($v) { |
|
| 77 | 77 | return $v; |
| 78 | 78 | }, $this->row); |
| 79 | 79 | } |
@@ -92,8 +92,8 @@ discard block |
||
| 92 | 92 | } |
| 93 | 93 | public function next(): void |
| 94 | 94 | { |
| 95 | - $this->fetched ++; |
|
| 96 | - $this->last = $this->nativeDriver ? ($this->result->fetch_assoc()?:null) : $this->statement->fetch(); |
|
| 95 | + $this->fetched++; |
|
| 96 | + $this->last = $this->nativeDriver ? ($this->result->fetch_assoc() ?: null) : $this->statement->fetch(); |
|
| 97 | 97 | } |
| 98 | 98 | public function valid(): bool |
| 99 | 99 | { |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | } |
| 25 | 25 | public function affected() : int |
| 26 | 26 | { |
| 27 | - return (int)\oci_num_rows($this->statement); |
|
| 27 | + return (int) \oci_num_rows($this->statement); |
|
| 28 | 28 | } |
| 29 | 29 | public function insertID(?string $sequence = null): mixed |
| 30 | 30 | { |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | public function count(): int |
| 39 | 39 | { |
| 40 | - return (int)\oci_num_rows($this->statement); |
|
| 40 | + return (int) \oci_num_rows($this->statement); |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | public function key(): mixed |
@@ -65,8 +65,8 @@ discard block |
||
| 65 | 65 | } |
| 66 | 66 | public function next(): void |
| 67 | 67 | { |
| 68 | - $this->fetched ++; |
|
| 69 | - $this->last = \oci_fetch_array($this->statement, \OCI_ASSOC + \OCI_RETURN_NULLS + \OCI_RETURN_LOBS)?:null; |
|
| 68 | + $this->fetched++; |
|
| 69 | + $this->last = \oci_fetch_array($this->statement, \OCI_ASSOC +\OCI_RETURN_NULLS +\OCI_RETURN_LOBS) ?: null; |
|
| 70 | 70 | if (is_array($this->last)) { |
| 71 | 71 | $this->cast(); |
| 72 | 72 | } |
@@ -78,23 +78,23 @@ discard block |
||
| 78 | 78 | protected function cast(): void |
| 79 | 79 | { |
| 80 | 80 | if (!count($this->types)) { |
| 81 | - foreach (array_keys($this->last??[]) as $k => $v) { |
|
| 81 | + foreach (array_keys($this->last ?? []) as $k => $v) { |
|
| 82 | 82 | $this->types[$v] = \oci_field_type($this->statement, $k + 1); |
| 83 | 83 | if ($this->types[$v] === 'NUMBER') { |
| 84 | 84 | $scale = \oci_field_scale($this->statement, $k + 1); |
| 85 | 85 | $precision = \oci_field_precision($this->statement, $k + 1); |
| 86 | 86 | // true float |
| 87 | - if ((int)$scale === -127 && (int)$precision !== 0) { |
|
| 87 | + if ((int) $scale === -127 && (int) $precision !== 0) { |
|
| 88 | 88 | $this->types[$v] = 'FLOAT'; |
| 89 | 89 | } |
| 90 | 90 | // TODO: decimal |
| 91 | - if ((int)$scale > 0) { |
|
| 91 | + if ((int) $scale > 0) { |
|
| 92 | 92 | $this->types[$v] = 'DECIMAL'; |
| 93 | 93 | } |
| 94 | 94 | } |
| 95 | 95 | } |
| 96 | 96 | } |
| 97 | - foreach ($this->last??[] as $k => $v) { |
|
| 97 | + foreach ($this->last ?? [] as $k => $v) { |
|
| 98 | 98 | if (!isset($this->types[$k])) { |
| 99 | 99 | continue; |
| 100 | 100 | } |
@@ -109,10 +109,10 @@ discard block |
||
| 109 | 109 | } |
| 110 | 110 | switch ($this->types[$k]) { |
| 111 | 111 | case 'NUMBER': |
| 112 | - $this->last[$k] = (int)$v; |
|
| 112 | + $this->last[$k] = (int) $v; |
|
| 113 | 113 | break; |
| 114 | 114 | case 'FLOAT': |
| 115 | - $this->last[$k] = (float)$v; |
|
| 115 | + $this->last[$k] = (float) $v; |
|
| 116 | 116 | break; |
| 117 | 117 | } |
| 118 | 118 | } |
@@ -84,10 +84,10 @@ discard block |
||
| 84 | 84 | * @param array|string $column either a single column name or an array of column names |
| 85 | 85 | * @return static |
| 86 | 86 | */ |
| 87 | - public function setPrimaryKey(array|string $column): static |
|
| 87 | + public function setPrimaryKey(array | string $column): static |
|
| 88 | 88 | { |
| 89 | 89 | if (!is_array($column)) { |
| 90 | - $column = [ $column ]; |
|
| 90 | + $column = [$column]; |
|
| 91 | 91 | } |
| 92 | 92 | $this->data['primary'] = array_values($column); |
| 93 | 93 | return $this; |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | */ |
| 115 | 115 | public function getFullName(): string |
| 116 | 116 | { |
| 117 | - return ($this->data['schema'] ? $this->data['schema'] . '.' : '') . $this->data['name']; |
|
| 117 | + return ($this->data['schema'] ? $this->data['schema'].'.' : '').$this->data['name']; |
|
| 118 | 118 | } |
| 119 | 119 | /** |
| 120 | 120 | * Get a column definition |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | public function hasOne( |
| 172 | 172 | Table $toTable, |
| 173 | 173 | ?string $name = null, |
| 174 | - string|array|null $toTableColumn = null, |
|
| 174 | + string | array | null $toTableColumn = null, |
|
| 175 | 175 | ?string $sql = null, |
| 176 | 176 | array $par = [] |
| 177 | 177 | ) : static { |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | if (!isset($name)) { |
| 202 | - $name = $toTable->getName() . '_' . implode('_', array_keys($keymap)); |
|
| 202 | + $name = $toTable->getName().'_'.implode('_', array_keys($keymap)); |
|
| 203 | 203 | } |
| 204 | 204 | $this->addRelation(new TableRelation( |
| 205 | 205 | $this, |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | public function hasMany( |
| 227 | 227 | Table $toTable, |
| 228 | 228 | ?string $name = null, |
| 229 | - string|array|null $toTableColumn = null, |
|
| 229 | + string | array | null $toTableColumn = null, |
|
| 230 | 230 | ?string $sql = null, |
| 231 | 231 | array $par = [] |
| 232 | 232 | ): static { |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | public function belongsTo( |
| 282 | 282 | Table $toTable, |
| 283 | 283 | ?string $name = null, |
| 284 | - string|array|null $localColumn = null, |
|
| 284 | + string | array | null $localColumn = null, |
|
| 285 | 285 | ?string $sql = null, |
| 286 | 286 | array $par = [] |
| 287 | 287 | ): static { |
@@ -337,8 +337,8 @@ discard block |
||
| 337 | 337 | Table $toTable, |
| 338 | 338 | Table $pivot, |
| 339 | 339 | ?string $name = null, |
| 340 | - string|array|null $toTableColumn = null, |
|
| 341 | - string|array|null $localColumn = null |
|
| 340 | + string | array | null $toTableColumn = null, |
|
| 341 | + string | array | null $localColumn = null |
|
| 342 | 342 | ): static { |
| 343 | 343 | $pivotColumns = $pivot->getColumns(); |
| 344 | 344 | |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | public function __construct( |
| 21 | 21 | DBInterface $db, |
| 22 | - Table|string $table, |
|
| 22 | + Table | string $table, |
|
| 23 | 23 | bool $findRelations = false, |
| 24 | 24 | ?MapperInterface $mapper = null |
| 25 | 25 | ) { |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | public function iterator(?array $fields = null, ?array $collectionKey = null): Collection |
| 35 | 35 | { |
| 36 | 36 | return Collection::from(parent::iterator($fields, $collectionKey)) |
| 37 | - ->map(function ($v) { |
|
| 37 | + ->map(function($v) { |
|
| 38 | 38 | return $this->mapper->entity($v); |
| 39 | 39 | }) |
| 40 | 40 | ->values(); |
@@ -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 | } |
@@ -502,11 +501,10 @@ discard block |
||
| 502 | 501 | ): TableQueryMapped { |
| 503 | 502 | return new TableQueryMapped($this, $this->definition($table), $findRelations, $mapper); |
| 504 | 503 | } |
| 505 | - public function __call(string $method, array $args): TableQuery|TableQueryMapped |
|
| 504 | + public function __call(string $method, array $args): TableQuery | TableQueryMapped |
|
| 506 | 505 | { |
| 507 | 506 | return ($args[0] ?? false) ? |
| 508 | - $this->tableMapped($method, $args[1] ?? false, $args[2] ?? null) : |
|
| 509 | - $this->table($method, $args[1] ?? false); |
|
| 507 | + $this->tableMapped($method, $args[1] ?? false, $args[2] ?? null) : $this->table($method, $args[1] ?? false); |
|
| 510 | 508 | } |
| 511 | 509 | public function findRelation(string $start, string $end): array |
| 512 | 510 | { |
@@ -542,12 +540,12 @@ discard block |
||
| 542 | 540 | $relations[$t] = $w; |
| 543 | 541 | } |
| 544 | 542 | if (!isset($schema[$name])) { |
| 545 | - $schema[$name] = [ 'edges' => [] ]; |
|
| 543 | + $schema[$name] = ['edges' => []]; |
|
| 546 | 544 | } |
| 547 | 545 | foreach ($relations as $t => $w) { |
| 548 | 546 | $schema[$name]['edges'][$t] = $w; |
| 549 | 547 | if (!isset($schema[$t])) { |
| 550 | - $schema[$t] = [ 'edges' => [] ]; |
|
| 548 | + $schema[$t] = ['edges' => []]; |
|
| 551 | 549 | } |
| 552 | 550 | $schema[$t]['edges'][$name] = $w; |
| 553 | 551 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | if (isset($this->map)) { |
| 27 | 27 | $par = []; |
| 28 | 28 | foreach ($this->map as $key) { |
| 29 | - $par[] = $data[$key] ?? throw new DBException('Missing param ' . $key); |
|
| 29 | + $par[] = $data[$key] ?? throw new DBException('Missing param '.$key); |
|
| 30 | 30 | } |
| 31 | 31 | $data = $par; |
| 32 | 32 | } |
@@ -34,28 +34,28 @@ discard block |
||
| 34 | 34 | foreach ($data as $i => $v) { |
| 35 | 35 | switch (gettype($v)) { |
| 36 | 36 | case 'boolean': |
| 37 | - $this->statement->bindValue($i+1, $v, \PDO::PARAM_BOOL); |
|
| 37 | + $this->statement->bindValue($i + 1, $v, \PDO::PARAM_BOOL); |
|
| 38 | 38 | break; |
| 39 | 39 | case 'integer': |
| 40 | - $this->statement->bindValue($i+1, $v, \PDO::PARAM_INT); |
|
| 40 | + $this->statement->bindValue($i + 1, $v, \PDO::PARAM_INT); |
|
| 41 | 41 | break; |
| 42 | 42 | case 'NULL': |
| 43 | - $this->statement->bindValue($i+1, $v, \PDO::PARAM_NULL); |
|
| 43 | + $this->statement->bindValue($i + 1, $v, \PDO::PARAM_NULL); |
|
| 44 | 44 | break; |
| 45 | 45 | case 'double': |
| 46 | - $this->statement->bindValue($i+1, $v); |
|
| 46 | + $this->statement->bindValue($i + 1, $v); |
|
| 47 | 47 | break; |
| 48 | 48 | default: |
| 49 | 49 | // keep in mind oracle needs a transaction when inserting LOBs, aside from the specific syntax: |
| 50 | 50 | // INSERT INTO table (column, lobcolumn) VALUES (?, ?, EMPTY_BLOB()) RETURNING lobcolumn INTO ? |
| 51 | 51 | if (is_resource($v) && get_resource_type($v) === 'stream') { |
| 52 | - $this->statement->bindParam($i+1, $v, \PDO::PARAM_LOB); |
|
| 52 | + $this->statement->bindParam($i + 1, $v, \PDO::PARAM_LOB); |
|
| 53 | 53 | break; |
| 54 | 54 | } |
| 55 | 55 | if (!is_string($data[$i])) { |
| 56 | 56 | $data[$i] = serialize($data[$i]); |
| 57 | 57 | } |
| 58 | - $this->statement->bindValue($i+1, $v); |
|
| 58 | + $this->statement->bindValue($i + 1, $v); |
|
| 59 | 59 | break; |
| 60 | 60 | } |
| 61 | 61 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | if (isset($this->map)) { |
| 29 | 29 | $par = []; |
| 30 | 30 | foreach ($this->map as $key) { |
| 31 | - $par[] = $data[$key] ?? throw new DBException('Missing param ' . $key); |
|
| 31 | + $par[] = $data[$key] ?? throw new DBException('Missing param '.$key); |
|
| 32 | 32 | } |
| 33 | 33 | $data = $par; |
| 34 | 34 | } |
@@ -49,23 +49,23 @@ discard block |
||
| 49 | 49 | break; |
| 50 | 50 | case 'array': |
| 51 | 51 | $par = implode(',', $par); |
| 52 | - $par = "'" . $this->lnk->escape_string($par) . "'"; |
|
| 52 | + $par = "'".$this->lnk->escape_string($par)."'"; |
|
| 53 | 53 | break; |
| 54 | 54 | case 'object': |
| 55 | 55 | $par = serialize($par); |
| 56 | - $par = "'" . $this->lnk->escape_string($par) . "'"; |
|
| 56 | + $par = "'".$this->lnk->escape_string($par)."'"; |
|
| 57 | 57 | break; |
| 58 | 58 | case 'resource': |
| 59 | 59 | if (is_resource($par) && get_resource_type($par) === 'stream') { |
| 60 | 60 | $par = stream_get_contents($par); |
| 61 | - $par = "'" . $this->lnk->escape_string($par) . "'"; |
|
| 61 | + $par = "'".$this->lnk->escape_string($par)."'"; |
|
| 62 | 62 | } else { |
| 63 | 63 | $par = serialize($par); |
| 64 | - $par = "'" . $this->lnk->escape_string($par) . "'"; |
|
| 64 | + $par = "'".$this->lnk->escape_string($par)."'"; |
|
| 65 | 65 | } |
| 66 | 66 | break; |
| 67 | 67 | default: |
| 68 | - $par = "'" . $this->lnk->escape_string((string)$par) . "'"; |
|
| 68 | + $par = "'".$this->lnk->escape_string((string) $par)."'"; |
|
| 69 | 69 | break; |
| 70 | 70 | } |
| 71 | 71 | $sql .= $par; |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | if (isset($this->map)) { |
| 32 | 32 | $par = []; |
| 33 | 33 | foreach ($this->map as $key) { |
| 34 | - $par[] = $data[$key] ?? throw new DBException('Missing param ' . $key); |
|
| 34 | + $par[] = $data[$key] ?? throw new DBException('Missing param '.$key); |
|
| 35 | 35 | } |
| 36 | 36 | $data = $par; |
| 37 | 37 | } |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | foreach ($lng as $index) { |
| 87 | 87 | if (is_resource($data[$index]) && get_resource_type($data[$index]) === 'stream') { |
| 88 | 88 | while (!feof($data[$index])) { |
| 89 | - $this->statement->send_long_data($index, (string)fread($data[$index], $lds)); |
|
| 89 | + $this->statement->send_long_data($index, (string) fread($data[$index], $lds)); |
|
| 90 | 90 | } |
| 91 | 91 | } else { |
| 92 | 92 | $data[$index] = str_split($data[$index], $lds); |
@@ -106,24 +106,24 @@ discard block |
||
| 106 | 106 | $res = false; |
| 107 | 107 | } |
| 108 | 108 | if (!$res) { |
| 109 | - if ($log && (int)$this->driver->option('log_errors', 1)) { |
|
| 109 | + if ($log && (int) $this->driver->option('log_errors', 1)) { |
|
| 110 | 110 | @file_put_contents( |
| 111 | 111 | $log, |
| 112 | - '--' . date('Y-m-d H:i:s') . ' ERROR: ' . $this->statement->error . "\r\n" . |
|
| 113 | - $this->sql . "\r\n" . |
|
| 112 | + '--'.date('Y-m-d H:i:s').' ERROR: '.$this->statement->error."\r\n". |
|
| 113 | + $this->sql."\r\n". |
|
| 114 | 114 | "\r\n", |
| 115 | 115 | FILE_APPEND |
| 116 | 116 | ); |
| 117 | 117 | } |
| 118 | - throw new DBException('Prepared execute error: ' . $this->statement->error); |
|
| 118 | + throw new DBException('Prepared execute error: '.$this->statement->error); |
|
| 119 | 119 | } |
| 120 | 120 | if ($log) { |
| 121 | 121 | $tm = microtime(true) - $tm; |
| 122 | - if ($tm >= (float)$this->driver->option('log_slow', 0)) { |
|
| 122 | + if ($tm >= (float) $this->driver->option('log_slow', 0)) { |
|
| 123 | 123 | @file_put_contents( |
| 124 | 124 | $log, |
| 125 | - '--' . date('Y-m-d H:i:s') . ' ' . sprintf('%01.6f', $tm) . "s\r\n" . |
|
| 126 | - $this->sql . "\r\n" . |
|
| 125 | + '--'.date('Y-m-d H:i:s').' '.sprintf('%01.6f', $tm)."s\r\n". |
|
| 126 | + $this->sql."\r\n". |
|
| 127 | 127 | "\r\n", |
| 128 | 128 | FILE_APPEND |
| 129 | 129 | ); |