@@ -36,7 +36,7 @@ |
||
| 36 | 36 | if (isset($this->map)) { |
| 37 | 37 | $par = []; |
| 38 | 38 | foreach ($this->map as $key) { |
| 39 | - $par[] = $data[$key] ?? throw new DBException('Missing param ' . $key); |
|
| 39 | + $par[] = $data[$key] ?? throw new DBException('Missing param '.$key); |
|
| 40 | 40 | } |
| 41 | 41 | $data = $par; |
| 42 | 42 | } |
@@ -36,7 +36,7 @@ |
||
| 36 | 36 | if (isset($this->map)) { |
| 37 | 37 | $par = []; |
| 38 | 38 | foreach ($this->map as $key) { |
| 39 | - $par[] = $data[$key] ?? throw new DBException('Missing param ' . $key); |
|
| 39 | + $par[] = $data[$key] ?? throw new DBException('Missing param '.$key); |
|
| 40 | 40 | } |
| 41 | 41 | $data = $par; |
| 42 | 42 | } |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | * @param class-string<T>|Table|string $table |
| 119 | 119 | * @return ($table is class-string ? MapperInterface<T> : MapperInterface<Entity>) |
| 120 | 120 | */ |
| 121 | - public function getMapper(Table|string $table): MapperInterface; |
|
| 121 | + public function getMapper(Table | string $table): MapperInterface; |
|
| 122 | 122 | /* |
| 123 | 123 | * @template T of Entity |
| 124 | 124 | * @param Table|string $table |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | * @param null|class-string<T> $class |
| 127 | 127 | * @return static |
| 128 | 128 | */ |
| 129 | - public function setMapper(Table|string $table, MapperInterface $mapper, ?string $class = null): static; |
|
| 129 | + public function setMapper(Table | string $table, MapperInterface $mapper, ?string $class = null): static; |
|
| 130 | 130 | public function clearMappers(): static; |
| 131 | 131 | public function tableMapped( |
| 132 | 132 | string $table, |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | } |
| 97 | 97 | $this->cached[$method] = $rslt; |
| 98 | 98 | } else { |
| 99 | - throw new DBException('Invalid relation name: ' . $method); |
|
| 99 | + throw new DBException('Invalid relation name: '.$method); |
|
| 100 | 100 | } |
| 101 | 101 | return $this->cached[$method] ?? null; |
| 102 | 102 | } |
@@ -107,14 +107,14 @@ discard block |
||
| 107 | 107 | protected function relatedQuery(string $name): TableQueryMapped |
| 108 | 108 | { |
| 109 | 109 | if (!array_key_exists($name, $this->relations)) { |
| 110 | - throw new DBException('Invalid relation name: ' . $name); |
|
| 110 | + throw new DBException('Invalid relation name: '.$name); |
|
| 111 | 111 | } |
| 112 | 112 | return call_user_func_array($this->relations[$name], [$this, true]); |
| 113 | 113 | } |
| 114 | 114 | protected function relatedRow(string $name): mixed |
| 115 | 115 | { |
| 116 | 116 | if (!array_key_exists($name, $this->relations)) { |
| 117 | - throw new DBException('Invalid relation name: ' . $name); |
|
| 117 | + throw new DBException('Invalid relation name: '.$name); |
|
| 118 | 118 | } |
| 119 | 119 | return call_user_func_array($this->relations[$name], [$this]); |
| 120 | 120 | } |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | protected function relatedRows(string $name): Collection |
| 126 | 126 | { |
| 127 | 127 | if (!array_key_exists($name, $this->relations)) { |
| 128 | - throw new DBException('Invalid relation name: ' . $name); |
|
| 128 | + throw new DBException('Invalid relation name: '.$name); |
|
| 129 | 129 | } |
| 130 | 130 | return call_user_func_array($this->relations[$name], [$this]); |
| 131 | 131 | } |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | $temp = $this->data; |
| 135 | 135 | foreach ($this->relations as $name => $relation) { |
| 136 | 136 | try { |
| 137 | - $temp[$name] = call_user_func_array($relation, [ $this, false, true ]); |
|
| 137 | + $temp[$name] = call_user_func_array($relation, [$this, false, true]); |
|
| 138 | 138 | } catch (DBException $ignore) {} |
| 139 | 139 | } |
| 140 | 140 | return $temp; |
@@ -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; |
@@ -53,8 +53,8 @@ discard block |
||
| 53 | 53 | ] |
| 54 | 54 | ) |
| 55 | 55 | ); |
| 56 | - $relationsT['main.' . $row['table']][] = $row; |
|
| 57 | - $relationsR['main.' . $row['referenced_table']][] = $row; |
|
| 56 | + $relationsT['main.'.$row['table']][] = $row; |
|
| 57 | + $relationsR['main.'.$row['referenced_table']][] = $row; |
|
| 58 | 58 | } |
| 59 | 59 | } |
| 60 | 60 | } |
@@ -64,10 +64,10 @@ discard block |
||
| 64 | 64 | */ |
| 65 | 65 | $columns = Collection::from($this |
| 66 | 66 | ->query("PRAGMA table_info(".$table.")")) |
| 67 | - ->mapKey(function ($v): string { |
|
| 67 | + ->mapKey(function($v): string { |
|
| 68 | 68 | return $v['name']; |
| 69 | 69 | }) |
| 70 | - ->map(function ($v) { |
|
| 70 | + ->map(function($v) { |
|
| 71 | 71 | $v['length'] = null; |
| 72 | 72 | if (!isset($v['type'])) { |
| 73 | 73 | return $v; |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | default: |
| 78 | 78 | if (strpos($type, 'char') !== false && strpos($type, '(') !== false) { |
| 79 | 79 | // extract length from varchar |
| 80 | - $v['length'] = (int)explode(')', explode('(', $type)[1])[0]; |
|
| 80 | + $v['length'] = (int) explode(')', explode('(', $type)[1])[0]; |
|
| 81 | 81 | $v['length'] = $v['length'] > 0 ? $v['length'] : null; |
| 82 | 82 | } |
| 83 | 83 | break; |
@@ -86,35 +86,35 @@ discard block |
||
| 86 | 86 | }) |
| 87 | 87 | ->toArray(); |
| 88 | 88 | if (!count($columns)) { |
| 89 | - throw new DBException('Table not found by name: ' . implode('.', [$schema,$table])); |
|
| 89 | + throw new DBException('Table not found by name: '.implode('.', [$schema, $table])); |
|
| 90 | 90 | } |
| 91 | 91 | $primary = []; |
| 92 | 92 | foreach ($columns as $column) { |
| 93 | - if ((int)$column['pk']) { |
|
| 93 | + if ((int) $column['pk']) { |
|
| 94 | 94 | $primary[] = $column['name']; |
| 95 | 95 | } |
| 96 | 96 | } |
| 97 | - $tables[$schema . '.' .$table] = $definition = (new Table($table, $schema)) |
|
| 97 | + $tables[$schema.'.'.$table] = $definition = (new Table($table, $schema)) |
|
| 98 | 98 | ->addColumns($columns) |
| 99 | 99 | ->setPrimaryKey($primary) |
| 100 | 100 | ->setComment(''); |
| 101 | 101 | |
| 102 | 102 | if ($detectRelations) { |
| 103 | 103 | $duplicated = []; |
| 104 | - foreach ($relationsT[$schema . '.' . $table] ?? [] as $relation) { |
|
| 105 | - $t = 'main.' . $relation['referenced_table']; |
|
| 104 | + foreach ($relationsT[$schema.'.'.$table] ?? [] as $relation) { |
|
| 105 | + $t = 'main.'.$relation['referenced_table']; |
|
| 106 | 106 | $duplicated[$t] = isset($duplicated[$t]); |
| 107 | 107 | } |
| 108 | - foreach ($relationsR[$schema . '.' . $table] ?? [] as $relation) { |
|
| 109 | - $t = 'main.' . $relation['table']; |
|
| 108 | + foreach ($relationsR[$schema.'.'.$table] ?? [] as $relation) { |
|
| 109 | + $t = 'main.'.$relation['table']; |
|
| 110 | 110 | $duplicated[$t] = isset($duplicated[$t]); |
| 111 | 111 | } |
| 112 | 112 | // pivot relations where the current table is referenced |
| 113 | 113 | // assuming current table is on the "one" end having "many" records in the referencing table |
| 114 | 114 | // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected) |
| 115 | 115 | $relations = []; |
| 116 | - foreach ($relationsR[$schema . '.' . $table] ?? [] as $k => $relation) { |
|
| 117 | - $relations[$relation['constraint_name']]['table'] = 'main.' . $relation['table']; |
|
| 116 | + foreach ($relationsR[$schema.'.'.$table] ?? [] as $k => $relation) { |
|
| 117 | + $relations[$relation['constraint_name']]['table'] = 'main.'.$relation['table']; |
|
| 118 | 118 | $relations[$relation['constraint_name']]['keymap'][$relation['to']] = $relation['from']; |
| 119 | 119 | } |
| 120 | 120 | ksort($relations); |
@@ -130,11 +130,11 @@ discard block |
||
| 130 | 130 | $usedcol = []; |
| 131 | 131 | if (count($columns)) { |
| 132 | 132 | foreach (Collection::from($relationsT[$data['table']] ?? []) |
| 133 | - ->filter(function ($v) use ($columns) { |
|
| 133 | + ->filter(function($v) use ($columns) { |
|
| 134 | 134 | return in_array($v['from'], $columns); |
| 135 | 135 | }) as $relation |
| 136 | 136 | ) { |
| 137 | - $foreign[$relation['constraint_name']]['table'] = 'main.' . |
|
| 137 | + $foreign[$relation['constraint_name']]['table'] = 'main.'. |
|
| 138 | 138 | $relation['referenced_table']; |
| 139 | 139 | $foreign[$relation['constraint_name']]['keymap'][$relation['from']] = $relation['to']; |
| 140 | 140 | $usedcol[] = $relation['from']; |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | $definition->getName() == $relname || |
| 154 | 154 | $definition->getColumn($relname) |
| 155 | 155 | ) { |
| 156 | - $relname = $orig . '_' . (++ $cntr); |
|
| 156 | + $relname = $orig.'_'.(++$cntr); |
|
| 157 | 157 | } |
| 158 | 158 | $definition->addRelation( |
| 159 | 159 | new TableRelation( |
@@ -175,8 +175,8 @@ discard block |
||
| 175 | 175 | // assuming current table is linked to "one" record in the referenced table |
| 176 | 176 | // resulting in a "belongsTo" relationship |
| 177 | 177 | $relations = []; |
| 178 | - foreach ($relationsT[$schema . '.' . $table] ?? [] as $relation) { |
|
| 179 | - $relations[$relation['constraint_name']]['table'] = 'main.' . $relation['referenced_table']; |
|
| 178 | + foreach ($relationsT[$schema.'.'.$table] ?? [] as $relation) { |
|
| 179 | + $relations[$relation['constraint_name']]['table'] = 'main.'.$relation['referenced_table']; |
|
| 180 | 180 | $relations[$relation['constraint_name']]['keymap'][$relation['from']] = $relation['to']; |
| 181 | 181 | } |
| 182 | 182 | ksort($relations); |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | $definition->getName() == $relname || |
| 192 | 192 | $definition->getColumn($relname) |
| 193 | 193 | ) { |
| 194 | - $relname = array_keys($data['keymap'])[0] . '_' . $relname; |
|
| 194 | + $relname = array_keys($data['keymap'])[0].'_'.$relname; |
|
| 195 | 195 | } |
| 196 | 196 | $orig = $relname; |
| 197 | 197 | $cntr = 1; |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | $definition->getName() == $relname || |
| 200 | 200 | $definition->getColumn($relname) |
| 201 | 201 | ) { |
| 202 | - $relname = $orig . '_' . (++ $cntr); |
|
| 202 | + $relname = $orig.'_'.(++$cntr); |
|
| 203 | 203 | } |
| 204 | 204 | $definition->addRelation( |
| 205 | 205 | new TableRelation( |
@@ -215,8 +215,8 @@ discard block |
||
| 215 | 215 | // assuming current table is on the "one" end having "many" records in the referencing table |
| 216 | 216 | // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected) |
| 217 | 217 | $relations = []; |
| 218 | - foreach ($relationsR[$schema . '.' . $table] ?? [] as $k => $relation) { |
|
| 219 | - $relations[$relation['constraint_name']]['table'] = 'main.' . $relation['table']; |
|
| 218 | + foreach ($relationsR[$schema.'.'.$table] ?? [] as $k => $relation) { |
|
| 219 | + $relations[$relation['constraint_name']]['table'] = 'main.'.$relation['table']; |
|
| 220 | 220 | $relations[$relation['constraint_name']]['keymap'][$relation['to']] = $relation['from']; |
| 221 | 221 | } |
| 222 | 222 | ksort($relations); |
@@ -232,11 +232,11 @@ discard block |
||
| 232 | 232 | $usedcol = []; |
| 233 | 233 | if (count($columns)) { |
| 234 | 234 | foreach (Collection::from($relationsT[$data['table']] ?? []) |
| 235 | - ->filter(function ($v) use ($columns) { |
|
| 235 | + ->filter(function($v) use ($columns) { |
|
| 236 | 236 | return in_array($v['from'], $columns); |
| 237 | 237 | }) as $relation |
| 238 | 238 | ) { |
| 239 | - $foreign[$relation['constraint_name']]['table'] = 'main.' . |
|
| 239 | + $foreign[$relation['constraint_name']]['table'] = 'main.'. |
|
| 240 | 240 | $relation['referenced_table']; |
| 241 | 241 | $foreign[$relation['constraint_name']]['keymap'][$relation['from']] = $relation['to']; |
| 242 | 242 | $usedcol[] = $relation['from']; |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | $definition->getName() == $relname || |
| 254 | 254 | $definition->getColumn($relname) |
| 255 | 255 | ) { |
| 256 | - $relname .= '_' . array_values($data['keymap'])[0]; |
|
| 256 | + $relname .= '_'.array_values($data['keymap'])[0]; |
|
| 257 | 257 | } |
| 258 | 258 | $orig = $relname; |
| 259 | 259 | $cntr = 1; |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | $definition->getName() == $relname || |
| 262 | 262 | $definition->getColumn($relname) |
| 263 | 263 | ) { |
| 264 | - $relname = $orig . '_' . (++ $cntr); |
|
| 264 | + $relname = $orig.'_'.(++$cntr); |
|
| 265 | 265 | } |
| 266 | 266 | $definition->addRelation( |
| 267 | 267 | new TableRelation( |
@@ -289,9 +289,9 @@ discard block |
||
| 289 | 289 | "SELECT tbl_name |
| 290 | 290 | FROM sqlite_schema |
| 291 | 291 | WHERE (type = ? OR type = ?) AND tbl_name NOT LIKE 'sqlite_%';", |
| 292 | - [ 'table', 'view' ] |
|
| 292 | + ['table', 'view'] |
|
| 293 | 293 | )) |
| 294 | - ->mapKey(function ($v) { |
|
| 294 | + ->mapKey(function($v) { |
|
| 295 | 295 | return strtolower($v['tbl_name']); |
| 296 | 296 | }) |
| 297 | 297 | ->pluck('tbl_name') |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | $tables[$k] = $this->table($v, true, array_keys($tables))->toLowerCase(); |
| 301 | 301 | } |
| 302 | 302 | foreach (array_keys($tables) as $k) { |
| 303 | - $tables[($this->connection['opts']['schema'] ?? 'main') . '.' . $k] = &$tables[$k]; |
|
| 303 | + $tables[($this->connection['opts']['schema'] ?? 'main').'.'.$k] = &$tables[$k]; |
|
| 304 | 304 | } |
| 305 | 305 | return $tables; |
| 306 | 306 | } |
@@ -32,19 +32,19 @@ discard block |
||
| 32 | 32 | $columns = Collection::from($this |
| 33 | 33 | ->query( |
| 34 | 34 | "SELECT * FROM user_tab_cols WHERE UPPER(table_name) = ?", |
| 35 | - [ strtoupper($table) ] |
|
| 35 | + [strtoupper($table)] |
|
| 36 | 36 | )) |
| 37 | - ->map(function ($v) { |
|
| 37 | + ->map(function($v) { |
|
| 38 | 38 | $new = []; |
| 39 | 39 | foreach ($v as $kk => $vv) { |
| 40 | 40 | $new[strtoupper($kk)] = $vv; |
| 41 | 41 | } |
| 42 | 42 | return $new; |
| 43 | 43 | }) |
| 44 | - ->mapKey(function ($v): string { |
|
| 44 | + ->mapKey(function($v): string { |
|
| 45 | 45 | return $v['COLUMN_NAME']; |
| 46 | 46 | }) |
| 47 | - ->map(function ($v) { |
|
| 47 | + ->map(function($v) { |
|
| 48 | 48 | $v['length'] = null; |
| 49 | 49 | if (!isset($v['DATA_TYPE'])) { |
| 50 | 50 | return $v; |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | default: |
| 57 | 57 | if (strpos($type, 'char') !== false && strpos($type, '(') !== false) { |
| 58 | 58 | // extract length from varchar |
| 59 | - $v['length'] = (int)explode(')', (explode('(', $type)[1] ?? ''))[0]; |
|
| 59 | + $v['length'] = (int) explode(')', (explode('(', $type)[1] ?? ''))[0]; |
|
| 60 | 60 | $v['length'] = $v['length'] > 0 ? $v['length'] : null; |
| 61 | 61 | } |
| 62 | 62 | break; |
@@ -73,9 +73,9 @@ discard block |
||
| 73 | 73 | ->query( |
| 74 | 74 | "SELECT constraint_name FROM user_constraints |
| 75 | 75 | WHERE table_name = ? AND constraint_type = ?", |
| 76 | - [ strtoupper($table), 'P' ] |
|
| 76 | + [strtoupper($table), 'P'] |
|
| 77 | 77 | )) |
| 78 | - ->map(function ($v) { |
|
| 78 | + ->map(function($v) { |
|
| 79 | 79 | $new = []; |
| 80 | 80 | foreach ($v as $kk => $vv) { |
| 81 | 81 | $new[strtoupper($kk)] = $vv; |
@@ -90,9 +90,9 @@ discard block |
||
| 90 | 90 | ->query( |
| 91 | 91 | "SELECT column_name FROM user_cons_columns |
| 92 | 92 | WHERE table_name = ? AND constraint_name = ?", |
| 93 | - [ strtoupper($table), $pkname ] |
|
| 93 | + [strtoupper($table), $pkname] |
|
| 94 | 94 | )) |
| 95 | - ->map(function ($v) { |
|
| 95 | + ->map(function($v) { |
|
| 96 | 96 | $new = []; |
| 97 | 97 | foreach ($v as $kk => $vv) { |
| 98 | 98 | $new[strtoupper($kk)] = $vv; |
@@ -120,9 +120,9 @@ discard block |
||
| 120 | 120 | LEFT JOIN user_cons_columns cc ON cc.CONSTRAINT_NAME = ac.CONSTRAINT_NAME |
| 121 | 121 | WHERE ac.TABLE_NAME = ? AND ac.CONSTRAINT_TYPE = ? |
| 122 | 122 | ORDER BY cc.POSITION", |
| 123 | - [ strtoupper($table), 'R' ] |
|
| 123 | + [strtoupper($table), 'R'] |
|
| 124 | 124 | )) |
| 125 | - ->map(function ($v) { |
|
| 125 | + ->map(function($v) { |
|
| 126 | 126 | $new = []; |
| 127 | 127 | foreach ($v as $kk => $vv) { |
| 128 | 128 | $new[strtoupper($kk)] = $vv; |
@@ -138,9 +138,9 @@ discard block |
||
| 138 | 138 | WHERE |
| 139 | 139 | ac.R_CONSTRAINT_NAME = ? AND ac.CONSTRAINT_TYPE = ? |
| 140 | 140 | ORDER BY cc.POSITION", |
| 141 | - [ $pkname, 'R' ] |
|
| 141 | + [$pkname, 'R'] |
|
| 142 | 142 | )) |
| 143 | - ->map(function ($v) { |
|
| 143 | + ->map(function($v) { |
|
| 144 | 144 | $new = []; |
| 145 | 145 | foreach ($v as $kk => $vv) { |
| 146 | 146 | $new[strtoupper($kk)] = $vv; |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | $relations = []; |
| 164 | 164 | foreach ($relationsR as $relation) { |
| 165 | 165 | $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_NAME']; |
| 166 | - $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int)$relation['POSITION']-1]] = |
|
| 166 | + $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int) $relation['POSITION'] - 1]] = |
|
| 167 | 167 | $relation['COLUMN_NAME']; |
| 168 | 168 | } |
| 169 | 169 | ksort($relations); |
@@ -194,9 +194,9 @@ discard block |
||
| 194 | 194 | ac.TABLE_NAME = ? AND ac.CONSTRAINT_TYPE = ? AND |
| 195 | 195 | cc.COLUMN_NAME IN (??) |
| 196 | 196 | ORDER BY POSITION", |
| 197 | - [ $data['table'], 'R', $columns ] |
|
| 197 | + [$data['table'], 'R', $columns] |
|
| 198 | 198 | )) |
| 199 | - ->map(function ($v) { |
|
| 199 | + ->map(function($v) { |
|
| 200 | 200 | $new = []; |
| 201 | 201 | foreach ($v as $kk => $vv) { |
| 202 | 202 | $new[strtoupper($kk)] = $vv; |
@@ -216,9 +216,9 @@ discard block |
||
| 216 | 216 | ->query( |
| 217 | 217 | "SELECT COLUMN_NAME FROM user_cons_columns |
| 218 | 218 | WHERE CONSTRAINT_NAME = ? ORDER BY POSITION", |
| 219 | - [ current($foreign['keymap']) ] |
|
| 219 | + [current($foreign['keymap'])] |
|
| 220 | 220 | )) |
| 221 | - ->map(function ($v) { |
|
| 221 | + ->map(function($v) { |
|
| 222 | 222 | $new = []; |
| 223 | 223 | foreach ($v as $kk => $vv) { |
| 224 | 224 | $new[strtoupper($kk)] = $vv; |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | $relname = $foreign['table']; |
| 234 | 234 | $cntr = 1; |
| 235 | 235 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
| 236 | - $relname = $foreign['table'] . '_' . (++ $cntr); |
|
| 236 | + $relname = $foreign['table'].'_'.(++$cntr); |
|
| 237 | 237 | } |
| 238 | 238 | $definition->addRelation( |
| 239 | 239 | new TableRelation( |
@@ -266,9 +266,9 @@ discard block |
||
| 266 | 266 | ->query( |
| 267 | 267 | "SELECT COLUMN_NAME FROM user_cons_columns |
| 268 | 268 | WHERE CONSTRAINT_NAME = ? ORDER BY POSITION", |
| 269 | - [ current($data['keymap']) ] |
|
| 269 | + [current($data['keymap'])] |
|
| 270 | 270 | )) |
| 271 | - ->map(function ($v) { |
|
| 271 | + ->map(function($v) { |
|
| 272 | 272 | $new = []; |
| 273 | 273 | foreach ($v as $kk => $vv) { |
| 274 | 274 | $new[strtoupper($kk)] = $vv; |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | $definition->getName() == $relname || |
| 287 | 287 | $definition->getColumn($relname) |
| 288 | 288 | ) { |
| 289 | - $relname = array_keys($data['keymap'])[0] . '_' . $relname; |
|
| 289 | + $relname = array_keys($data['keymap'])[0].'_'.$relname; |
|
| 290 | 290 | } |
| 291 | 291 | $orig = $relname; |
| 292 | 292 | $cntr = 1; |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | $definition->getName() == $relname || |
| 296 | 296 | $definition->getColumn($relname) |
| 297 | 297 | ) { |
| 298 | - $relname = $orig . '_' . (++ $cntr); |
|
| 298 | + $relname = $orig.'_'.(++$cntr); |
|
| 299 | 299 | } |
| 300 | 300 | $definition->addRelation( |
| 301 | 301 | new TableRelation( |
@@ -313,7 +313,7 @@ discard block |
||
| 313 | 313 | $relations = []; |
| 314 | 314 | foreach ($relationsR as $relation) { |
| 315 | 315 | $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_NAME']; |
| 316 | - $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int)$relation['POSITION']-1]] = |
|
| 316 | + $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int) $relation['POSITION'] - 1]] = |
|
| 317 | 317 | $relation['COLUMN_NAME']; |
| 318 | 318 | } |
| 319 | 319 | ksort($relations); |
@@ -344,9 +344,9 @@ discard block |
||
| 344 | 344 | ac.TABLE_NAME = ? AND ac.CONSTRAINT_TYPE = ? AND |
| 345 | 345 | cc.COLUMN_NAME IN (??) |
| 346 | 346 | ORDER BY POSITION", |
| 347 | - [ $data['table'], 'R', $columns ] |
|
| 347 | + [$data['table'], 'R', $columns] |
|
| 348 | 348 | )) |
| 349 | - ->map(function ($v) { |
|
| 349 | + ->map(function($v) { |
|
| 350 | 350 | $new = []; |
| 351 | 351 | foreach ($v as $kk => $vv) { |
| 352 | 352 | $new[strtoupper($kk)] = $vv; |
@@ -367,7 +367,7 @@ discard block |
||
| 367 | 367 | $definition->getName() == $relname || |
| 368 | 368 | $definition->getColumn($relname) |
| 369 | 369 | ) { |
| 370 | - $relname .= '_' . array_values($data['keymap'])[0]; |
|
| 370 | + $relname .= '_'.array_values($data['keymap'])[0]; |
|
| 371 | 371 | } |
| 372 | 372 | $orig = $relname; |
| 373 | 373 | $cntr = 1; |
@@ -376,7 +376,7 @@ discard block |
||
| 376 | 376 | $definition->getName() == $relname || |
| 377 | 377 | $definition->getColumn($relname) |
| 378 | 378 | ) { |
| 379 | - $relname = $orig . '_' . (++ $cntr); |
|
| 379 | + $relname = $orig.'_'.(++$cntr); |
|
| 380 | 380 | } |
| 381 | 381 | $definition->addRelation( |
| 382 | 382 | new TableRelation( |
@@ -406,18 +406,18 @@ discard block |
||
| 406 | 406 | SELECT VIEW_NAME AS TABLE_NAME FROM USER_VIEWS", |
| 407 | 407 | [] |
| 408 | 408 | )) |
| 409 | - ->map(function ($v) { |
|
| 409 | + ->map(function($v) { |
|
| 410 | 410 | $new = []; |
| 411 | 411 | foreach ($v as $kk => $vv) { |
| 412 | 412 | $new[strtoupper($kk)] = $vv; |
| 413 | 413 | } |
| 414 | 414 | return $new; |
| 415 | 415 | }) |
| 416 | - ->mapKey(function ($v) { |
|
| 416 | + ->mapKey(function($v) { |
|
| 417 | 417 | return strtolower($v['TABLE_NAME']); |
| 418 | 418 | }) |
| 419 | 419 | ->pluck('TABLE_NAME') |
| 420 | - ->map(function ($v) { |
|
| 420 | + ->map(function($v) { |
|
| 421 | 421 | return $this->table($v)->toLowerCase(); |
| 422 | 422 | }) |
| 423 | 423 | ->toArray(); |
@@ -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']; |
@@ -194,11 +194,11 @@ discard block |
||
| 194 | 194 | $usedcol = []; |
| 195 | 195 | if (count($columns)) { |
| 196 | 196 | foreach (Collection::from($relationsT[$data['table']] ?? []) |
| 197 | - ->filter(function ($v) use ($columns) { |
|
| 197 | + ->filter(function($v) use ($columns) { |
|
| 198 | 198 | return in_array($v['column_name'], $columns); |
| 199 | 199 | }) as $relation |
| 200 | 200 | ) { |
| 201 | - $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' . |
|
| 201 | + $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'. |
|
| 202 | 202 | $relation['referenced_table_name']; |
| 203 | 203 | $foreign[$relation['constraint_name']]['keymap'][$relation['column_name']] = |
| 204 | 204 | $relation['referenced_column_name']; |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | $definition->getName() == $relname || |
| 219 | 219 | $definition->getColumn($relname) |
| 220 | 220 | ) { |
| 221 | - $relname = $orig . '_' . (++ $cntr); |
|
| 221 | + $relname = $orig.'_'.(++$cntr); |
|
| 222 | 222 | } |
| 223 | 223 | $definition->addRelation( |
| 224 | 224 | new TableRelation( |
@@ -240,8 +240,8 @@ discard block |
||
| 240 | 240 | // assuming current table is linked to "one" record in the referenced table |
| 241 | 241 | // resulting in a "belongsTo" relationship |
| 242 | 242 | $relations = []; |
| 243 | - foreach ($relationsT[$schema . '.' . $table] ?? [] as $relation) { |
|
| 244 | - $relations[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' . |
|
| 243 | + foreach ($relationsT[$schema.'.'.$table] ?? [] as $relation) { |
|
| 244 | + $relations[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'. |
|
| 245 | 245 | $relation['referenced_table_name']; |
| 246 | 246 | $relations[$relation['constraint_name']]['keymap'][$relation['column_name']] = |
| 247 | 247 | $relation['referenced_column_name']; |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | $definition->getName() == $relname || |
| 259 | 259 | $definition->getColumn($relname) |
| 260 | 260 | ) { |
| 261 | - $relname = array_keys($data['keymap'])[0] . '_' . $relname; |
|
| 261 | + $relname = array_keys($data['keymap'])[0].'_'.$relname; |
|
| 262 | 262 | } |
| 263 | 263 | $orig = $relname; |
| 264 | 264 | $cntr = 1; |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | $definition->getName() == $relname || |
| 267 | 267 | $definition->getColumn($relname) |
| 268 | 268 | ) { |
| 269 | - $relname = $orig . '_' . (++ $cntr); |
|
| 269 | + $relname = $orig.'_'.(++$cntr); |
|
| 270 | 270 | } |
| 271 | 271 | $definition->addRelation( |
| 272 | 272 | new TableRelation( |
@@ -282,8 +282,8 @@ discard block |
||
| 282 | 282 | // assuming current table is on the "one" end having "many" records in the referencing table |
| 283 | 283 | // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected) |
| 284 | 284 | $relations = []; |
| 285 | - foreach ($relationsR[$schema . '.' . $table] ?? [] as $relation) { |
|
| 286 | - $relations[$relation['constraint_name']]['table'] = $relation['table_schema'] . '.' . |
|
| 285 | + foreach ($relationsR[$schema.'.'.$table] ?? [] as $relation) { |
|
| 286 | + $relations[$relation['constraint_name']]['table'] = $relation['table_schema'].'.'. |
|
| 287 | 287 | $relation['table_name']; |
| 288 | 288 | $relations[$relation['constraint_name']]['keymap'][$relation['referenced_column_name']] = |
| 289 | 289 | $relation['column_name']; |
@@ -301,11 +301,11 @@ discard block |
||
| 301 | 301 | $usedcol = []; |
| 302 | 302 | if (count($columns)) { |
| 303 | 303 | foreach (Collection::from($relationsT[$data['table']] ?? []) |
| 304 | - ->filter(function ($v) use ($columns) { |
|
| 304 | + ->filter(function($v) use ($columns) { |
|
| 305 | 305 | return in_array($v['column_name'], $columns); |
| 306 | 306 | }) as $relation |
| 307 | 307 | ) { |
| 308 | - $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' . |
|
| 308 | + $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'. |
|
| 309 | 309 | $relation['referenced_table_name']; |
| 310 | 310 | $foreign[$relation['constraint_name']]['keymap'][$relation['column_name']] = |
| 311 | 311 | $relation['referenced_column_name']; |
@@ -323,7 +323,7 @@ discard block |
||
| 323 | 323 | $definition->getName() == $relname || |
| 324 | 324 | $definition->getColumn($relname) |
| 325 | 325 | ) { |
| 326 | - $relname .= '_' . array_values($data['keymap'])[0]; |
|
| 326 | + $relname .= '_'.array_values($data['keymap'])[0]; |
|
| 327 | 327 | } |
| 328 | 328 | $orig = $relname; |
| 329 | 329 | $cntr = 1; |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | $definition->getName() == $relname || |
| 332 | 332 | $definition->getColumn($relname) |
| 333 | 333 | ) { |
| 334 | - $relname = $orig . '_' . (++ $cntr); |
|
| 334 | + $relname = $orig.'_'.(++$cntr); |
|
| 335 | 335 | } |
| 336 | 336 | $definition->addRelation( |
| 337 | 337 | new TableRelation( |
@@ -381,20 +381,20 @@ discard block |
||
| 381 | 381 | attr.attnum > 0 |
| 382 | 382 | order by |
| 383 | 383 | attr.attnum", |
| 384 | - [ $table, $schema ] |
|
| 384 | + [$table, $schema] |
|
| 385 | 385 | )) |
| 386 | - ->mapKey(function ($v): string { |
|
| 386 | + ->mapKey(function($v): string { |
|
| 387 | 387 | return $v['column_name']; |
| 388 | 388 | }) |
| 389 | - ->map(function ($v) { |
|
| 389 | + ->map(function($v) { |
|
| 390 | 390 | $v['length'] = null; |
| 391 | 391 | return $v; |
| 392 | 392 | }) |
| 393 | 393 | ->toArray(); |
| 394 | 394 | if (!count($columns)) { |
| 395 | - throw new DBException('View not found by name: ' . implode('.', [$schema,$table])); |
|
| 395 | + throw new DBException('View not found by name: '.implode('.', [$schema, $table])); |
|
| 396 | 396 | } |
| 397 | - $tables[$schema . '.' .$table] = $definition = (new Table($table, $schema)) |
|
| 397 | + $tables[$schema.'.'.$table] = $definition = (new Table($table, $schema)) |
|
| 398 | 398 | ->addColumns($columns) |
| 399 | 399 | ->setComment(''); |
| 400 | 400 | return $definition; |
@@ -410,13 +410,13 @@ discard block |
||
| 410 | 410 | (cls.relkind = 'p' OR cls.relkind = 'r') AND |
| 411 | 411 | ns.nspname = ? AND |
| 412 | 412 | NOT EXISTS (SELECT 1 FROM pg_inherits WHERE inhrelid = cls.oid) ", |
| 413 | - [ $this->connection['opts']['schema'] ?? 'public' ] |
|
| 413 | + [$this->connection['opts']['schema'] ?? 'public'] |
|
| 414 | 414 | )) |
| 415 | - ->mapKey(function ($v) { |
|
| 415 | + ->mapKey(function($v) { |
|
| 416 | 416 | return strtolower($v['table_name']); |
| 417 | 417 | }) |
| 418 | 418 | ->pluck('table_name') |
| 419 | - ->map(function ($v) { |
|
| 419 | + ->map(function($v) { |
|
| 420 | 420 | return $this->table($v)->toLowerCase(); |
| 421 | 421 | }) |
| 422 | 422 | ->toArray(); |
@@ -427,19 +427,19 @@ discard block |
||
| 427 | 427 | FROM pg_catalog.pg_class cls |
| 428 | 428 | join pg_catalog.pg_namespace as ns on ns.oid = cls.relnamespace |
| 429 | 429 | WHERE cls.relkind = 'm' and ns.nspname = ?", |
| 430 | - [ $this->connection['opts']['schema'] ?? 'public' ] |
|
| 430 | + [$this->connection['opts']['schema'] ?? 'public'] |
|
| 431 | 431 | )) |
| 432 | - ->mapKey(function ($v) { |
|
| 432 | + ->mapKey(function($v) { |
|
| 433 | 433 | return strtolower($v['table_name']); |
| 434 | 434 | }) |
| 435 | 435 | ->pluck('table_name') |
| 436 | - ->map(function ($v) { |
|
| 436 | + ->map(function($v) { |
|
| 437 | 437 | return $this->view($v)->toLowerCase(); |
| 438 | 438 | }) |
| 439 | 439 | ->toArray(); |
| 440 | 440 | $tables = array_merge($views, $tables); |
| 441 | 441 | foreach (array_keys($tables) as $k) { |
| 442 | - $tables[($this->connection['opts']['schema'] ?? 'public') . '.' . $k] = &$tables[$k]; |
|
| 442 | + $tables[($this->connection['opts']['schema'] ?? 'public').'.'.$k] = &$tables[$k]; |
|
| 443 | 443 | } |
| 444 | 444 | return $tables; |
| 445 | 445 | } |
@@ -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 | } |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | protected array $order = []; |
| 23 | 23 | protected array $group = []; |
| 24 | 24 | protected array $having = []; |
| 25 | - protected array $li_of = [0,0]; |
|
| 25 | + protected array $li_of = [0, 0]; |
|
| 26 | 26 | protected bool $li_mt = false; |
| 27 | 27 | protected array $fields = []; |
| 28 | 28 | protected array $withr = []; |
@@ -39,11 +39,11 @@ discard block |
||
| 39 | 39 | * @param Table|string $table the name or definition of the main table in the query |
| 40 | 40 | * @param bool $findRelations should the query builder try to find missing joins |
| 41 | 41 | */ |
| 42 | - public function __construct(DBInterface $db, Table|string $table, bool $findRelations = false) |
|
| 42 | + public function __construct(DBInterface $db, Table | string $table, bool $findRelations = false) |
|
| 43 | 43 | { |
| 44 | 44 | $this->db = $db; |
| 45 | 45 | $this->findRelations = $findRelations; |
| 46 | - $this->definition = $table instanceof Table ? $table : $this->db->definition((string)$table); |
|
| 46 | + $this->definition = $table instanceof Table ? $table : $this->db->definition((string) $table); |
|
| 47 | 47 | $primary = $this->definition->getPrimaryKey(); |
| 48 | 48 | $columns = $this->definition->getColumns(); |
| 49 | 49 | $this->pkey = count($primary) ? $primary : $columns; |
@@ -67,27 +67,27 @@ discard block |
||
| 67 | 67 | { |
| 68 | 68 | $column = explode('.', $column); |
| 69 | 69 | if (count($column) === 1) { |
| 70 | - $column = [ $this->definition->getFullName(), $column[0] ]; |
|
| 70 | + $column = [$this->definition->getFullName(), $column[0]]; |
|
| 71 | 71 | $col = $this->definition->getColumn($column[1]); |
| 72 | 72 | if (!$col) { |
| 73 | - throw new DBException('Invalid column name in main table: ' . $column[1]); |
|
| 73 | + throw new DBException('Invalid column name in main table: '.$column[1]); |
|
| 74 | 74 | } |
| 75 | 75 | } elseif (count($column) === 2) { |
| 76 | 76 | if ($column[0] === $this->definition->getName()) { |
| 77 | 77 | $col = $this->definition->getColumn($column[1]); |
| 78 | 78 | if (!$col) { |
| 79 | - throw new DBException('Invalid column name in main table: ' . $column[1]); |
|
| 79 | + throw new DBException('Invalid column name in main table: '.$column[1]); |
|
| 80 | 80 | } |
| 81 | 81 | } else { |
| 82 | 82 | if ($this->definition->hasRelation($column[0])) { |
| 83 | 83 | $col = $this->definition->getRelation($column[0])?->table?->getColumn($column[1]); |
| 84 | 84 | if (!$col) { |
| 85 | - throw new DBException('Invalid column name in related table: ' . $column[1]); |
|
| 85 | + throw new DBException('Invalid column name in related table: '.$column[1]); |
|
| 86 | 86 | } |
| 87 | 87 | } elseif (isset($this->joins[$column[0]])) { |
| 88 | 88 | $col = $this->joins[$column[0]]->table->getColumn($column[1]); |
| 89 | 89 | if (!$col) { |
| 90 | - throw new DBException('Invalid column name in related table: ' . $column[1]); |
|
| 90 | + throw new DBException('Invalid column name in related table: '.$column[1]); |
|
| 91 | 91 | } |
| 92 | 92 | } else { |
| 93 | 93 | $col = null; |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | $path = $this->db->findRelation($this->definition->getName(), $column[0]); |
| 107 | 107 | } |
| 108 | 108 | if (!count($path)) { |
| 109 | - throw new DBException('Invalid foreign table / column name: ' . implode(',', $column)); |
|
| 109 | + throw new DBException('Invalid foreign table / column name: '.implode(',', $column)); |
|
| 110 | 110 | } |
| 111 | 111 | unset($path[0]); |
| 112 | 112 | $this->with(implode('.', $path), false); |
@@ -119,26 +119,26 @@ discard block |
||
| 119 | 119 | if ($this->definition->hasRelation(implode('.', $column))) { |
| 120 | 120 | $this->with(implode('.', $column), false); |
| 121 | 121 | $col = $this->definition->getRelation(implode('.', $column))?->table?->getColumn($name); |
| 122 | - $column = [ implode('.', $column), $name ]; |
|
| 122 | + $column = [implode('.', $column), $name]; |
|
| 123 | 123 | } else { |
| 124 | 124 | $this->with(implode('.', $column), false); |
| 125 | 125 | $table = $this->definition; |
| 126 | 126 | $table = array_reduce( |
| 127 | 127 | $column, |
| 128 | - function ($carry, $item) use (&$table) { |
|
| 128 | + function($carry, $item) use (&$table) { |
|
| 129 | 129 | $table = $table->getRelation($item)->table; |
| 130 | 130 | return $table; |
| 131 | 131 | } |
| 132 | 132 | ); |
| 133 | 133 | $col = $table->getColumn($name); |
| 134 | - $column = [ implode(static::SEP, $column), $name ]; |
|
| 134 | + $column = [implode(static::SEP, $column), $name]; |
|
| 135 | 135 | } |
| 136 | 136 | } |
| 137 | - return [ 'name' => implode('.', $column), 'data' => $col ]; |
|
| 137 | + return ['name' => implode('.', $column), 'data' => $col]; |
|
| 138 | 138 | } |
| 139 | 139 | protected function normalizeValue(TableColumn $col, mixed $value): mixed |
| 140 | 140 | { |
| 141 | - $strict = (int)$this->db->driverOption('strict', 0) > 0; |
|
| 141 | + $strict = (int) $this->db->driverOption('strict', 0) > 0; |
|
| 142 | 142 | if ($value === null && $col->isNullable()) { |
| 143 | 143 | return null; |
| 144 | 144 | } |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | $temp = strtotime($value); |
| 149 | 149 | if (!$temp) { |
| 150 | 150 | if ($strict) { |
| 151 | - throw new DBException('Invalid value for date column: ' . $col->getName()); |
|
| 151 | + throw new DBException('Invalid value for date column: '.$col->getName()); |
|
| 152 | 152 | } |
| 153 | 153 | return null; |
| 154 | 154 | } |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | return $value->format('Y-m-d'); |
| 162 | 162 | } |
| 163 | 163 | if ($strict) { |
| 164 | - throw new DBException('Invalid value (unknown data type) for date column: ' . $col->getName()); |
|
| 164 | + throw new DBException('Invalid value (unknown data type) for date column: '.$col->getName()); |
|
| 165 | 165 | } |
| 166 | 166 | return $value; |
| 167 | 167 | case 'datetime': |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | $temp = strtotime($value); |
| 170 | 170 | if (!$temp) { |
| 171 | 171 | if ($strict) { |
| 172 | - throw new DBException('Invalid value for datetime column: ' . $col->getName()); |
|
| 172 | + throw new DBException('Invalid value for datetime column: '.$col->getName()); |
|
| 173 | 173 | } |
| 174 | 174 | return null; |
| 175 | 175 | } |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | return $value->format('Y-m-d H:i:s'); |
| 183 | 183 | } |
| 184 | 184 | if ($strict) { |
| 185 | - throw new DBException('Invalid value (unknown data type) for datetime column ' . $col->getName()); |
|
| 185 | + throw new DBException('Invalid value (unknown data type) for datetime column '.$col->getName()); |
|
| 186 | 186 | } |
| 187 | 187 | return $value; |
| 188 | 188 | case 'enum': |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | if (is_int($value)) { |
| 191 | 191 | if (!isset($values[$value])) { |
| 192 | 192 | if ($strict) { |
| 193 | - throw new DBException('Invalid value (using integer) for enum: ' . $col->getName()); |
|
| 193 | + throw new DBException('Invalid value (using integer) for enum: '.$col->getName()); |
|
| 194 | 194 | } |
| 195 | 195 | return $value; |
| 196 | 196 | } |
@@ -198,29 +198,29 @@ discard block |
||
| 198 | 198 | } |
| 199 | 199 | if (!in_array($value, $col->getValues())) { |
| 200 | 200 | if ($strict) { |
| 201 | - throw new DBException('Invalid value for enum: ' . $col->getName()); |
|
| 201 | + throw new DBException('Invalid value for enum: '.$col->getName()); |
|
| 202 | 202 | } |
| 203 | 203 | return 0; |
| 204 | 204 | } |
| 205 | 205 | return $value; |
| 206 | 206 | case 'int': |
| 207 | - $temp = preg_replace('([^+\-0-9]+)', '', (string)$value); |
|
| 208 | - return is_string($temp) ? (int)$temp : 0; |
|
| 207 | + $temp = preg_replace('([^+\-0-9]+)', '', (string) $value); |
|
| 208 | + return is_string($temp) ? (int) $temp : 0; |
|
| 209 | 209 | case 'float': |
| 210 | - $temp = preg_replace('([^+\-0-9.]+)', '', str_replace(',', '.', (string)$value)); |
|
| 211 | - return is_string($temp) ? (float)$temp : 0; |
|
| 210 | + $temp = preg_replace('([^+\-0-9.]+)', '', str_replace(',', '.', (string) $value)); |
|
| 211 | + return is_string($temp) ? (float) $temp : 0; |
|
| 212 | 212 | case 'text': |
| 213 | 213 | if (!is_scalar($value)) { |
| 214 | 214 | $value = json_encode($value, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); |
| 215 | 215 | } |
| 216 | 216 | if (!is_string($value)) { |
| 217 | - $value = (string)$value; |
|
| 217 | + $value = (string) $value; |
|
| 218 | 218 | } |
| 219 | 219 | // check using strlen first, in order to avoid hitting mb_ functions which might be polyfilled |
| 220 | 220 | // because the polyfill is quite slow |
| 221 | 221 | if ($col->hasLength() && strlen($value) > $col->getLength() && mb_strlen($value) > $col->getLength()) { |
| 222 | 222 | if ($strict) { |
| 223 | - throw new DBException('Invalid value for text column: ' . $col->getName()); |
|
| 223 | + throw new DBException('Invalid value for text column: '.$col->getName()); |
|
| 224 | 224 | } |
| 225 | 225 | return mb_substr($value, 0, $col->getLength()); |
| 226 | 226 | } |
@@ -253,11 +253,11 @@ discard block |
||
| 253 | 253 | $sqls[] = $temp[0]; |
| 254 | 254 | $pars = array_merge($pars, $temp[1]); |
| 255 | 255 | unset($value[$k]); |
| 256 | - } elseif (in_array($k, ['like','ilike','contains','icontains','ends','iends'])) { |
|
| 256 | + } elseif (in_array($k, ['like', 'ilike', 'contains', 'icontains', 'ends', 'iends'])) { |
|
| 257 | 257 | if ($column->getBasicType() !== 'text') { |
| 258 | 258 | switch ($this->db->driverName()) { |
| 259 | 259 | case 'oracle': |
| 260 | - $name = 'CAST(' . $name . ' AS NVARCHAR(500))'; |
|
| 260 | + $name = 'CAST('.$name.' AS NVARCHAR(500))'; |
|
| 261 | 261 | break; |
| 262 | 262 | case 'postgre': |
| 263 | 263 | $name = $name.'::text'; |
@@ -272,25 +272,25 @@ discard block |
||
| 272 | 272 | $sql = []; |
| 273 | 273 | $par = []; |
| 274 | 274 | foreach ($values as $v) { |
| 275 | - $v = str_replace(['%', '_'], ['\\%','\\_'], $v) . '%'; |
|
| 275 | + $v = str_replace(['%', '_'], ['\\%', '\\_'], $v).'%'; |
|
| 276 | 276 | if ($mode === 'contains' || $mode === 'icontains') { |
| 277 | - $v = '%' . $v; |
|
| 277 | + $v = '%'.$v; |
|
| 278 | 278 | } |
| 279 | 279 | if ($mode === 'ends' || $mode === 'iends') { |
| 280 | - $v = '%' . rtrim($v, '%'); |
|
| 280 | + $v = '%'.rtrim($v, '%'); |
|
| 281 | 281 | } |
| 282 | 282 | if ($mode === 'icontains' || $mode === 'ilike' || $mode === 'iends') { |
| 283 | 283 | $v = mb_strtoupper($v); |
| 284 | - $name = 'UPPER(' . $name . ')'; |
|
| 284 | + $name = 'UPPER('.$name.')'; |
|
| 285 | 285 | } |
| 286 | - $sql[] = $negate ? $name . ' NOT LIKE ?' : $name . ' LIKE ?'; |
|
| 286 | + $sql[] = $negate ? $name.' NOT LIKE ?' : $name.' LIKE ?'; |
|
| 287 | 287 | $par[] = $v; |
| 288 | 288 | } |
| 289 | 289 | if ($negate) { |
| 290 | - $sqls[] = '(' . implode(' AND ', $sql) . ')'; |
|
| 290 | + $sqls[] = '('.implode(' AND ', $sql).')'; |
|
| 291 | 291 | $pars = array_merge($pars, $par); |
| 292 | 292 | } else { |
| 293 | - $sqls[] = '(' . implode(' OR ', $sql) . ')'; |
|
| 293 | + $sqls[] = '('.implode(' OR ', $sql).')'; |
|
| 294 | 294 | $pars = array_merge($pars, $par); |
| 295 | 295 | } |
| 296 | 296 | unset($value[$k]); |
@@ -298,38 +298,38 @@ discard block |
||
| 298 | 298 | } |
| 299 | 299 | if (!count($value)) { |
| 300 | 300 | return [ |
| 301 | - '(' . implode(' AND ', $sqls) . ')', |
|
| 301 | + '('.implode(' AND ', $sqls).')', |
|
| 302 | 302 | $pars |
| 303 | 303 | ]; |
| 304 | 304 | } |
| 305 | 305 | } |
| 306 | 306 | if (is_null($value)) { |
| 307 | - $sqls[] = $negate ? $name . ' IS NOT NULL' : $name . ' IS NULL'; |
|
| 307 | + $sqls[] = $negate ? $name.' IS NOT NULL' : $name.' IS NULL'; |
|
| 308 | 308 | return [ |
| 309 | - '(' . implode(' AND ', $sqls) . ')', |
|
| 309 | + '('.implode(' AND ', $sqls).')', |
|
| 310 | 310 | $pars |
| 311 | 311 | ]; |
| 312 | 312 | } |
| 313 | 313 | if (!is_array($value)) { |
| 314 | - $sqls[] = $negate ? $name . ' <> ?' : $name . ' = ?'; |
|
| 314 | + $sqls[] = $negate ? $name.' <> ?' : $name.' = ?'; |
|
| 315 | 315 | $pars[] = $this->normalizeValue($column, $value); |
| 316 | 316 | return [ |
| 317 | - '(' . implode(' AND ', $sqls) . ')', |
|
| 317 | + '('.implode(' AND ', $sqls).')', |
|
| 318 | 318 | $pars |
| 319 | 319 | ]; |
| 320 | 320 | } |
| 321 | 321 | if (isset($value['beg']) && strlen($value['beg']) && (!isset($value['end']) || !strlen($value['end']))) { |
| 322 | - $value = [ 'gte' => $value['beg'] ]; |
|
| 322 | + $value = ['gte' => $value['beg']]; |
|
| 323 | 323 | } |
| 324 | 324 | if (isset($value['end']) && strlen($value['end']) && (!isset($value['beg']) || !strlen($value['beg']))) { |
| 325 | - $value = [ 'lte' => $value['end'] ]; |
|
| 325 | + $value = ['lte' => $value['end']]; |
|
| 326 | 326 | } |
| 327 | 327 | if (isset($value['beg']) && isset($value['end'])) { |
| 328 | 328 | $sqls[] = $negate ? $name.' NOT BETWEEN ? AND ?' : $name.' BETWEEN ? AND ?'; |
| 329 | 329 | $pars[] = $this->normalizeValue($column, $value['beg']); |
| 330 | 330 | $pars[] = $this->normalizeValue($column, $value['end']); |
| 331 | 331 | return [ |
| 332 | - '(' . implode(' AND ', $sqls) . ')', |
|
| 332 | + '('.implode(' AND ', $sqls).')', |
|
| 333 | 333 | $pars |
| 334 | 334 | ]; |
| 335 | 335 | } |
@@ -337,51 +337,51 @@ discard block |
||
| 337 | 337 | $sql = []; |
| 338 | 338 | $par = []; |
| 339 | 339 | if (isset($value['gt'])) { |
| 340 | - $sql[] = $name. ' ' . ($negate ? '<=' : '>') . ' ?'; |
|
| 340 | + $sql[] = $name.' '.($negate ? '<=' : '>').' ?'; |
|
| 341 | 341 | $par[] = $this->normalizeValue($column, $value['gt']); |
| 342 | 342 | } |
| 343 | 343 | if (isset($value['gte'])) { |
| 344 | - $sql[] = $name. ' ' . ($negate ? '<' : '>=') . ' ?'; |
|
| 344 | + $sql[] = $name.' '.($negate ? '<' : '>=').' ?'; |
|
| 345 | 345 | $par[] = $this->normalizeValue($column, $value['gte']); |
| 346 | 346 | } |
| 347 | 347 | if (isset($value['lt'])) { |
| 348 | - $sql[] = $name. ' ' . ($negate ? '>=' : '<') . ' ?'; |
|
| 348 | + $sql[] = $name.' '.($negate ? '>=' : '<').' ?'; |
|
| 349 | 349 | $par[] = $this->normalizeValue($column, $value['lt']); |
| 350 | 350 | } |
| 351 | 351 | if (isset($value['lte'])) { |
| 352 | - $sql[] = $name. ' ' . ($negate ? '>' : '<=') . ' ?'; |
|
| 352 | + $sql[] = $name.' '.($negate ? '>' : '<=').' ?'; |
|
| 353 | 353 | $par[] = $this->normalizeValue($column, $value['lte']); |
| 354 | 354 | } |
| 355 | - $sqls[] = '(' . implode(' AND ', $sql) . ')'; |
|
| 355 | + $sqls[] = '('.implode(' AND ', $sql).')'; |
|
| 356 | 356 | $pars = array_merge($pars, $par); |
| 357 | 357 | return [ |
| 358 | - '(' . implode(' AND ', $sqls) . ')', |
|
| 358 | + '('.implode(' AND ', $sqls).')', |
|
| 359 | 359 | $pars |
| 360 | 360 | ]; |
| 361 | 361 | } |
| 362 | 362 | |
| 363 | - $value = array_values(array_map(function ($v) use ($column) { |
|
| 363 | + $value = array_values(array_map(function($v) use ($column) { |
|
| 364 | 364 | return $this->normalizeValue($column, $v); |
| 365 | 365 | }, $value)); |
| 366 | 366 | if ($this->db->driverName() === 'oracle') { |
| 367 | 367 | $sql = []; |
| 368 | 368 | $par = []; |
| 369 | 369 | for ($i = 0; $i < count($value); $i += 500) { |
| 370 | - $sql[] = $negate ? $name . ' NOT IN (??)' : $name . ' IN (??)'; |
|
| 370 | + $sql[] = $negate ? $name.' NOT IN (??)' : $name.' IN (??)'; |
|
| 371 | 371 | $par[] = array_slice($value, $i, 500); |
| 372 | 372 | } |
| 373 | - $sql = '(' . implode($negate ? ' AND ' : ' OR ', $sql) . ')'; |
|
| 373 | + $sql = '('.implode($negate ? ' AND ' : ' OR ', $sql).')'; |
|
| 374 | 374 | $sqls[] = $sql; |
| 375 | 375 | $pars = array_merge($pars, $par); |
| 376 | 376 | return [ |
| 377 | - '(' . implode(' AND ', $sqls) . ')', |
|
| 377 | + '('.implode(' AND ', $sqls).')', |
|
| 378 | 378 | $pars |
| 379 | 379 | ]; |
| 380 | 380 | } |
| 381 | - $sqls[] = $negate ? $name . ' NOT IN (??)' : $name . ' IN (??)'; |
|
| 381 | + $sqls[] = $negate ? $name.' NOT IN (??)' : $name.' IN (??)'; |
|
| 382 | 382 | $pars[] = $value; |
| 383 | 383 | return [ |
| 384 | - '(' . implode(' AND ', $sqls) . ')', |
|
| 384 | + '('.implode(' AND ', $sqls).')', |
|
| 385 | 385 | $pars |
| 386 | 386 | ]; |
| 387 | 387 | } |
@@ -413,7 +413,7 @@ discard block |
||
| 413 | 413 | $par = array_merge($par, $temp[1]); |
| 414 | 414 | } |
| 415 | 415 | } |
| 416 | - return $this->where('(' . implode(' OR ', $sql) . ')', $par); |
|
| 416 | + return $this->where('('.implode(' OR ', $sql).')', $par); |
|
| 417 | 417 | } |
| 418 | 418 | /** |
| 419 | 419 | * Filter the results matching all of the criteria |
@@ -431,7 +431,7 @@ discard block |
||
| 431 | 431 | $par = array_merge($par, $temp[1]); |
| 432 | 432 | } |
| 433 | 433 | } |
| 434 | - return $this->where('(' . implode(' AND ', $sql) . ')', $par); |
|
| 434 | + return $this->where('('.implode(' AND ', $sql).')', $par); |
|
| 435 | 435 | } |
| 436 | 436 | /** |
| 437 | 437 | * Sort by a column |
@@ -444,9 +444,9 @@ discard block |
||
| 444 | 444 | try { |
| 445 | 445 | $this->getColumn($column); |
| 446 | 446 | } catch (DBException $e) { |
| 447 | - throw new DBException('Invalid sort column: ' . $column); |
|
| 447 | + throw new DBException('Invalid sort column: '.$column); |
|
| 448 | 448 | } |
| 449 | - return $this->order($column . ' ' . ($desc ? 'DESC' : 'ASC')); |
|
| 449 | + return $this->order($column.' '.($desc ? 'DESC' : 'ASC')); |
|
| 450 | 450 | } |
| 451 | 451 | /** |
| 452 | 452 | * Group by a column (or columns) |
@@ -456,7 +456,7 @@ discard block |
||
| 456 | 456 | public function group($column) : static |
| 457 | 457 | { |
| 458 | 458 | if (!is_array($column)) { |
| 459 | - $column = [ $column ]; |
|
| 459 | + $column = [$column]; |
|
| 460 | 460 | } |
| 461 | 461 | foreach ($column as $k => $v) { |
| 462 | 462 | $column[$k] = $this->getColumn($v)['name']; |
@@ -499,7 +499,7 @@ discard block |
||
| 499 | 499 | $this->order = []; |
| 500 | 500 | $this->having = []; |
| 501 | 501 | $this->aliases = []; |
| 502 | - $this->li_of = [0,0]; |
|
| 502 | + $this->li_of = [0, 0]; |
|
| 503 | 503 | $this->li_mt = false; |
| 504 | 504 | $this->qiterator = null; |
| 505 | 505 | return $this; |
@@ -513,7 +513,7 @@ discard block |
||
| 513 | 513 | public function groupBy(string $sql, array $params = []) : static |
| 514 | 514 | { |
| 515 | 515 | $this->qiterator = null; |
| 516 | - $this->group = [ $sql, $params ]; |
|
| 516 | + $this->group = [$sql, $params]; |
|
| 517 | 517 | return $this; |
| 518 | 518 | } |
| 519 | 519 | /** |
@@ -527,7 +527,7 @@ discard block |
||
| 527 | 527 | public function join($table, array $fields, ?string $name = null, bool $multiple = true) |
| 528 | 528 | { |
| 529 | 529 | $this->qiterator = null; |
| 530 | - $table = $table instanceof Table ? $table : $this->db->definition((string)$table); |
|
| 530 | + $table = $table instanceof Table ? $table : $this->db->definition((string) $table); |
|
| 531 | 531 | $name = $name ?? $table->getName(); |
| 532 | 532 | if (isset($this->joins[$name]) || $this->definition->hasRelation($name)) { |
| 533 | 533 | throw new DBException('Alias / table name already in use'); |
@@ -536,7 +536,7 @@ discard block |
||
| 536 | 536 | foreach ($fields as $k => $v) { |
| 537 | 537 | $k = explode('.', $k, 2); |
| 538 | 538 | $k = count($k) == 2 ? $k[1] : $k[0]; |
| 539 | - $this->joins[$name]->keymap[$this->getColumn($name . '.' . $k)['name']] = $this->getColumn($v)['name']; |
|
| 539 | + $this->joins[$name]->keymap[$this->getColumn($name.'.'.$k)['name']] = $this->getColumn($v)['name']; |
|
| 540 | 540 | } |
| 541 | 541 | return $this; |
| 542 | 542 | } |
@@ -549,7 +549,7 @@ discard block |
||
| 549 | 549 | public function where(string $sql, array $params = []) : static |
| 550 | 550 | { |
| 551 | 551 | $this->qiterator = null; |
| 552 | - $this->where[] = [ $sql, $params ]; |
|
| 552 | + $this->where[] = [$sql, $params]; |
|
| 553 | 553 | return $this; |
| 554 | 554 | } |
| 555 | 555 | /** |
@@ -561,7 +561,7 @@ discard block |
||
| 561 | 561 | public function having(string $sql, array $params = []) : static |
| 562 | 562 | { |
| 563 | 563 | $this->qiterator = null; |
| 564 | - $this->having[] = [ $sql, $params ]; |
|
| 564 | + $this->having[] = [$sql, $params]; |
|
| 565 | 565 | return $this; |
| 566 | 566 | } |
| 567 | 567 | /** |
@@ -581,12 +581,12 @@ discard block |
||
| 581 | 581 | throw new \Exception(); |
| 582 | 582 | } |
| 583 | 583 | $name = $this->getColumn(trim($name))['name']; |
| 584 | - $sql = $name . ' ' . (strpos(strtolower($sql), ' desc') ? 'DESC' : 'ASC'); |
|
| 584 | + $sql = $name.' '.(strpos(strtolower($sql), ' desc') ? 'DESC' : 'ASC'); |
|
| 585 | 585 | } catch (\Exception $e) { |
| 586 | 586 | $name = null; |
| 587 | 587 | } |
| 588 | 588 | } |
| 589 | - $this->order = [ $sql, $params, $name ]; |
|
| 589 | + $this->order = [$sql, $params, $name]; |
|
| 590 | 590 | return $this; |
| 591 | 591 | } |
| 592 | 592 | /** |
@@ -598,7 +598,7 @@ discard block |
||
| 598 | 598 | public function limit(int $limit, int $offset = 0, ?bool $limitOnMainTable = null) : static |
| 599 | 599 | { |
| 600 | 600 | $this->qiterator = null; |
| 601 | - $this->li_of = [ $limit, $offset ]; |
|
| 601 | + $this->li_of = [$limit, $offset]; |
|
| 602 | 602 | if (isset($limitOnMainTable)) { |
| 603 | 603 | $this->li_mt = $limitOnMainTable; |
| 604 | 604 | } |
@@ -617,9 +617,9 @@ discard block |
||
| 617 | 617 | { |
| 618 | 618 | $aliases = []; |
| 619 | 619 | $aliases_ext = []; |
| 620 | - $getAlias = function ($name) use (&$aliases, &$aliases_ext) { |
|
| 620 | + $getAlias = function($name) use (&$aliases, &$aliases_ext) { |
|
| 621 | 621 | // to bypass use: return $name; |
| 622 | - $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases); |
|
| 622 | + $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases); |
|
| 623 | 623 | if (isset($aliases_ext[$name])) { |
| 624 | 624 | unset($aliases_ext[$name]); |
| 625 | 625 | } |
@@ -642,7 +642,7 @@ discard block |
||
| 642 | 642 | $h = $this->having; |
| 643 | 643 | $o = $this->order; |
| 644 | 644 | $g = $this->group; |
| 645 | - $j = array_map(function ($v) { |
|
| 645 | + $j = array_map(function($v) { |
|
| 646 | 646 | return clone $v; |
| 647 | 647 | }, $this->joins); |
| 648 | 648 | |
@@ -652,28 +652,28 @@ discard block |
||
| 652 | 652 | continue; |
| 653 | 653 | } |
| 654 | 654 | foreach ($w as $kk => $v) { |
| 655 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) { |
|
| 655 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) { |
|
| 656 | 656 | $used_relations[] = $k; |
| 657 | - $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]); |
|
| 657 | + $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]); |
|
| 658 | 658 | } |
| 659 | 659 | } |
| 660 | 660 | foreach ($h as $kk => $v) { |
| 661 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) { |
|
| 661 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) { |
|
| 662 | 662 | $used_relations[] = $k; |
| 663 | - $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]); |
|
| 663 | + $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]); |
|
| 664 | 664 | } |
| 665 | 665 | } |
| 666 | - if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) { |
|
| 666 | + if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) { |
|
| 667 | 667 | $used_relations[] = $k; |
| 668 | - $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]); |
|
| 668 | + $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]); |
|
| 669 | 669 | } |
| 670 | 670 | foreach ($j as $kk => $v) { |
| 671 | 671 | foreach ($v->keymap as $kkk => $vv) { |
| 672 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) { |
|
| 672 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) { |
|
| 673 | 673 | $used_relations[] = $k; |
| 674 | 674 | $j[$kk]->keymap[$kkk] = preg_replace( |
| 675 | - '(\b'.preg_quote($k . '.'). ')i', |
|
| 676 | - $getAlias($k) . '.', |
|
| 675 | + '(\b'.preg_quote($k.'.').')i', |
|
| 676 | + $getAlias($k).'.', |
|
| 677 | 677 | $vv |
| 678 | 678 | ); |
| 679 | 679 | } |
@@ -682,65 +682,65 @@ discard block |
||
| 682 | 682 | } |
| 683 | 683 | foreach ($this->definition->getRelations() as $k => $v) { |
| 684 | 684 | foreach ($w as $kk => $vv) { |
| 685 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) { |
|
| 686 | - $relations[$k] = [ $v, $table ]; |
|
| 685 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) { |
|
| 686 | + $relations[$k] = [$v, $table]; |
|
| 687 | 687 | $used_relations[] = $k; |
| 688 | - $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]); |
|
| 688 | + $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]); |
|
| 689 | 689 | } |
| 690 | 690 | } |
| 691 | - if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) { |
|
| 692 | - $relations[$k] = [ $v, $table ]; |
|
| 691 | + if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) { |
|
| 692 | + $relations[$k] = [$v, $table]; |
|
| 693 | 693 | } |
| 694 | 694 | foreach ($h as $kk => $vv) { |
| 695 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) { |
|
| 696 | - $relations[$k] = [ $v, $table ]; |
|
| 695 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) { |
|
| 696 | + $relations[$k] = [$v, $table]; |
|
| 697 | 697 | $used_relations[] = $k; |
| 698 | - $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]); |
|
| 698 | + $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]); |
|
| 699 | 699 | } |
| 700 | 700 | } |
| 701 | - if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) { |
|
| 702 | - $relations[$k] = [ $v, $table ]; |
|
| 701 | + if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) { |
|
| 702 | + $relations[$k] = [$v, $table]; |
|
| 703 | 703 | $used_relations[] = $k; |
| 704 | - $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]); |
|
| 704 | + $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]); |
|
| 705 | 705 | } |
| 706 | 706 | foreach ($j as $kk => $vv) { |
| 707 | 707 | foreach ($vv->keymap as $kkk => $vvv) { |
| 708 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vvv)) { |
|
| 709 | - $relations[$k] = [ $v, $table ]; |
|
| 708 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $vvv)) { |
|
| 709 | + $relations[$k] = [$v, $table]; |
|
| 710 | 710 | $used_relations[] = $k; |
| 711 | 711 | $j[$kk]->keymap[$kkk] = |
| 712 | - preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vvv); |
|
| 712 | + preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vvv); |
|
| 713 | 713 | } |
| 714 | 714 | } |
| 715 | 715 | } |
| 716 | 716 | } |
| 717 | 717 | foreach ($aliases_ext as $k => $alias) { |
| 718 | 718 | foreach ($w as $kk => $v) { |
| 719 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) { |
|
| 720 | - $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $v[0]); |
|
| 719 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) { |
|
| 720 | + $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $v[0]); |
|
| 721 | 721 | $used_relations[] = $k; |
| 722 | 722 | } |
| 723 | 723 | } |
| 724 | 724 | foreach ($h as $kk => $v) { |
| 725 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) { |
|
| 726 | - $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $v[0]); |
|
| 725 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) { |
|
| 726 | + $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $v[0]); |
|
| 727 | 727 | $used_relations[] = $k; |
| 728 | 728 | } |
| 729 | 729 | } |
| 730 | - if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) { |
|
| 730 | + if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) { |
|
| 731 | 731 | $used_relations[] = $k; |
| 732 | 732 | } |
| 733 | - if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) { |
|
| 734 | - $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $g[0]); |
|
| 733 | + if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) { |
|
| 734 | + $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $g[0]); |
|
| 735 | 735 | $used_relations[] = $k; |
| 736 | 736 | } |
| 737 | 737 | foreach ($j as $kk => $v) { |
| 738 | 738 | foreach ($v->keymap as $kkk => $vv) { |
| 739 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) { |
|
| 739 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) { |
|
| 740 | 740 | $used_relations[] = $k; |
| 741 | 741 | $j[$kk]->keymap[$kkk] = preg_replace( |
| 742 | - '(\b'.preg_quote($k . '.'). ')i', |
|
| 743 | - $alias . '.', |
|
| 742 | + '(\b'.preg_quote($k.'.').')i', |
|
| 743 | + $alias.'.', |
|
| 744 | 744 | $vv |
| 745 | 745 | ); |
| 746 | 746 | } |
@@ -759,13 +759,13 @@ discard block |
||
| 759 | 759 | foreach ($v->keymap as $kk => $vv) { |
| 760 | 760 | $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' '; |
| 761 | 761 | } |
| 762 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
| 762 | + $sql .= implode(' AND ', $tmp).' '; |
|
| 763 | 763 | $sql .= 'LEFT JOIN '.$v->table->getFullName().' '.$getAlias($k).' ON '; |
| 764 | 764 | $tmp = []; |
| 765 | 765 | foreach ($v->pivot_keymap as $kk => $vv) { |
| 766 | 766 | $tmp[] = $getAlias($k).'.'.$vv.' = '.$alias.'.'.$kk.' '; |
| 767 | 767 | } |
| 768 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
| 768 | + $sql .= implode(' AND ', $tmp).' '; |
|
| 769 | 769 | } else { |
| 770 | 770 | $alias = $getAlias($k); |
| 771 | 771 | $sql .= 'LEFT JOIN '.$v->table->getFullName().' '.$alias.' ON '; |
@@ -774,10 +774,10 @@ discard block |
||
| 774 | 774 | $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' '; |
| 775 | 775 | } |
| 776 | 776 | if ($v->sql) { |
| 777 | - $tmp[] = $v->sql . ' '; |
|
| 777 | + $tmp[] = $v->sql.' '; |
|
| 778 | 778 | $par = array_merge($par, $v->par ?? []); |
| 779 | 779 | } |
| 780 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
| 780 | + $sql .= implode(' AND ', $tmp).' '; |
|
| 781 | 781 | } |
| 782 | 782 | } |
| 783 | 783 | } |
@@ -786,12 +786,12 @@ discard block |
||
| 786 | 786 | if ($v->many) { |
| 787 | 787 | $jMany = true; |
| 788 | 788 | } |
| 789 | - $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getFullName().' '.$k.' ON '; |
|
| 789 | + $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getFullName().' '.$k.' ON '; |
|
| 790 | 790 | $tmp = []; |
| 791 | 791 | foreach ($v->keymap as $kk => $vv) { |
| 792 | 792 | $tmp[] = $kk.' = '.$vv; |
| 793 | 793 | } |
| 794 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
| 794 | + $sql .= implode(' AND ', $tmp).' '; |
|
| 795 | 795 | } |
| 796 | 796 | if (!$jMany && !count($used_relations)) { |
| 797 | 797 | $sql = str_replace('COUNT(DISTINCT ', 'COUNT(', $sql); |
@@ -800,20 +800,20 @@ discard block |
||
| 800 | 800 | $sql .= 'WHERE '; |
| 801 | 801 | $tmp = []; |
| 802 | 802 | foreach ($w as $v) { |
| 803 | - $tmp[] = '(' . $v[0] . ')'; |
|
| 803 | + $tmp[] = '('.$v[0].')'; |
|
| 804 | 804 | $par = array_merge($par, $v[1]); |
| 805 | 805 | } |
| 806 | 806 | $sql .= implode(' AND ', $tmp).' '; |
| 807 | 807 | } |
| 808 | 808 | if (count($g)) { |
| 809 | - $sql .= 'GROUP BY ' . $g[0] . ' '; |
|
| 809 | + $sql .= 'GROUP BY '.$g[0].' '; |
|
| 810 | 810 | $par = array_merge($par, $g[1]); |
| 811 | 811 | } |
| 812 | 812 | if (count($h)) { |
| 813 | 813 | $sql .= 'HAVING '; |
| 814 | 814 | $tmp = []; |
| 815 | 815 | foreach ($h as $v) { |
| 816 | - $tmp[] = '(' . $v[0] . ')'; |
|
| 816 | + $tmp[] = '('.$v[0].')'; |
|
| 817 | 817 | $par = array_merge($par, $v[1]); |
| 818 | 818 | } |
| 819 | 819 | $sql .= implode(' AND ', $tmp).' '; |
@@ -843,14 +843,14 @@ discard block |
||
| 843 | 843 | } elseif (isset($this->joins[$table])) { |
| 844 | 844 | $cols = $this->joins[$table]->table->getColumns(); |
| 845 | 845 | } else { |
| 846 | - throw new DBException('Invalid foreign table name: ' . $table); |
|
| 846 | + throw new DBException('Invalid foreign table name: '.$table); |
|
| 847 | 847 | } |
| 848 | 848 | } else { |
| 849 | 849 | array_pop($temp); |
| 850 | 850 | $this->with(implode('.', $temp)); |
| 851 | 851 | $table = array_reduce( |
| 852 | 852 | $temp, |
| 853 | - function ($carry, $item) use (&$table) { |
|
| 853 | + function($carry, $item) use (&$table) { |
|
| 854 | 854 | return $table->getRelation($item)->table; |
| 855 | 855 | } |
| 856 | 856 | ); |
@@ -859,7 +859,7 @@ discard block |
||
| 859 | 859 | } |
| 860 | 860 | unset($fields[$k]); |
| 861 | 861 | foreach ($cols as $col) { |
| 862 | - $fields[] = $table . '.' . $col; |
|
| 862 | + $fields[] = $table.'.'.$col; |
|
| 863 | 863 | } |
| 864 | 864 | } |
| 865 | 865 | } |
@@ -893,11 +893,11 @@ discard block |
||
| 893 | 893 | if ($relation[2]) { |
| 894 | 894 | if (!$this->manualColumns) { |
| 895 | 895 | foreach ($relation[0]->table->getColumns() as $column) { |
| 896 | - $f[] = $name . '.' . $column; |
|
| 896 | + $f[] = $name.'.'.$column; |
|
| 897 | 897 | } |
| 898 | 898 | } else { |
| 899 | 899 | foreach ($relation[0]->table->getPrimaryKey() as $column) { |
| 900 | - $f[] = $name . '.' . $column; |
|
| 900 | + $f[] = $name.'.'.$column; |
|
| 901 | 901 | } |
| 902 | 902 | } |
| 903 | 903 | } |
@@ -917,11 +917,11 @@ discard block |
||
| 917 | 917 | continue; |
| 918 | 918 | } |
| 919 | 919 | if (count($temp) === 2 && $this->definition->hasRelation($temp[0]) && $this->definition->getRelation($temp[0])?->table->getColumn($temp[1])) { |
| 920 | - $r[] = $temp[0] . '.' . $temp[1]; |
|
| 920 | + $r[] = $temp[0].'.'.$temp[1]; |
|
| 921 | 921 | continue; |
| 922 | 922 | } |
| 923 | 923 | if (count($temp) === 3 && $temp[0] === $this->definition->getSchema() && $this->definition->hasRelation($temp[1])) { |
| 924 | - $r[] = $temp[1] . '.' . $temp[2]; |
|
| 924 | + $r[] = $temp[1].'.'.$temp[2]; |
|
| 925 | 925 | continue; |
| 926 | 926 | } |
| 927 | 927 | } |
@@ -940,9 +940,9 @@ discard block |
||
| 940 | 940 | } |
| 941 | 941 | $aliases = []; |
| 942 | 942 | $aliases_ext = []; |
| 943 | - $getAlias = function ($name) use (&$aliases, &$aliases_ext) { |
|
| 943 | + $getAlias = function($name) use (&$aliases, &$aliases_ext) { |
|
| 944 | 944 | // to bypass use: return $name; |
| 945 | - $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases); |
|
| 945 | + $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases); |
|
| 946 | 946 | if (isset($aliases_ext[$name])) { |
| 947 | 947 | unset($aliases_ext[$name]); |
| 948 | 948 | } |
@@ -967,7 +967,7 @@ discard block |
||
| 967 | 967 | $h = $this->having; |
| 968 | 968 | $o = $this->order; |
| 969 | 969 | $g = $this->group; |
| 970 | - $j = array_map(function ($v) { |
|
| 970 | + $j = array_map(function($v) { |
|
| 971 | 971 | return clone $v; |
| 972 | 972 | }, $this->joins); |
| 973 | 973 | |
@@ -982,11 +982,10 @@ discard block |
||
| 982 | 982 | } |
| 983 | 983 | $temp = []; |
| 984 | 984 | foreach ($f as $kk => $field) { |
| 985 | - if (strpos($field, $k . '.') === 0) { |
|
| 986 | - $f[$kk] = str_replace($k . '.', $getAlias($k) . '.', $field); |
|
| 985 | + if (strpos($field, $k.'.') === 0) { |
|
| 986 | + $f[$kk] = str_replace($k.'.', $getAlias($k).'.', $field); |
|
| 987 | 987 | $nk = $this->aliasColumns && is_numeric($kk) ? |
| 988 | - $getAlias($k . static::SEP . str_replace($k . '.', '', $field)) : |
|
| 989 | - $kk; |
|
| 988 | + $getAlias($k.static::SEP.str_replace($k.'.', '', $field)) : $kk; |
|
| 990 | 989 | $temp[$nk] = $f[$kk]; |
| 991 | 990 | } else { |
| 992 | 991 | $temp[$kk] = $field; |
@@ -994,27 +993,27 @@ discard block |
||
| 994 | 993 | } |
| 995 | 994 | $f = $temp; |
| 996 | 995 | foreach ($w as $kk => $v) { |
| 997 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) { |
|
| 998 | - $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]); |
|
| 996 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) { |
|
| 997 | + $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]); |
|
| 999 | 998 | } |
| 1000 | 999 | } |
| 1001 | 1000 | foreach ($h as $kk => $v) { |
| 1002 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) { |
|
| 1003 | - $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]); |
|
| 1001 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) { |
|
| 1002 | + $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]); |
|
| 1004 | 1003 | } |
| 1005 | 1004 | } |
| 1006 | - if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) { |
|
| 1007 | - $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]); |
|
| 1005 | + if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) { |
|
| 1006 | + $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]); |
|
| 1008 | 1007 | } |
| 1009 | - if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) { |
|
| 1010 | - $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]); |
|
| 1008 | + if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) { |
|
| 1009 | + $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]); |
|
| 1011 | 1010 | } |
| 1012 | 1011 | foreach ($j as $kk => $v) { |
| 1013 | 1012 | foreach ($v->keymap as $kkk => $vv) { |
| 1014 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) { |
|
| 1013 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) { |
|
| 1015 | 1014 | $j[$kk]->keymap[$kkk] = preg_replace( |
| 1016 | - '(\b'.preg_quote($k . '.'). ')i', |
|
| 1017 | - $getAlias($k) . '.', |
|
| 1015 | + '(\b'.preg_quote($k.'.').')i', |
|
| 1016 | + $getAlias($k).'.', |
|
| 1018 | 1017 | $vv |
| 1019 | 1018 | ); |
| 1020 | 1019 | } |
@@ -1024,12 +1023,11 @@ discard block |
||
| 1024 | 1023 | foreach ($this->definition->getRelations() as $k => $relation) { |
| 1025 | 1024 | $temp = []; |
| 1026 | 1025 | foreach ($f as $kk => $field) { |
| 1027 | - if (strpos($field, $k . '.') === 0) { |
|
| 1028 | - $relations[$k] = [ $relation, $table ]; |
|
| 1029 | - $f[$kk] = str_replace($k . '.', $getAlias($k) . '.', $field); |
|
| 1026 | + if (strpos($field, $k.'.') === 0) { |
|
| 1027 | + $relations[$k] = [$relation, $table]; |
|
| 1028 | + $f[$kk] = str_replace($k.'.', $getAlias($k).'.', $field); |
|
| 1030 | 1029 | $nk = $this->aliasColumns && is_numeric($kk) ? |
| 1031 | - $getAlias($k . static::SEP . str_replace($k . '.', '', $field)) : |
|
| 1032 | - $kk; |
|
| 1030 | + $getAlias($k.static::SEP.str_replace($k.'.', '', $field)) : $kk; |
|
| 1033 | 1031 | $temp[$nk] = $f[$kk]; |
| 1034 | 1032 | } else { |
| 1035 | 1033 | $temp[$kk] = $field; |
@@ -1037,32 +1035,32 @@ discard block |
||
| 1037 | 1035 | } |
| 1038 | 1036 | $f = $temp; |
| 1039 | 1037 | foreach ($w as $kk => $v) { |
| 1040 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) { |
|
| 1041 | - $relations[$k] = [ $relation, $table ]; |
|
| 1042 | - $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]); |
|
| 1038 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) { |
|
| 1039 | + $relations[$k] = [$relation, $table]; |
|
| 1040 | + $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]); |
|
| 1043 | 1041 | } |
| 1044 | 1042 | } |
| 1045 | 1043 | foreach ($h as $kk => $v) { |
| 1046 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) { |
|
| 1047 | - $relations[$k] = [ $relation, $table ]; |
|
| 1048 | - $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]); |
|
| 1044 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) { |
|
| 1045 | + $relations[$k] = [$relation, $table]; |
|
| 1046 | + $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]); |
|
| 1049 | 1047 | } |
| 1050 | 1048 | } |
| 1051 | - if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) { |
|
| 1052 | - $relations[$k] = [ $relation, $table ]; |
|
| 1053 | - $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]); |
|
| 1049 | + if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) { |
|
| 1050 | + $relations[$k] = [$relation, $table]; |
|
| 1051 | + $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]); |
|
| 1054 | 1052 | } |
| 1055 | - if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) { |
|
| 1056 | - $relations[$k] = [ $relation, $table ]; |
|
| 1057 | - $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]); |
|
| 1053 | + if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) { |
|
| 1054 | + $relations[$k] = [$relation, $table]; |
|
| 1055 | + $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]); |
|
| 1058 | 1056 | } |
| 1059 | 1057 | foreach ($j as $kk => $v) { |
| 1060 | 1058 | foreach ($v->keymap as $kkk => $vv) { |
| 1061 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) { |
|
| 1062 | - $relations[$k] = [ $relation, $table ]; |
|
| 1059 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) { |
|
| 1060 | + $relations[$k] = [$relation, $table]; |
|
| 1063 | 1061 | $j[$kk]->keymap[$kkk] = preg_replace( |
| 1064 | - '(\b'.preg_quote($k . '.'). ')i', |
|
| 1065 | - $getAlias($k) . '.', |
|
| 1062 | + '(\b'.preg_quote($k.'.').')i', |
|
| 1063 | + $getAlias($k).'.', |
|
| 1066 | 1064 | $vv |
| 1067 | 1065 | ); |
| 1068 | 1066 | } |
@@ -1072,11 +1070,10 @@ discard block |
||
| 1072 | 1070 | foreach ($aliases_ext as $k => $alias) { |
| 1073 | 1071 | $temp = []; |
| 1074 | 1072 | foreach ($f as $kk => $field) { |
| 1075 | - if (strpos($field, $k . '.') === 0) { |
|
| 1076 | - $f[$kk] = str_replace($k . '.', $alias . '.', $field); |
|
| 1073 | + if (strpos($field, $k.'.') === 0) { |
|
| 1074 | + $f[$kk] = str_replace($k.'.', $alias.'.', $field); |
|
| 1077 | 1075 | $nk = $this->aliasColumns && is_numeric($kk) ? |
| 1078 | - $getAlias($k . static::SEP . str_replace($k . '.', '', $field)) : |
|
| 1079 | - $kk; |
|
| 1076 | + $getAlias($k.static::SEP.str_replace($k.'.', '', $field)) : $kk; |
|
| 1080 | 1077 | $temp[$nk] = $f[$kk]; |
| 1081 | 1078 | } else { |
| 1082 | 1079 | $temp[$kk] = $field; |
@@ -1084,27 +1081,27 @@ discard block |
||
| 1084 | 1081 | } |
| 1085 | 1082 | $f = $temp; |
| 1086 | 1083 | foreach ($w as $kk => $v) { |
| 1087 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) { |
|
| 1088 | - $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $v[0]); |
|
| 1084 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) { |
|
| 1085 | + $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $v[0]); |
|
| 1089 | 1086 | } |
| 1090 | 1087 | } |
| 1091 | 1088 | foreach ($h as $kk => $v) { |
| 1092 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) { |
|
| 1093 | - $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $v[0]); |
|
| 1089 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) { |
|
| 1090 | + $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $v[0]); |
|
| 1094 | 1091 | } |
| 1095 | 1092 | } |
| 1096 | - if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) { |
|
| 1097 | - $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $o[0]); |
|
| 1093 | + if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) { |
|
| 1094 | + $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $o[0]); |
|
| 1098 | 1095 | } |
| 1099 | - if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) { |
|
| 1100 | - $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $g[0]); |
|
| 1096 | + if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) { |
|
| 1097 | + $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $g[0]); |
|
| 1101 | 1098 | } |
| 1102 | 1099 | foreach ($j as $kk => $v) { |
| 1103 | 1100 | foreach ($v->keymap as $kkk => $vv) { |
| 1104 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) { |
|
| 1101 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) { |
|
| 1105 | 1102 | $j[$kk]->keymap[$kkk] = preg_replace( |
| 1106 | - '(\b'.preg_quote($k . '.'). ')i', |
|
| 1107 | - $alias . '.', |
|
| 1103 | + '(\b'.preg_quote($k.'.').')i', |
|
| 1104 | + $alias.'.', |
|
| 1108 | 1105 | $vv |
| 1109 | 1106 | ); |
| 1110 | 1107 | } |
@@ -1115,14 +1112,14 @@ discard block |
||
| 1115 | 1112 | if ($relation[2]) { |
| 1116 | 1113 | if (!$this->manualColumns) { |
| 1117 | 1114 | foreach ($relation[0]->table->getColumns() as $column) { |
| 1118 | - if (!in_array($getAlias($name) . '.' . $column, $f)) { |
|
| 1119 | - $f[$getAlias($name . static::SEP . $column)] = $getAlias($name) . '.' . $column; |
|
| 1115 | + if (!in_array($getAlias($name).'.'.$column, $f)) { |
|
| 1116 | + $f[$getAlias($name.static::SEP.$column)] = $getAlias($name).'.'.$column; |
|
| 1120 | 1117 | } |
| 1121 | 1118 | } |
| 1122 | 1119 | } else { |
| 1123 | 1120 | foreach ($relation[0]->table->getPrimaryKey() as $column) { |
| 1124 | - if (!in_array($getAlias($name) . '.' . $column, $f)) { |
|
| 1125 | - $f[$getAlias($name . static::SEP . $column)] = $getAlias($name) . '.' . $column; |
|
| 1121 | + if (!in_array($getAlias($name).'.'.$column, $f)) { |
|
| 1122 | + $f[$getAlias($name.static::SEP.$column)] = $getAlias($name).'.'.$column; |
|
| 1126 | 1123 | } |
| 1127 | 1124 | } |
| 1128 | 1125 | } |
@@ -1130,7 +1127,7 @@ discard block |
||
| 1130 | 1127 | } |
| 1131 | 1128 | $select = []; |
| 1132 | 1129 | foreach ($f as $k => $field) { |
| 1133 | - $select[] = $field . (!is_numeric($k) ? ' ' . $k : ''); |
|
| 1130 | + $select[] = $field.(!is_numeric($k) ? ' '.$k : ''); |
|
| 1134 | 1131 | } |
| 1135 | 1132 | $sql = 'SELECT '.implode(', ', $select).' FROM '.$this->definition->getFullName().' '; |
| 1136 | 1133 | $par = []; |
@@ -1149,13 +1146,13 @@ discard block |
||
| 1149 | 1146 | foreach ($v->keymap as $kk => $vv) { |
| 1150 | 1147 | $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' '; |
| 1151 | 1148 | } |
| 1152 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
| 1149 | + $sql .= implode(' AND ', $tmp).' '; |
|
| 1153 | 1150 | $sql .= 'LEFT JOIN '.$v->table->getFullName().' '.$getAlias($relation).' ON '; |
| 1154 | 1151 | $tmp = []; |
| 1155 | 1152 | foreach ($v->pivot_keymap as $kk => $vv) { |
| 1156 | 1153 | $tmp[] = $getAlias($relation).'.'.$vv.' = '.$alias.'.'.$kk.' '; |
| 1157 | 1154 | } |
| 1158 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
| 1155 | + $sql .= implode(' AND ', $tmp).' '; |
|
| 1159 | 1156 | } else { |
| 1160 | 1157 | $alias = $getAlias($relation); |
| 1161 | 1158 | |
@@ -1165,22 +1162,22 @@ discard block |
||
| 1165 | 1162 | $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' '; |
| 1166 | 1163 | } |
| 1167 | 1164 | if ($v->sql) { |
| 1168 | - $tmp[] = $v->sql . ' '; |
|
| 1165 | + $tmp[] = $v->sql.' '; |
|
| 1169 | 1166 | $par = array_merge($par, $v->par ?? []); |
| 1170 | 1167 | } |
| 1171 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
| 1168 | + $sql .= implode(' AND ', $tmp).' '; |
|
| 1172 | 1169 | } |
| 1173 | 1170 | } |
| 1174 | 1171 | foreach ($j as $k => $v) { |
| 1175 | 1172 | if ($v->many) { |
| 1176 | 1173 | $many = true; |
| 1177 | 1174 | } |
| 1178 | - $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getFullName().' '.$k.' ON '; |
|
| 1175 | + $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getFullName().' '.$k.' ON '; |
|
| 1179 | 1176 | $tmp = []; |
| 1180 | 1177 | foreach ($v->keymap as $kk => $vv) { |
| 1181 | 1178 | $tmp[] = $kk.' = '.$vv; |
| 1182 | 1179 | } |
| 1183 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
| 1180 | + $sql .= implode(' AND ', $tmp).' '; |
|
| 1184 | 1181 | } |
| 1185 | 1182 | if ($many && count($porder) && $this->li_mt) { |
| 1186 | 1183 | $ids = $this->ids(); |
@@ -1188,9 +1185,9 @@ discard block |
||
| 1188 | 1185 | if (count($porder) > 1) { |
| 1189 | 1186 | $pkw = []; |
| 1190 | 1187 | foreach ($porder as $name) { |
| 1191 | - $pkw[] = $name . ' = ?'; |
|
| 1188 | + $pkw[] = $name.' = ?'; |
|
| 1192 | 1189 | } |
| 1193 | - $pkw = '(' . implode(' AND ', $pkw) . ')'; |
|
| 1190 | + $pkw = '('.implode(' AND ', $pkw).')'; |
|
| 1194 | 1191 | $pkp = []; |
| 1195 | 1192 | foreach ($ids as $id) { |
| 1196 | 1193 | foreach ($id as $p) { |
@@ -1202,60 +1199,60 @@ discard block |
||
| 1202 | 1199 | $pkp |
| 1203 | 1200 | ]; |
| 1204 | 1201 | } else { |
| 1205 | - $w[] = [ $porder[0] . ' IN ('.implode(',', array_fill(0, count($ids), '?')).')', $ids ]; |
|
| 1202 | + $w[] = [$porder[0].' IN ('.implode(',', array_fill(0, count($ids), '?')).')', $ids]; |
|
| 1206 | 1203 | } |
| 1207 | 1204 | } else { |
| 1208 | - $w[] = [ '1=0', [] ]; |
|
| 1205 | + $w[] = ['1=0', []]; |
|
| 1209 | 1206 | } |
| 1210 | 1207 | } |
| 1211 | 1208 | if (count($w)) { |
| 1212 | 1209 | $sql .= 'WHERE '; |
| 1213 | 1210 | $tmp = []; |
| 1214 | 1211 | foreach ($w as $v) { |
| 1215 | - $tmp[] = '(' . $v[0] . ')'; |
|
| 1212 | + $tmp[] = '('.$v[0].')'; |
|
| 1216 | 1213 | $par = array_merge($par, $v[1]); |
| 1217 | 1214 | } |
| 1218 | 1215 | $sql .= implode(' AND ', $tmp).' '; |
| 1219 | 1216 | } |
| 1220 | 1217 | if (count($g)) { |
| 1221 | - $sql .= 'GROUP BY ' . $g[0] . ' '; |
|
| 1218 | + $sql .= 'GROUP BY '.$g[0].' '; |
|
| 1222 | 1219 | $par = array_merge($par, $g[1]); |
| 1223 | 1220 | } |
| 1224 | 1221 | if (count($h)) { |
| 1225 | 1222 | $sql .= 'HAVING '; |
| 1226 | 1223 | $tmp = []; |
| 1227 | 1224 | foreach ($h as $v) { |
| 1228 | - $tmp[] = '(' . $v[0] . ')'; |
|
| 1225 | + $tmp[] = '('.$v[0].')'; |
|
| 1229 | 1226 | $par = array_merge($par, $v[1]); |
| 1230 | 1227 | } |
| 1231 | 1228 | $sql .= implode(' AND ', $tmp).' '; |
| 1232 | 1229 | } |
| 1233 | 1230 | $ordered = false; |
| 1234 | 1231 | if (count($o)) { |
| 1235 | - $sql .= 'ORDER BY ' . $o[0] . ' '; |
|
| 1232 | + $sql .= 'ORDER BY '.$o[0].' '; |
|
| 1236 | 1233 | $par = array_merge($par, $o[1]); |
| 1237 | 1234 | $ordered = true; |
| 1238 | 1235 | } |
| 1239 | 1236 | if (!count($g) && count($porder)) { |
| 1240 | 1237 | $pdir = (count($o) && strpos($o[0], 'DESC') !== false) ? 'DESC' : 'ASC'; |
| 1241 | - $porder = array_map(function ($v) use ($pdir) { |
|
| 1242 | - return $v . ' ' . $pdir; |
|
| 1238 | + $porder = array_map(function($v) use ($pdir) { |
|
| 1239 | + return $v.' '.$pdir; |
|
| 1243 | 1240 | }, $porder); |
| 1244 | - $sql .= ($ordered ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' '; |
|
| 1241 | + $sql .= ($ordered ? ', ' : 'ORDER BY ').implode(', ', $porder).' '; |
|
| 1245 | 1242 | $ordered = true; |
| 1246 | 1243 | } |
| 1247 | 1244 | foreach ($this->withr as $k => $v) { |
| 1248 | 1245 | if (isset($v[3])) { |
| 1249 | - $sql .= ($ordered ? ', ' : 'ORDER BY ') . $getAlias($k) . '.' . $v[3] . ' ' . ($v[4] ? 'DESC' : 'ASC'); |
|
| 1246 | + $sql .= ($ordered ? ', ' : 'ORDER BY ').$getAlias($k).'.'.$v[3].' '.($v[4] ? 'DESC' : 'ASC'); |
|
| 1250 | 1247 | $ordered = true; |
| 1251 | 1248 | } |
| 1252 | 1249 | } |
| 1253 | 1250 | if ((!$many || !$this->li_mt || !count($porder)) && $this->li_of[0]) { |
| 1254 | 1251 | if ($this->db->driverName() === 'oracle') { |
| 1255 | - if ((int)$this->db->driverOption('version', 0) >= 12) { |
|
| 1256 | - $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY'; |
|
| 1252 | + if ((int) $this->db->driverOption('version', 0) >= 12) { |
|
| 1253 | + $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY'; |
|
| 1257 | 1254 | } else { |
| 1258 | - $f = array_map(function ($v) { |
|
| 1255 | + $f = array_map(function($v) { |
|
| 1259 | 1256 | $v = explode(' ', trim($v), 2); |
| 1260 | 1257 | if (count($v) === 2) { |
| 1261 | 1258 | return $v[1]; |
@@ -1263,16 +1260,16 @@ discard block |
||
| 1263 | 1260 | $v = explode('.', $v[0], 2); |
| 1264 | 1261 | return count($v) === 2 ? $v[1] : $v[0]; |
| 1265 | 1262 | }, $select); |
| 1266 | - $sql = "SELECT " . implode(', ', $f) . " |
|
| 1263 | + $sql = "SELECT ".implode(', ', $f)." |
|
| 1267 | 1264 | FROM ( |
| 1268 | 1265 | SELECT tbl__.*, rownum rnum__ FROM ( |
| 1269 | - " . $sql . " |
|
| 1266 | + " . $sql." |
|
| 1270 | 1267 | ) tbl__ |
| 1271 | - WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . " |
|
| 1268 | + WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])." |
|
| 1272 | 1269 | ) WHERE rnum__ > " . $this->li_of[1]; |
| 1273 | 1270 | } |
| 1274 | 1271 | } else { |
| 1275 | - $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1]; |
|
| 1272 | + $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1]; |
|
| 1276 | 1273 | } |
| 1277 | 1274 | } |
| 1278 | 1275 | return $this->qiterator = new TableQueryIterator( |
@@ -1322,12 +1319,12 @@ discard block |
||
| 1322 | 1319 | $ret[$k] = str_repeat(' ', 255); |
| 1323 | 1320 | $par[] = &$ret[$k]; |
| 1324 | 1321 | } |
| 1325 | - $sql .= ' RETURNING ' . implode(',', $primary) . |
|
| 1326 | - ' INTO ' . implode(',', array_fill(0, count($primary), '?')); |
|
| 1322 | + $sql .= ' RETURNING '.implode(',', $primary). |
|
| 1323 | + ' INTO '.implode(',', array_fill(0, count($primary), '?')); |
|
| 1327 | 1324 | $this->db->query($sql, $par); |
| 1328 | 1325 | return $ret; |
| 1329 | 1326 | } elseif ($this->db->driverName() === 'postgre') { |
| 1330 | - $sql .= ' RETURNING ' . implode(',', $primary); |
|
| 1327 | + $sql .= ' RETURNING '.implode(',', $primary); |
|
| 1331 | 1328 | return $this->db->one($sql, $par, false); |
| 1332 | 1329 | } else { |
| 1333 | 1330 | $ret = []; |
@@ -1358,9 +1355,9 @@ discard block |
||
| 1358 | 1355 | } |
| 1359 | 1356 | $sql = 'UPDATE '.$table.' SET '; |
| 1360 | 1357 | $par = []; |
| 1361 | - $sql .= implode(', ', array_map(function ($v) { |
|
| 1362 | - return $v . ' = ?'; |
|
| 1363 | - }, array_keys($update))) . ' '; |
|
| 1358 | + $sql .= implode(', ', array_map(function($v) { |
|
| 1359 | + return $v.' = ?'; |
|
| 1360 | + }, array_keys($update))).' '; |
|
| 1364 | 1361 | $par = array_merge($par, array_values($update)); |
| 1365 | 1362 | if (count($this->where)) { |
| 1366 | 1363 | $sql .= 'WHERE '; |
@@ -1369,7 +1366,7 @@ discard block |
||
| 1369 | 1366 | $tmp[] = $v[0]; |
| 1370 | 1367 | $par = array_merge($par, $v[1]); |
| 1371 | 1368 | } |
| 1372 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
| 1369 | + $sql .= implode(' AND ', $tmp).' '; |
|
| 1373 | 1370 | } |
| 1374 | 1371 | if (count($this->order)) { |
| 1375 | 1372 | $sql .= $this->order[0]; |
@@ -1393,7 +1390,7 @@ discard block |
||
| 1393 | 1390 | $tmp[] = $v[0]; |
| 1394 | 1391 | $par = array_merge($par, $v[1]); |
| 1395 | 1392 | } |
| 1396 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
| 1393 | + $sql .= implode(' AND ', $tmp).' '; |
|
| 1397 | 1394 | } |
| 1398 | 1395 | if (count($this->order)) { |
| 1399 | 1396 | $sql .= $this->order[0]; |
@@ -1424,15 +1421,15 @@ discard block |
||
| 1424 | 1421 | try { |
| 1425 | 1422 | $name = array_reduce( |
| 1426 | 1423 | $parts, |
| 1427 | - function ($carry, $item) use (&$table, $select) { |
|
| 1424 | + function($carry, $item) use (&$table, $select) { |
|
| 1428 | 1425 | if (!$table->hasRelation($item)) { |
| 1429 | - throw new DBException('Invalid relation name: '.$table->getName().' -> ' . $item); |
|
| 1426 | + throw new DBException('Invalid relation name: '.$table->getName().' -> '.$item); |
|
| 1430 | 1427 | } |
| 1431 | 1428 | $relation = $table->getRelation($item); |
| 1432 | 1429 | if (!$relation) { |
| 1433 | - throw new DBException('Invalid relation name: '.$table->getName().' -> ' . $item); |
|
| 1430 | + throw new DBException('Invalid relation name: '.$table->getName().' -> '.$item); |
|
| 1434 | 1431 | } |
| 1435 | - $name = $carry ? $carry . static::SEP . $item : $item; |
|
| 1432 | + $name = $carry ? $carry.static::SEP.$item : $item; |
|
| 1436 | 1433 | $this->withr[$name] = [ |
| 1437 | 1434 | $relation, |
| 1438 | 1435 | $carry ?? $table->getName(), |
@@ -1501,9 +1498,9 @@ discard block |
||
| 1501 | 1498 | |
| 1502 | 1499 | $aliases = []; |
| 1503 | 1500 | $aliases_ext = []; |
| 1504 | - $getAlias = function ($name) use (&$aliases, &$aliases_ext) { |
|
| 1501 | + $getAlias = function($name) use (&$aliases, &$aliases_ext) { |
|
| 1505 | 1502 | // to bypass use: return $name; |
| 1506 | - $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases); |
|
| 1503 | + $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases); |
|
| 1507 | 1504 | if (isset($aliases_ext[$name])) { |
| 1508 | 1505 | unset($aliases_ext[$name]); |
| 1509 | 1506 | } |
@@ -1523,7 +1520,7 @@ discard block |
||
| 1523 | 1520 | $w = $this->where; |
| 1524 | 1521 | $h = $this->having; |
| 1525 | 1522 | $o = $this->order; |
| 1526 | - $j = array_map(function ($v) { |
|
| 1523 | + $j = array_map(function($v) { |
|
| 1527 | 1524 | return clone $v; |
| 1528 | 1525 | }, $this->joins); |
| 1529 | 1526 | |
@@ -1532,24 +1529,24 @@ discard block |
||
| 1532 | 1529 | continue; |
| 1533 | 1530 | } |
| 1534 | 1531 | foreach ($w as $kk => $v) { |
| 1535 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) { |
|
| 1536 | - $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]); |
|
| 1532 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) { |
|
| 1533 | + $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]); |
|
| 1537 | 1534 | } |
| 1538 | 1535 | } |
| 1539 | 1536 | foreach ($h as $kk => $v) { |
| 1540 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) { |
|
| 1541 | - $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]); |
|
| 1537 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) { |
|
| 1538 | + $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]); |
|
| 1542 | 1539 | } |
| 1543 | 1540 | } |
| 1544 | - if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) { |
|
| 1545 | - $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]); |
|
| 1541 | + if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) { |
|
| 1542 | + $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]); |
|
| 1546 | 1543 | } |
| 1547 | 1544 | foreach ($j as $kk => $v) { |
| 1548 | 1545 | foreach ($v->keymap as $kkk => $vv) { |
| 1549 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) { |
|
| 1546 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) { |
|
| 1550 | 1547 | $j[$kk]->keymap[$kkk] = preg_replace( |
| 1551 | - '(\b'.preg_quote($k . '.'). ')i', |
|
| 1552 | - $getAlias($k) . '.', |
|
| 1548 | + '(\b'.preg_quote($k.'.').')i', |
|
| 1549 | + $getAlias($k).'.', |
|
| 1553 | 1550 | $vv |
| 1554 | 1551 | ); |
| 1555 | 1552 | } |
@@ -1558,52 +1555,52 @@ discard block |
||
| 1558 | 1555 | } |
| 1559 | 1556 | foreach ($this->definition->getRelations() as $k => $v) { |
| 1560 | 1557 | foreach ($w as $kk => $vv) { |
| 1561 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) { |
|
| 1562 | - $relations[$k] = [ $v, $table ]; |
|
| 1563 | - $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]); |
|
| 1558 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) { |
|
| 1559 | + $relations[$k] = [$v, $table]; |
|
| 1560 | + $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]); |
|
| 1564 | 1561 | } |
| 1565 | 1562 | } |
| 1566 | - if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) { |
|
| 1567 | - $relations[$k] = [ $v, $table ]; |
|
| 1568 | - $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]); |
|
| 1569 | - $o[2] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[2]); |
|
| 1563 | + if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) { |
|
| 1564 | + $relations[$k] = [$v, $table]; |
|
| 1565 | + $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]); |
|
| 1566 | + $o[2] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[2]); |
|
| 1570 | 1567 | } |
| 1571 | 1568 | foreach ($h as $kk => $vv) { |
| 1572 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) { |
|
| 1573 | - $relations[$k] = [ $v, $table ]; |
|
| 1574 | - $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]); |
|
| 1569 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) { |
|
| 1570 | + $relations[$k] = [$v, $table]; |
|
| 1571 | + $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]); |
|
| 1575 | 1572 | } |
| 1576 | 1573 | } |
| 1577 | 1574 | foreach ($j as $kk => $vv) { |
| 1578 | 1575 | foreach ($vv->keymap as $kkk => $vvv) { |
| 1579 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vvv)) { |
|
| 1580 | - $relations[$k] = [ $v, $table ]; |
|
| 1576 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $vvv)) { |
|
| 1577 | + $relations[$k] = [$v, $table]; |
|
| 1581 | 1578 | $j[$kk]->keymap[$kkk] = |
| 1582 | - preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vvv); |
|
| 1579 | + preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vvv); |
|
| 1583 | 1580 | } |
| 1584 | 1581 | } |
| 1585 | 1582 | } |
| 1586 | 1583 | } |
| 1587 | 1584 | foreach ($aliases_ext as $k => $alias) { |
| 1588 | 1585 | foreach ($w as $kk => $v) { |
| 1589 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) { |
|
| 1590 | - $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $v[0]); |
|
| 1586 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) { |
|
| 1587 | + $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $v[0]); |
|
| 1591 | 1588 | } |
| 1592 | 1589 | } |
| 1593 | 1590 | foreach ($h as $kk => $v) { |
| 1594 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) { |
|
| 1595 | - $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $v[0]); |
|
| 1591 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) { |
|
| 1592 | + $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $v[0]); |
|
| 1596 | 1593 | } |
| 1597 | 1594 | } |
| 1598 | - if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) { |
|
| 1599 | - $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $o[0]); |
|
| 1595 | + if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) { |
|
| 1596 | + $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $o[0]); |
|
| 1600 | 1597 | } |
| 1601 | 1598 | foreach ($j as $kk => $v) { |
| 1602 | 1599 | foreach ($v->keymap as $kkk => $vv) { |
| 1603 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) { |
|
| 1600 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) { |
|
| 1604 | 1601 | $j[$kk]->keymap[$kkk] = preg_replace( |
| 1605 | - '(\b'.preg_quote($k . '.'). ')i', |
|
| 1606 | - $alias . '.', |
|
| 1602 | + '(\b'.preg_quote($k.'.').')i', |
|
| 1603 | + $alias.'.', |
|
| 1607 | 1604 | $vv |
| 1608 | 1605 | ); |
| 1609 | 1606 | } |
@@ -1611,29 +1608,29 @@ discard block |
||
| 1611 | 1608 | } |
| 1612 | 1609 | } |
| 1613 | 1610 | |
| 1614 | - $key = array_map(function ($v) use ($table) { |
|
| 1615 | - return $table . '.' . $v; |
|
| 1611 | + $key = array_map(function($v) use ($table) { |
|
| 1612 | + return $table.'.'.$v; |
|
| 1616 | 1613 | }, $this->pkey); |
| 1617 | 1614 | $own = false; |
| 1618 | 1615 | $dir = 'ASC'; |
| 1619 | 1616 | if (count($o)) { |
| 1620 | 1617 | $dir = strpos($o[0], ' DESC') ? 'DESC' : 'ASC'; |
| 1621 | - $own = strpos($o[2], $table . '.') === 0; |
|
| 1618 | + $own = strpos($o[2], $table.'.') === 0; |
|
| 1622 | 1619 | } |
| 1623 | 1620 | |
| 1624 | 1621 | $dst = $key; |
| 1625 | 1622 | if (count($o)) { |
| 1626 | 1623 | if ($own) { |
| 1627 | 1624 | // if using own table - do not use max/min in order - that will prevent index usage |
| 1628 | - $dst[] = $o[2] . ' orderbyfix___'; |
|
| 1625 | + $dst[] = $o[2].' orderbyfix___'; |
|
| 1629 | 1626 | } else { |
| 1630 | - $dst[] = 'MAX(' . $o[2] . ') orderbyfix___'; |
|
| 1627 | + $dst[] = 'MAX('.$o[2].') orderbyfix___'; |
|
| 1631 | 1628 | } |
| 1632 | 1629 | } |
| 1633 | 1630 | $dst = array_unique($dst); |
| 1634 | 1631 | |
| 1635 | 1632 | $par = []; |
| 1636 | - $sql = 'SELECT DISTINCT '.implode(', ', $dst).' FROM '.$this->definition->getFullName().' '; |
|
| 1633 | + $sql = 'SELECT DISTINCT '.implode(', ', $dst).' FROM '.$this->definition->getFullName().' '; |
|
| 1637 | 1634 | foreach ($relations as $k => $v) { |
| 1638 | 1635 | $table = $v[1] !== $this->definition->getName() ? $getAlias($v[1]) : $v[1]; |
| 1639 | 1636 | $v = $v[0]; |
@@ -1644,13 +1641,13 @@ discard block |
||
| 1644 | 1641 | foreach ($v->keymap as $kk => $vv) { |
| 1645 | 1642 | $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' '; |
| 1646 | 1643 | } |
| 1647 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
| 1644 | + $sql .= implode(' AND ', $tmp).' '; |
|
| 1648 | 1645 | $sql .= 'LEFT JOIN '.$v->table->getFullName().' '.$getAlias($k).' ON '; |
| 1649 | 1646 | $tmp = []; |
| 1650 | 1647 | foreach ($v->pivot_keymap as $kk => $vv) { |
| 1651 | 1648 | $tmp[] = $getAlias($k).'.'.$vv.' = '.$alias.'.'.$kk.' '; |
| 1652 | 1649 | } |
| 1653 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
| 1650 | + $sql .= implode(' AND ', $tmp).' '; |
|
| 1654 | 1651 | } else { |
| 1655 | 1652 | $alias = $getAlias($k); |
| 1656 | 1653 | $sql .= 'LEFT JOIN '.$v->table->getFullName().' '.$alias.' ON '; |
@@ -1659,37 +1656,37 @@ discard block |
||
| 1659 | 1656 | $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' '; |
| 1660 | 1657 | } |
| 1661 | 1658 | if ($v->sql) { |
| 1662 | - $tmp[] = $v->sql . ' '; |
|
| 1659 | + $tmp[] = $v->sql.' '; |
|
| 1663 | 1660 | $par = array_merge($par, $v->par ?? []); |
| 1664 | 1661 | } |
| 1665 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
| 1662 | + $sql .= implode(' AND ', $tmp).' '; |
|
| 1666 | 1663 | } |
| 1667 | 1664 | } |
| 1668 | 1665 | foreach ($j as $k => $v) { |
| 1669 | - $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getFullName().' '.$k.' ON '; |
|
| 1666 | + $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getFullName().' '.$k.' ON '; |
|
| 1670 | 1667 | $tmp = []; |
| 1671 | 1668 | foreach ($v->keymap as $kk => $vv) { |
| 1672 | 1669 | $tmp[] = $kk.' = '.$vv; |
| 1673 | 1670 | } |
| 1674 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
| 1671 | + $sql .= implode(' AND ', $tmp).' '; |
|
| 1675 | 1672 | } |
| 1676 | 1673 | if (count($w)) { |
| 1677 | 1674 | $sql .= 'WHERE '; |
| 1678 | 1675 | $tmp = []; |
| 1679 | 1676 | foreach ($w as $v) { |
| 1680 | - $tmp[] = '(' . $v[0] . ')'; |
|
| 1677 | + $tmp[] = '('.$v[0].')'; |
|
| 1681 | 1678 | $par = array_merge($par, $v[1]); |
| 1682 | 1679 | } |
| 1683 | 1680 | $sql .= implode(' AND ', $tmp).' '; |
| 1684 | 1681 | } |
| 1685 | 1682 | if (!$own) { |
| 1686 | - $sql .= 'GROUP BY ' . implode(', ', $key) . ' '; |
|
| 1683 | + $sql .= 'GROUP BY '.implode(', ', $key).' '; |
|
| 1687 | 1684 | } |
| 1688 | 1685 | if (count($h)) { |
| 1689 | 1686 | $sql .= 'HAVING '; |
| 1690 | 1687 | $tmp = []; |
| 1691 | 1688 | foreach ($h as $v) { |
| 1692 | - $tmp[] = '(' . $v[0] . ')'; |
|
| 1689 | + $tmp[] = '('.$v[0].')'; |
|
| 1693 | 1690 | $par = array_merge($par, $v[1]); |
| 1694 | 1691 | } |
| 1695 | 1692 | $sql .= implode(' AND ', $tmp).' '; |
@@ -1697,38 +1694,38 @@ discard block |
||
| 1697 | 1694 | if (count($o)) { |
| 1698 | 1695 | $sql .= 'ORDER BY '; |
| 1699 | 1696 | if ($own) { |
| 1700 | - $sql .= $o[2] . ' ' . $dir; |
|
| 1697 | + $sql .= $o[2].' '.$dir; |
|
| 1701 | 1698 | } else { |
| 1702 | - $sql .= 'MAX('.$o[2].') ' . $dir; |
|
| 1699 | + $sql .= 'MAX('.$o[2].') '.$dir; |
|
| 1703 | 1700 | } |
| 1704 | 1701 | } |
| 1705 | 1702 | $porder = []; |
| 1706 | 1703 | $pdir = (count($o) && strpos($o[0], 'DESC') !== false) ? 'DESC' : 'ASC'; |
| 1707 | 1704 | foreach ($this->definition->getPrimaryKey() as $field) { |
| 1708 | - $porder[] = $this->getColumn($field)['name'] . ' ' . $pdir; |
|
| 1705 | + $porder[] = $this->getColumn($field)['name'].' '.$pdir; |
|
| 1709 | 1706 | } |
| 1710 | 1707 | if (count($porder)) { |
| 1711 | - $sql .= (count($o) ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' '; |
|
| 1708 | + $sql .= (count($o) ? ', ' : 'ORDER BY ').implode(', ', $porder).' '; |
|
| 1712 | 1709 | } |
| 1713 | 1710 | |
| 1714 | 1711 | if ($this->li_of[0]) { |
| 1715 | 1712 | if ($this->db->driverName() === 'oracle') { |
| 1716 | - if ((int)$this->db->driverOption('version', 12) >= 12) { |
|
| 1717 | - $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY'; |
|
| 1713 | + if ((int) $this->db->driverOption('version', 12) >= 12) { |
|
| 1714 | + $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY'; |
|
| 1718 | 1715 | } else { |
| 1719 | - $sql = "SELECT " . implode(', ', $dst) . " |
|
| 1716 | + $sql = "SELECT ".implode(', ', $dst)." |
|
| 1720 | 1717 | FROM ( |
| 1721 | 1718 | SELECT tbl__.*, rownum rnum__ FROM ( |
| 1722 | - " . $sql . " |
|
| 1719 | + " . $sql." |
|
| 1723 | 1720 | ) tbl__ |
| 1724 | - WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . " |
|
| 1721 | + WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])." |
|
| 1725 | 1722 | ) WHERE rnum__ > " . $this->li_of[1]; |
| 1726 | 1723 | } |
| 1727 | 1724 | } else { |
| 1728 | - $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1]; |
|
| 1725 | + $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1]; |
|
| 1729 | 1726 | } |
| 1730 | 1727 | } |
| 1731 | - return array_map(function ($v) { |
|
| 1728 | + return array_map(function($v) { |
|
| 1732 | 1729 | if (array_key_exists('orderbyfix___', $v)) { |
| 1733 | 1730 | unset($v['orderbyfix___']); |
| 1734 | 1731 | } |