@@ -124,7 +124,7 @@ |
||
124 | 124 | } |
125 | 125 | return $new; |
126 | 126 | }) |
127 | - as $relation |
|
127 | + as $relation |
|
128 | 128 | ) { |
129 | 129 | $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_NAME']; |
130 | 130 | $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int)$relation['POSITION']-1]] = |
@@ -29,19 +29,19 @@ discard block |
||
29 | 29 | $columns = Collection::from($this |
30 | 30 | ->query( |
31 | 31 | "SELECT * FROM all_tab_cols WHERE table_name = ? AND owner = ?", |
32 | - [ strtoupper($table), $this->name() ] |
|
32 | + [strtoupper($table), $this->name()] |
|
33 | 33 | )) |
34 | - ->map(function ($v) { |
|
34 | + ->map(function($v) { |
|
35 | 35 | $new = []; |
36 | 36 | foreach ($v as $kk => $vv) { |
37 | 37 | $new[strtoupper($kk)] = $vv; |
38 | 38 | } |
39 | 39 | return $new; |
40 | 40 | }) |
41 | - ->mapKey(function ($v) { |
|
41 | + ->mapKey(function($v) { |
|
42 | 42 | return $v['COLUMN_NAME']; |
43 | 43 | }) |
44 | - ->map(function ($v) { |
|
44 | + ->map(function($v) { |
|
45 | 45 | $v['length'] = null; |
46 | 46 | if (!isset($v['DATA_TYPE'])) { |
47 | 47 | return $v; |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | default: |
54 | 54 | if (strpos($type, 'char') !== false && strpos($type, '(') !== false) { |
55 | 55 | // extract length from varchar |
56 | - $v['length'] = (int)explode(')', (explode('(', $type)[1] ?? ''))[0]; |
|
56 | + $v['length'] = (int) explode(')', (explode('(', $type)[1] ?? ''))[0]; |
|
57 | 57 | $v['length'] = $v['length'] > 0 ? $v['length'] : null; |
58 | 58 | } |
59 | 59 | break; |
@@ -69,9 +69,9 @@ discard block |
||
69 | 69 | ->query( |
70 | 70 | "SELECT constraint_name FROM all_constraints |
71 | 71 | WHERE table_name = ? AND constraint_type = ? AND owner = ?", |
72 | - [ strtoupper($table), 'P', $owner ] |
|
72 | + [strtoupper($table), 'P', $owner] |
|
73 | 73 | )) |
74 | - ->map(function ($v) { |
|
74 | + ->map(function($v) { |
|
75 | 75 | $new = []; |
76 | 76 | foreach ($v as $kk => $vv) { |
77 | 77 | $new[strtoupper($kk)] = $vv; |
@@ -86,9 +86,9 @@ discard block |
||
86 | 86 | ->query( |
87 | 87 | "SELECT column_name FROM all_cons_columns |
88 | 88 | WHERE table_name = ? AND constraint_name = ? AND owner = ?", |
89 | - [ strtoupper($table), $pkname, $owner ] |
|
89 | + [strtoupper($table), $pkname, $owner] |
|
90 | 90 | )) |
91 | - ->map(function ($v) { |
|
91 | + ->map(function($v) { |
|
92 | 92 | $new = []; |
93 | 93 | foreach ($v as $kk => $vv) { |
94 | 94 | $new[strtoupper($kk)] = $vv; |
@@ -115,9 +115,9 @@ discard block |
||
115 | 115 | LEFT JOIN all_cons_columns cc ON cc.OWNER = ac.OWNER AND cc.CONSTRAINT_NAME = ac.CONSTRAINT_NAME |
116 | 116 | WHERE ac.OWNER = ? AND ac.R_OWNER = ? AND ac.R_CONSTRAINT_NAME = ? AND ac.CONSTRAINT_TYPE = ? |
117 | 117 | ORDER BY cc.POSITION", |
118 | - [ $owner, $owner, $pkname, 'R' ] |
|
118 | + [$owner, $owner, $pkname, 'R'] |
|
119 | 119 | )) |
120 | - ->map(function ($v) { |
|
120 | + ->map(function($v) { |
|
121 | 121 | $new = []; |
122 | 122 | foreach ($v as $kk => $vv) { |
123 | 123 | $new[strtoupper($kk)] = $vv; |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | as $relation |
128 | 128 | ) { |
129 | 129 | $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_NAME']; |
130 | - $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int)$relation['POSITION']-1]] = |
|
130 | + $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int) $relation['POSITION'] - 1]] = |
|
131 | 131 | $relation['COLUMN_NAME']; |
132 | 132 | } |
133 | 133 | foreach ($relations as $data) { |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | ac.OWNER = ? AND ac.R_OWNER = ? AND ac.TABLE_NAME = ? AND ac.CONSTRAINT_TYPE = ? AND |
158 | 158 | cc.COLUMN_NAME IN (??) |
159 | 159 | ORDER BY POSITION", |
160 | - [ $owner, $owner, $data['table'], 'R', $columns ] |
|
160 | + [$owner, $owner, $data['table'], 'R', $columns] |
|
161 | 161 | )) |
162 | - ->map(function ($v) { |
|
162 | + ->map(function($v) { |
|
163 | 163 | $new = []; |
164 | 164 | foreach ($v as $kk => $vv) { |
165 | 165 | $new[strtoupper($kk)] = $vv; |
@@ -179,9 +179,9 @@ discard block |
||
179 | 179 | ->query( |
180 | 180 | "SELECT COLUMN_NAME FROM all_cons_columns |
181 | 181 | WHERE OWNER = ? AND CONSTRAINT_NAME = ? ORDER BY POSITION", |
182 | - [ $owner, current($foreign['keymap']) ] |
|
182 | + [$owner, current($foreign['keymap'])] |
|
183 | 183 | )) |
184 | - ->map(function ($v) { |
|
184 | + ->map(function($v) { |
|
185 | 185 | $new = []; |
186 | 186 | foreach ($v as $kk => $vv) { |
187 | 187 | $new[strtoupper($kk)] = $vv; |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | $relname = $foreign['table']; |
197 | 197 | $cntr = 1; |
198 | 198 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
199 | - $relname = $foreign['table'] . '_' . (++ $cntr); |
|
199 | + $relname = $foreign['table'].'_'.(++$cntr); |
|
200 | 200 | } |
201 | 201 | $definition->addRelation( |
202 | 202 | new TableRelation( |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | $relname = $data['table']; |
213 | 213 | $cntr = 1; |
214 | 214 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
215 | - $relname = $data['table'] . '_' . (++ $cntr); |
|
215 | + $relname = $data['table'].'_'.(++$cntr); |
|
216 | 216 | } |
217 | 217 | $definition->addRelation( |
218 | 218 | new TableRelation( |
@@ -240,9 +240,9 @@ discard block |
||
240 | 240 | LEFT JOIN all_cons_columns cc ON cc.OWNER = ac.OWNER AND cc.CONSTRAINT_NAME = ac.CONSTRAINT_NAME |
241 | 241 | WHERE ac.OWNER = ? AND ac.R_OWNER = ? AND ac.TABLE_NAME = ? AND ac.CONSTRAINT_TYPE = ? |
242 | 242 | ORDER BY cc.POSITION", |
243 | - [ $owner, $owner, strtoupper($table), 'R' ] |
|
243 | + [$owner, $owner, strtoupper($table), 'R'] |
|
244 | 244 | )) |
245 | - ->map(function ($v) { |
|
245 | + ->map(function($v) { |
|
246 | 246 | $new = []; |
247 | 247 | foreach ($v as $kk => $vv) { |
248 | 248 | $new[strtoupper($kk)] = $vv; |
@@ -260,9 +260,9 @@ discard block |
||
260 | 260 | ->query( |
261 | 261 | "SELECT COLUMN_NAME FROM all_cons_columns |
262 | 262 | WHERE OWNER = ? AND CONSTRAINT_NAME = ? ORDER BY POSITION", |
263 | - [ $owner, current($data['keymap']) ] |
|
263 | + [$owner, current($data['keymap'])] |
|
264 | 264 | )) |
265 | - ->map(function ($v) { |
|
265 | + ->map(function($v) { |
|
266 | 266 | $new = []; |
267 | 267 | foreach ($v as $kk => $vv) { |
268 | 268 | $new[strtoupper($kk)] = $vv; |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | $relname = $data['table']; |
278 | 278 | $cntr = 1; |
279 | 279 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
280 | - $relname = $data['table'] . '_' . (++ $cntr); |
|
280 | + $relname = $data['table'].'_'.(++$cntr); |
|
281 | 281 | } |
282 | 282 | $definition->addRelation( |
283 | 283 | new TableRelation( |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | "SELECT TABLE_NAME FROM ALL_TABLES where OWNER = ?", |
299 | 299 | [$this->connection['name']] |
300 | 300 | )) |
301 | - ->map(function ($v) { |
|
301 | + ->map(function($v) { |
|
302 | 302 | $new = []; |
303 | 303 | foreach ($v as $kk => $vv) { |
304 | 304 | $new[strtoupper($kk)] = $vv; |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | return $new; |
307 | 307 | }) |
308 | 308 | ->pluck('TABLE_NAME') |
309 | - ->map(function ($v) { |
|
309 | + ->map(function($v) { |
|
310 | 310 | return $this->table($v); |
311 | 311 | }) |
312 | 312 | ->toArray(); |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | $connection['pass'] = isset($temp['pass']) && strlen($temp['pass']) ? $temp['pass'] : null; |
75 | 75 | $connection['host'] = isset($temp['host']) && strlen($temp['host']) ? $temp['host'] : null; |
76 | 76 | $connection['name'] = isset($temp['path']) && strlen($temp['path']) ? trim($temp['path'], '/') : null; |
77 | - $connection['port'] = isset($temp['port']) && (int)$temp['port'] ? (int)$temp['port'] : null; |
|
77 | + $connection['port'] = isset($temp['port']) && (int) $temp['port'] ? (int) $temp['port'] : null; |
|
78 | 78 | if (isset($temp['query']) && strlen($temp['query'])) { |
79 | 79 | parse_str($temp['query'], $connection['opts']); |
80 | 80 | } |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | $new = ''; |
118 | 118 | $par = array_values($par); |
119 | 119 | if (substr_count($sql, '?') === 2 && !is_array($par[0])) { |
120 | - $par = [ $par ]; |
|
120 | + $par = [$par]; |
|
121 | 121 | } |
122 | 122 | $parts = explode('??', $sql); |
123 | 123 | $index = 0; |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | $index += count($tmp) - 1; |
128 | 128 | if (isset($par[$index])) { |
129 | 129 | if (!is_array($par[$index])) { |
130 | - $par[$index] = [ $par[$index] ]; |
|
130 | + $par[$index] = [$par[$index]]; |
|
131 | 131 | } |
132 | 132 | $params = $par[$index]; |
133 | 133 | array_splice($par, $index, 1, $params); |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | $new .= implode(',', array_fill(0, count($params), '?')); |
136 | 136 | } |
137 | 137 | } |
138 | - return [ $new, $par ]; |
|
138 | + return [$new, $par]; |
|
139 | 139 | } |
140 | 140 | /** |
141 | 141 | * Run a query (prepare & execute). |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | ): Collection { |
185 | 185 | $coll = Collection::from($this->query($sql, $par, $buff)); |
186 | 186 | if (($keys = $this->driver->option('mode')) && in_array($keys, ['strtoupper', 'strtolower'])) { |
187 | - $coll->map(function ($v) use ($keys) { |
|
187 | + $coll->map(function($v) use ($keys) { |
|
188 | 188 | $new = []; |
189 | 189 | foreach ($v as $k => $vv) { |
190 | 190 | $new[call_user_func($keys, $k)] = $vv; |
@@ -193,18 +193,18 @@ discard block |
||
193 | 193 | }); |
194 | 194 | } |
195 | 195 | if ($key !== null) { |
196 | - $coll->mapKey(function ($v) use ($key) { |
|
196 | + $coll->mapKey(function($v) use ($key) { |
|
197 | 197 | return $v[$key]; |
198 | 198 | }); |
199 | 199 | } |
200 | 200 | if ($skip) { |
201 | - $coll->map(function ($v) use ($key) { |
|
201 | + $coll->map(function($v) use ($key) { |
|
202 | 202 | unset($v[$key]); |
203 | 203 | return $v; |
204 | 204 | }); |
205 | 205 | } |
206 | 206 | if ($opti) { |
207 | - $coll->map(function ($v) { |
|
207 | + $coll->map(function($v) { |
|
208 | 208 | return count($v) === 1 ? current($v) : $v; |
209 | 209 | }); |
210 | 210 | } |
@@ -299,8 +299,7 @@ discard block |
||
299 | 299 | public function definition(string $table, bool $detectRelations = true) : Table |
300 | 300 | { |
301 | 301 | return isset($this->tables[$table]) ? |
302 | - $this->tables[$table] : |
|
303 | - $this->driver->table($table, $detectRelations); |
|
302 | + $this->tables[$table] : $this->driver->table($table, $detectRelations); |
|
304 | 303 | } |
305 | 304 | /** |
306 | 305 | * Parse all tables from the database. |
@@ -317,13 +316,13 @@ discard block |
||
317 | 316 | */ |
318 | 317 | public function getSchema($asPlainArray = true) |
319 | 318 | { |
320 | - return !$asPlainArray ? $this->tables : array_map(function ($table) { |
|
319 | + return !$asPlainArray ? $this->tables : array_map(function($table) { |
|
321 | 320 | return [ |
322 | 321 | 'name' => $table->getName(), |
323 | 322 | 'schema' => $table->getSchema(), |
324 | 323 | 'pkey' => $table->getPrimaryKey(), |
325 | 324 | 'comment' => $table->getComment(), |
326 | - 'columns' => array_map(function ($column) { |
|
325 | + 'columns' => array_map(function($column) { |
|
327 | 326 | return [ |
328 | 327 | 'name' => $column->getName(), |
329 | 328 | 'type' => $column->getType(), |
@@ -334,9 +333,9 @@ discard block |
||
334 | 333 | 'nullable' => $column->isNullable() |
335 | 334 | ]; |
336 | 335 | }, $table->getFullColumns()), |
337 | - 'relations' => array_map(function ($rel) { |
|
336 | + 'relations' => array_map(function($rel) { |
|
338 | 337 | $relation = clone $rel; |
339 | - $relation = (array)$relation; |
|
338 | + $relation = (array) $relation; |
|
340 | 339 | $relation['table'] = $rel->table->getName(); |
341 | 340 | if ($rel->pivot) { |
342 | 341 | $relation['pivot'] = $rel->pivot->getName(); |
@@ -389,8 +388,7 @@ discard block |
||
389 | 388 | public function table(string $table, bool $mapped = false) |
390 | 389 | { |
391 | 390 | return $mapped ? |
392 | - new TableQueryMapped($this, $this->definition($table)) : |
|
393 | - new TableQuery($this, $this->definition($table)); |
|
391 | + new TableQueryMapped($this, $this->definition($table)) : new TableQuery($this, $this->definition($table)); |
|
394 | 392 | } |
395 | 393 | public function __call($method, $args) |
396 | 394 | { |
@@ -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 | } |
@@ -110,12 +110,12 @@ discard block |
||
110 | 110 | $columns = Collection::from($this |
111 | 111 | ->query( |
112 | 112 | "SELECT * FROM information_schema.columns WHERE table_name = ? AND table_schema = ? AND table_catalog = ?", |
113 | - [ $table, $schema, $catalog ] |
|
113 | + [$table, $schema, $catalog] |
|
114 | 114 | )) |
115 | - ->mapKey(function ($v) { |
|
115 | + ->mapKey(function($v) { |
|
116 | 116 | return $v['column_name']; |
117 | 117 | }) |
118 | - ->map(function ($v) { |
|
118 | + ->map(function($v) { |
|
119 | 119 | $v['length'] = null; |
120 | 120 | if (!isset($v['data_type'])) { |
121 | 121 | return $v; |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | switch ($v['data_type']) { |
124 | 124 | case 'character': |
125 | 125 | case 'character varying': |
126 | - $v['length'] = (int)$v['character_maximum_length']; |
|
126 | + $v['length'] = (int) $v['character_maximum_length']; |
|
127 | 127 | break; |
128 | 128 | } |
129 | 129 | return $v; |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | ->query( |
137 | 137 | "SELECT constraint_name FROM information_schema.table_constraints |
138 | 138 | WHERE table_name = ? AND constraint_type = ? AND table_schema = ? AND table_catalog = ?", |
139 | - [ $table, 'PRIMARY KEY', $schema, $catalog ] |
|
139 | + [$table, 'PRIMARY KEY', $schema, $catalog] |
|
140 | 140 | )) |
141 | 141 | ->pluck('constraint_name') |
142 | 142 | ->value(); |
@@ -146,12 +146,12 @@ discard block |
||
146 | 146 | ->query( |
147 | 147 | "SELECT column_name FROM information_schema.constraint_column_usage |
148 | 148 | WHERE table_name = ? AND constraint_name = ? AND table_schema = ? AND table_catalog = ?", |
149 | - [ $table, $pkname, $schema, $catalog ] |
|
149 | + [$table, $pkname, $schema, $catalog] |
|
150 | 150 | )) |
151 | 151 | ->pluck('column_name') |
152 | 152 | ->toArray(); |
153 | 153 | } |
154 | - $tables[$schema . '.' .$table] = $definition = (new Table($table, $schema)) |
|
154 | + $tables[$schema.'.'.$table] = $definition = (new Table($table, $schema)) |
|
155 | 155 | ->addColumns($columns) |
156 | 156 | ->setPrimaryKey($primary) |
157 | 157 | ->setComment(''); |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected) |
163 | 163 | $relations = []; |
164 | 164 | foreach ($relationsR[$table] ?? [] as $relation) { |
165 | - $relations[$relation['constraint_name']]['table'] = $relation['table_schema'] . $relation['table_name']; |
|
165 | + $relations[$relation['constraint_name']]['table'] = $relation['table_schema'].$relation['table_name']; |
|
166 | 166 | $relations[$relation['constraint_name']]['keymap'][$relation['referenced_column_name']] = |
167 | 167 | $relation['column_name']; |
168 | 168 | } |
@@ -178,11 +178,11 @@ discard block |
||
178 | 178 | $usedcol = []; |
179 | 179 | if (count($columns)) { |
180 | 180 | foreach (Collection::from($relationsT[$data['table']] ?? []) |
181 | - ->filter(function ($v) use ($columns) { |
|
181 | + ->filter(function($v) use ($columns) { |
|
182 | 182 | return in_array($v['column_name'], $columns); |
183 | 183 | }) as $relation |
184 | 184 | ) { |
185 | - $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' . $relation['referenced_table_name']; |
|
185 | + $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'.$relation['referenced_table_name']; |
|
186 | 186 | $foreign[$relation['constraint_name']]['keymap'][$relation['column_name']] = |
187 | 187 | $relation['referenced_column_name']; |
188 | 188 | $usedcol[] = $relation['column_name']; |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | $orig = $relname; |
199 | 199 | $cntr = 1; |
200 | 200 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
201 | - $relname = $orig . '_' . (++ $cntr); |
|
201 | + $relname = $orig.'_'.(++$cntr); |
|
202 | 202 | } |
203 | 203 | $definition->addRelation( |
204 | 204 | new TableRelation( |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | $orig = $relname; |
220 | 220 | $cntr = 1; |
221 | 221 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
222 | - $relname = $orig . '_' . (++ $cntr); |
|
222 | + $relname = $orig.'_'.(++$cntr); |
|
223 | 223 | } |
224 | 224 | $definition->addRelation( |
225 | 225 | new TableRelation( |
@@ -235,8 +235,8 @@ discard block |
||
235 | 235 | // assuming current table is linked to "one" record in the referenced table |
236 | 236 | // resulting in a "belongsTo" relationship |
237 | 237 | $relations = []; |
238 | - foreach ($relationsT[$schema . '.' . $table] ?? [] as $relation) { |
|
239 | - $relations[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' . $relation['referenced_table_name']; |
|
238 | + foreach ($relationsT[$schema.'.'.$table] ?? [] as $relation) { |
|
239 | + $relations[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'.$relation['referenced_table_name']; |
|
240 | 240 | $relations[$relation['constraint_name']]['keymap'][$relation['column_name']] = |
241 | 241 | $relation['referenced_column_name']; |
242 | 242 | } |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | $orig = $relname; |
250 | 250 | $cntr = 1; |
251 | 251 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
252 | - $relname = $orig . '_' . (++ $cntr); |
|
252 | + $relname = $orig.'_'.(++$cntr); |
|
253 | 253 | } |
254 | 254 | $definition->addRelation( |
255 | 255 | new TableRelation( |
@@ -268,10 +268,10 @@ discard block |
||
268 | 268 | return Collection::from($this |
269 | 269 | ->query( |
270 | 270 | "SELECT table_name FROM information_schema.tables where table_schema = ? AND table_catalog = ?", |
271 | - [ $this->connection['opts']['schema'] ?? 'public', $this->connection['name'] ] |
|
271 | + [$this->connection['opts']['schema'] ?? 'public', $this->connection['name']] |
|
272 | 272 | )) |
273 | 273 | ->pluck('table_name') |
274 | - ->map(function ($v) { |
|
274 | + ->map(function($v) { |
|
275 | 275 | return $this->table($v); |
276 | 276 | }) |
277 | 277 | ->toArray(); |
@@ -28,8 +28,8 @@ discard block |
||
28 | 28 | $table = $temp[1]; |
29 | 29 | } |
30 | 30 | |
31 | - if (isset($tables[$schema . '.' . $table])) { |
|
32 | - return $tables[$schema . '.' . $table]; |
|
31 | + if (isset($tables[$schema.'.'.$table])) { |
|
32 | + return $tables[$schema.'.'.$table]; |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | static $comments = []; |
@@ -37,10 +37,10 @@ discard block |
||
37 | 37 | $comments[$schema] = Collection::from( |
38 | 38 | $this->query( |
39 | 39 | "SELECT TABLE_NAME, TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ?", |
40 | - [ $schema ] |
|
40 | + [$schema] |
|
41 | 41 | ) |
42 | 42 | ) |
43 | - ->mapKey(function ($v) { |
|
43 | + ->mapKey(function($v) { |
|
44 | 44 | return $v['TABLE_NAME']; |
45 | 45 | }) |
46 | 46 | ->pluck('TABLE_COMMENT') |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | WHERE |
61 | 61 | (TABLE_SCHEMA = ? OR REFERENCED_TABLE_SCHEMA = ?) AND |
62 | 62 | TABLE_NAME IS NOT NULL AND REFERENCED_TABLE_NAME IS NOT NULL", |
63 | - [ $main, $main ] |
|
63 | + [$main, $main] |
|
64 | 64 | ) |
65 | 65 | )->toArray(); |
66 | 66 | foreach ($col as $row) { |
@@ -70,8 +70,8 @@ discard block |
||
70 | 70 | if ($row['REFERENCED_TABLE_SCHEMA'] !== $main) { |
71 | 71 | $additional[] = $row['REFERENCED_TABLE_SCHEMA']; |
72 | 72 | } |
73 | - $relationsT[$row['TABLE_SCHEMA'] . '.' . $row['TABLE_NAME']][] = $row; |
|
74 | - $relationsR[$row['REFERENCED_TABLE_SCHEMA'] . '.' . $row['REFERENCED_TABLE_NAME']][] = $row; |
|
73 | + $relationsT[$row['TABLE_SCHEMA'].'.'.$row['TABLE_NAME']][] = $row; |
|
74 | + $relationsR[$row['REFERENCED_TABLE_SCHEMA'].'.'.$row['REFERENCED_TABLE_NAME']][] = $row; |
|
75 | 75 | } |
76 | 76 | foreach (array_filter(array_unique($additional)) as $s) { |
77 | 77 | $col = Collection::from( |
@@ -81,12 +81,12 @@ discard block |
||
81 | 81 | WHERE |
82 | 82 | TABLE_SCHEMA = ? AND REFERENCED_TABLE_SCHEMA = ? AND |
83 | 83 | TABLE_NAME IS NOT NULL AND REFERENCED_TABLE_NAME IS NOT NULL", |
84 | - [ $s, $s ] |
|
84 | + [$s, $s] |
|
85 | 85 | ) |
86 | 86 | )->toArray(); |
87 | 87 | foreach ($col as $row) { |
88 | - $relationsT[$row['TABLE_SCHEMA'] . '.' . $row['TABLE_NAME']][] = $row; |
|
89 | - $relationsR[$row['REFERENCED_TABLE_SCHEMA'] . '.' . $row['REFERENCED_TABLE_NAME']][] = $row; |
|
88 | + $relationsT[$row['TABLE_SCHEMA'].'.'.$row['TABLE_NAME']][] = $row; |
|
89 | + $relationsR[$row['REFERENCED_TABLE_SCHEMA'].'.'.$row['REFERENCED_TABLE_NAME']][] = $row; |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | } |
@@ -95,14 +95,14 @@ discard block |
||
95 | 95 | if (!count($columns)) { |
96 | 96 | throw new DBException('Table not found by name'); |
97 | 97 | } |
98 | - $tables[$schema . '.' . $table] = $definition = (new Table($table, $schema)) |
|
98 | + $tables[$schema.'.'.$table] = $definition = (new Table($table, $schema)) |
|
99 | 99 | ->addColumns( |
100 | 100 | $columns |
101 | 101 | ->clone() |
102 | - ->mapKey(function ($v) { |
|
102 | + ->mapKey(function($v) { |
|
103 | 103 | return $v['Field']; |
104 | 104 | }) |
105 | - ->map(function ($v) { |
|
105 | + ->map(function($v) { |
|
106 | 106 | $v['length'] = null; |
107 | 107 | if (!isset($v['Type'])) { |
108 | 108 | return $v; |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | default: |
125 | 125 | if (strpos($type, 'char') !== false && strpos($type, '(') !== false) { |
126 | 126 | // extract length from varchar |
127 | - $v['length'] = (int)explode(')', explode('(', $type)[1])[0]; |
|
127 | + $v['length'] = (int) explode(')', explode('(', $type)[1])[0]; |
|
128 | 128 | $v['length'] = $v['length'] > 0 ? $v['length'] : null; |
129 | 129 | } |
130 | 130 | break; |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | ->setPrimaryKey( |
137 | 137 | $columns |
138 | 138 | ->clone() |
139 | - ->filter(function ($v) { |
|
139 | + ->filter(function($v) { |
|
140 | 140 | return $v['Key'] === 'PRI'; |
141 | 141 | }) |
142 | 142 | ->pluck('Field') |
@@ -149,8 +149,8 @@ discard block |
||
149 | 149 | // assuming current table is on the "one" end having "many" records in the referencing table |
150 | 150 | // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected) |
151 | 151 | $relations = []; |
152 | - foreach ($relationsR[$schema . '.' . $table] ?? [] as $relation) { |
|
153 | - $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_SCHEMA'] . '.' . $relation['TABLE_NAME']; |
|
152 | + foreach ($relationsR[$schema.'.'.$table] ?? [] as $relation) { |
|
153 | + $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_SCHEMA'].'.'.$relation['TABLE_NAME']; |
|
154 | 154 | $relations[$relation['CONSTRAINT_NAME']]['keymap'][$relation['REFERENCED_COLUMN_NAME']] = |
155 | 155 | $relation['COLUMN_NAME']; |
156 | 156 | } |
@@ -166,10 +166,10 @@ discard block |
||
166 | 166 | $usedcol = []; |
167 | 167 | if (count($columns)) { |
168 | 168 | foreach (Collection::from($relationsT[$data['table']] ?? []) |
169 | - ->filter(function ($v) use ($columns) { |
|
169 | + ->filter(function($v) use ($columns) { |
|
170 | 170 | return in_array($v['COLUMN_NAME'], $columns); |
171 | 171 | }) |
172 | - ->map(function ($v) { |
|
172 | + ->map(function($v) { |
|
173 | 173 | $new = []; |
174 | 174 | foreach ($v as $kk => $vv) { |
175 | 175 | $new[strtoupper($kk)] = $vv; |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | return $new; |
178 | 178 | }) as $relation |
179 | 179 | ) { |
180 | - $foreign[$relation['CONSTRAINT_NAME']]['table'] = $relation['REFERENCED_TABLE_SCHEMA'] . '.' . $relation['REFERENCED_TABLE_NAME']; |
|
180 | + $foreign[$relation['CONSTRAINT_NAME']]['table'] = $relation['REFERENCED_TABLE_SCHEMA'].'.'.$relation['REFERENCED_TABLE_NAME']; |
|
181 | 181 | $foreign[$relation['CONSTRAINT_NAME']]['keymap'][$relation['COLUMN_NAME']] = |
182 | 182 | $relation['REFERENCED_COLUMN_NAME']; |
183 | 183 | $usedcol[] = $relation['COLUMN_NAME']; |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | $orig = $relname; |
194 | 194 | $cntr = 1; |
195 | 195 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
196 | - $relname = $orig . '_' . (++ $cntr); |
|
196 | + $relname = $orig.'_'.(++$cntr); |
|
197 | 197 | } |
198 | 198 | $definition->addRelation( |
199 | 199 | new TableRelation( |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | $orig = $relname; |
215 | 215 | $cntr = 1; |
216 | 216 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
217 | - $relname = $orig . '_' . (++ $cntr); |
|
217 | + $relname = $orig.'_'.(++$cntr); |
|
218 | 218 | } |
219 | 219 | $definition->addRelation( |
220 | 220 | new TableRelation( |
@@ -230,8 +230,8 @@ discard block |
||
230 | 230 | // assuming current table is linked to "one" record in the referenced table |
231 | 231 | // resulting in a "belongsTo" relationship |
232 | 232 | $relations = []; |
233 | - foreach (Collection::from($relationsT[$schema . '.' . $table] ?? []) |
|
234 | - ->map(function ($v) { |
|
233 | + foreach (Collection::from($relationsT[$schema.'.'.$table] ?? []) |
|
234 | + ->map(function($v) { |
|
235 | 235 | $new = []; |
236 | 236 | foreach ($v as $kk => $vv) { |
237 | 237 | $new[strtoupper($kk)] = $vv; |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | return $new; |
240 | 240 | }) as $relation |
241 | 241 | ) { |
242 | - $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['REFERENCED_TABLE_SCHEMA'] . '.' . $relation['REFERENCED_TABLE_NAME']; |
|
242 | + $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['REFERENCED_TABLE_SCHEMA'].'.'.$relation['REFERENCED_TABLE_NAME']; |
|
243 | 243 | $relations[$relation['CONSTRAINT_NAME']]['keymap'][$relation['COLUMN_NAME']] = |
244 | 244 | $relation['REFERENCED_COLUMN_NAME']; |
245 | 245 | } |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | $orig = $relname; |
253 | 253 | $cntr = 1; |
254 | 254 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
255 | - $relname = $orig . '_' . (++ $cntr); |
|
255 | + $relname = $orig.'_'.(++$cntr); |
|
256 | 256 | } |
257 | 257 | $definition->addRelation( |
258 | 258 | new TableRelation( |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | "SELECT table_name FROM information_schema.tables where table_schema = ?", |
274 | 274 | [$this->connection['opts']['schema'] ?? $this->connection['name']] |
275 | 275 | )) |
276 | - ->map(function ($v) { |
|
276 | + ->map(function($v) { |
|
277 | 277 | $new = []; |
278 | 278 | foreach ($v as $kk => $vv) { |
279 | 279 | $new[strtoupper($kk)] = $vv; |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | return $new; |
282 | 282 | }) |
283 | 283 | ->pluck('TABLE_NAME') |
284 | - ->map(function ($v) { |
|
284 | + ->map(function($v) { |
|
285 | 285 | return $this->table($v); |
286 | 286 | }) |
287 | 287 | ->toArray(); |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | public function collection(TableQueryIterator $iterator, Table $definition) : Collection |
53 | 53 | { |
54 | 54 | return Collection::from($iterator) |
55 | - ->map(function ($v) use ($definition) { |
|
55 | + ->map(function($v) use ($definition) { |
|
56 | 56 | return $this->entity($definition, $v); |
57 | 57 | }); |
58 | 58 | } |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | $definition = $entity->definition(); |
128 | 128 | foreach ($definition->getColumns() as $column) { |
129 | 129 | if (!array_key_exists($column, $data)) { |
130 | - $entity->__lazyProperty($column, function () use ($definition, $primary, $column) { |
|
130 | + $entity->__lazyProperty($column, function() use ($definition, $primary, $column) { |
|
131 | 131 | $query = $this->db->table($definition->getFullName()); |
132 | 132 | foreach ($primary as $k => $v) { |
133 | 133 | $query->filter($k, $v); |
@@ -141,12 +141,12 @@ discard block |
||
141 | 141 | $name, |
142 | 142 | array_key_exists($name, $data) && isset($data[$name]) ? |
143 | 143 | ($relation->many ? |
144 | - array_map(function ($v) use ($relation) { |
|
144 | + array_map(function($v) use ($relation) { |
|
145 | 145 | return $this->entity($relation->table, $v); |
146 | 146 | }, $data[$name]) : |
147 | 147 | $this->entity($relation->table, $data[$name]) |
148 | 148 | ) : |
149 | - function (array $columns = null) use ($entity, $definition, $relation, $data) { |
|
149 | + function(array $columns = null) use ($entity, $definition, $relation, $data) { |
|
150 | 150 | $query = $this->db->table($relation->table->getFullName(), true); |
151 | 151 | if ($columns !== null) { |
152 | 152 | $query->columns($columns); |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | ); |
173 | 173 | } |
174 | 174 | foreach ($definition->getPrimaryKey() as $v) { |
175 | - $query->filter($nm . '.' . $v, $data[$v] ?? null); |
|
175 | + $query->filter($nm.'.'.$v, $data[$v] ?? null); |
|
176 | 176 | } |
177 | 177 | } else { |
178 | 178 | foreach ($relation->keymap as $k => $v) { |
@@ -180,8 +180,7 @@ discard block |
||
180 | 180 | } |
181 | 181 | } |
182 | 182 | return $relation->many ? |
183 | - $query->iterator() : |
|
184 | - $query[0]; |
|
183 | + $query->iterator() : $query[0]; |
|
185 | 184 | } |
186 | 185 | ); |
187 | 186 | } |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | public function setPrimaryKey($column) : Table |
83 | 83 | { |
84 | 84 | if (!is_array($column)) { |
85 | - $column = [ $column ]; |
|
85 | + $column = [$column]; |
|
86 | 86 | } |
87 | 87 | $this->data['primary'] = $column; |
88 | 88 | return $this; |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | */ |
110 | 110 | public function getFullName() |
111 | 111 | { |
112 | - return ($this->data['schema'] ? $this->data['schema'] . '.' : '') . $this->data['name']; |
|
112 | + return ($this->data['schema'] ? $this->data['schema'].'.' : '').$this->data['name']; |
|
113 | 113 | } |
114 | 114 | /** |
115 | 115 | * Get a column definition |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | } |
185 | 185 | |
186 | 186 | if (!isset($name)) { |
187 | - $name = $toTable->getName() . '_' . implode('_', array_keys($keymap)); |
|
187 | + $name = $toTable->getName().'_'.implode('_', array_keys($keymap)); |
|
188 | 188 | } |
189 | 189 | $this->addRelation(new TableRelation( |
190 | 190 | $name, |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | /** |
45 | 45 | * @var int[] |
46 | 46 | */ |
47 | - protected $li_of = [0,0,0]; |
|
47 | + protected $li_of = [0, 0, 0]; |
|
48 | 48 | /** |
49 | 49 | * @var array |
50 | 50 | */ |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | public function __construct(DBInterface $db, $table) |
75 | 75 | { |
76 | 76 | $this->db = $db; |
77 | - $this->definition = $table instanceof Table ? $table : $this->db->definition((string)$table); |
|
77 | + $this->definition = $table instanceof Table ? $table : $this->db->definition((string) $table); |
|
78 | 78 | $primary = $this->definition->getPrimaryKey(); |
79 | 79 | $columns = $this->definition->getColumns(); |
80 | 80 | $this->pkey = count($primary) ? $primary : $columns; |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | { |
98 | 98 | $column = explode('.', $column); |
99 | 99 | if (count($column) === 1) { |
100 | - $column = [ $this->definition->getFullName(), $column[0] ]; |
|
100 | + $column = [$this->definition->getFullName(), $column[0]]; |
|
101 | 101 | $col = $this->definition->getColumn($column[1]); |
102 | 102 | if (!$col) { |
103 | 103 | throw new DBException('Invalid column name in own table'); |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | throw new DBException('Invalid column name in related table'); |
121 | 121 | } |
122 | 122 | } else { |
123 | - throw new DBException('Invalid foreign table name: ' . implode(',', $column)); |
|
123 | + throw new DBException('Invalid foreign table name: '.implode(',', $column)); |
|
124 | 124 | } |
125 | 125 | } |
126 | 126 | } else { |
@@ -128,26 +128,26 @@ discard block |
||
128 | 128 | if ($this->definition->hasRelation(implode('.', $column))) { |
129 | 129 | $this->with(implode('.', $column)); |
130 | 130 | $col = $this->definition->getRelation(implode('.', $column))->table->getColumn($name); |
131 | - $column = [ implode('.', $column), $name ]; |
|
131 | + $column = [implode('.', $column), $name]; |
|
132 | 132 | } else { |
133 | 133 | $this->with(implode('.', $column)); |
134 | 134 | $table = $this->definition; |
135 | 135 | $table = array_reduce( |
136 | 136 | $column, |
137 | - function ($carry, $item) use (&$table) { |
|
137 | + function($carry, $item) use (&$table) { |
|
138 | 138 | $table = $table->getRelation($item)->table; |
139 | 139 | return $table; |
140 | 140 | } |
141 | 141 | ); |
142 | 142 | $col = $table->getColumn($name); |
143 | - $column = [ implode(static::SEP, $column), $name ]; |
|
143 | + $column = [implode(static::SEP, $column), $name]; |
|
144 | 144 | } |
145 | 145 | } |
146 | - return [ 'name' => implode('.', $column), 'data' => $col ]; |
|
146 | + return ['name' => implode('.', $column), 'data' => $col]; |
|
147 | 147 | } |
148 | 148 | protected function normalizeValue(TableColumn $col, $value) |
149 | 149 | { |
150 | - $strict = (int)$this->db->driverOption('strict', 0) > 0; |
|
150 | + $strict = (int) $this->db->driverOption('strict', 0) > 0; |
|
151 | 151 | if ($value === null && $col->isNullable()) { |
152 | 152 | return null; |
153 | 153 | } |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | $temp = strtotime($value); |
158 | 158 | if (!$temp) { |
159 | 159 | if ($strict) { |
160 | - throw new DBException('Invalid value for date column ' . $col->getName()); |
|
160 | + throw new DBException('Invalid value for date column '.$col->getName()); |
|
161 | 161 | } |
162 | 162 | return null; |
163 | 163 | } |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | return $value->format('Y-m-d'); |
171 | 171 | } |
172 | 172 | if ($strict) { |
173 | - throw new DBException('Invalid value (unknown data type) for date column ' . $col->getName()); |
|
173 | + throw new DBException('Invalid value (unknown data type) for date column '.$col->getName()); |
|
174 | 174 | } |
175 | 175 | return $value; |
176 | 176 | case 'datetime': |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | $temp = strtotime($value); |
179 | 179 | if (!$temp) { |
180 | 180 | if ($strict) { |
181 | - throw new DBException('Invalid value for datetime column ' . $col->getName()); |
|
181 | + throw new DBException('Invalid value for datetime column '.$col->getName()); |
|
182 | 182 | } |
183 | 183 | return null; |
184 | 184 | } |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | return $value->format('Y-m-d H:i:s'); |
192 | 192 | } |
193 | 193 | if ($strict) { |
194 | - throw new DBException('Invalid value (unknown data type) for datetime column ' . $col->getName()); |
|
194 | + throw new DBException('Invalid value (unknown data type) for datetime column '.$col->getName()); |
|
195 | 195 | } |
196 | 196 | return $value; |
197 | 197 | case 'enum': |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | if (is_int($value)) { |
200 | 200 | if (!isset($values[$value])) { |
201 | 201 | if ($strict) { |
202 | - throw new DBException('Invalid value (using integer) for enum ' . $col->getName()); |
|
202 | + throw new DBException('Invalid value (using integer) for enum '.$col->getName()); |
|
203 | 203 | } |
204 | 204 | return $value; |
205 | 205 | } |
@@ -207,23 +207,23 @@ discard block |
||
207 | 207 | } |
208 | 208 | if (!in_array($value, $col->getValues())) { |
209 | 209 | if ($strict) { |
210 | - throw new DBException('Invalid value for enum ' . $col->getName()); |
|
210 | + throw new DBException('Invalid value for enum '.$col->getName()); |
|
211 | 211 | } |
212 | 212 | return 0; |
213 | 213 | } |
214 | 214 | return $value; |
215 | 215 | case 'int': |
216 | 216 | $temp = preg_replace('([^+\-0-9]+)', '', $value); |
217 | - return is_string($temp) ? (int)$temp : 0; |
|
217 | + return is_string($temp) ? (int) $temp : 0; |
|
218 | 218 | case 'float': |
219 | 219 | $temp = preg_replace('([^+\-0-9.]+)', '', str_replace(',', '.', $value)); |
220 | - return is_string($temp) ? (float)$temp : 0; |
|
220 | + return is_string($temp) ? (float) $temp : 0; |
|
221 | 221 | case 'text': |
222 | 222 | // check using strlen first, in order to avoid hitting mb_ functions which might be polyfilled |
223 | 223 | // because the polyfill is quite slow |
224 | 224 | if ($col->hasLength() && strlen($value) > $col->getLength() && mb_strlen($value) > $col->getLength()) { |
225 | 225 | if ($strict) { |
226 | - throw new DBException('Invalid value for text column ' . $col->getName()); |
|
226 | + throw new DBException('Invalid value for text column '.$col->getName()); |
|
227 | 227 | } |
228 | 228 | return mb_substr($value, 0, $col->getLength()); |
229 | 229 | } |
@@ -245,35 +245,32 @@ discard block |
||
245 | 245 | // str_replace(['%', '_'], ['\\%','\\_'], $q) |
246 | 246 | return $negate ? |
247 | 247 | [ |
248 | - $name . ' NOT LIKE ?', |
|
249 | - [ $this->normalizeValue($column, $value) ] |
|
250 | - ] : |
|
251 | - [ |
|
252 | - $name . ' LIKE ?', |
|
253 | - [ $this->normalizeValue($column, $value) ] |
|
248 | + $name.' NOT LIKE ?', |
|
249 | + [$this->normalizeValue($column, $value)] |
|
250 | + ] : [ |
|
251 | + $name.' LIKE ?', |
|
252 | + [$this->normalizeValue($column, $value)] |
|
254 | 253 | ]; |
255 | 254 | } |
256 | 255 | if (is_null($value)) { |
257 | 256 | return $negate ? |
258 | - [ $name . ' IS NOT NULL', [] ]: |
|
259 | - [ $name . ' IS NULL', [] ]; |
|
257 | + [$name.' IS NOT NULL', []] : [$name.' IS NULL', []]; |
|
260 | 258 | } |
261 | 259 | if (!is_array($value)) { |
262 | 260 | return $negate ? |
263 | 261 | [ |
264 | - $name . ' <> ?', |
|
265 | - [ $this->normalizeValue($column, $value) ] |
|
266 | - ] : |
|
267 | - [ |
|
268 | - $name . ' = ?', |
|
269 | - [ $this->normalizeValue($column, $value) ] |
|
262 | + $name.' <> ?', |
|
263 | + [$this->normalizeValue($column, $value)] |
|
264 | + ] : [ |
|
265 | + $name.' = ?', |
|
266 | + [$this->normalizeValue($column, $value)] |
|
270 | 267 | ]; |
271 | 268 | } |
272 | 269 | if (isset($value['beg']) && strlen($value['beg']) && (!isset($value['end']) || !strlen($value['end']))) { |
273 | - $value = [ 'gte' => $value['beg'] ]; |
|
270 | + $value = ['gte' => $value['beg']]; |
|
274 | 271 | } |
275 | 272 | if (isset($value['end']) && strlen($value['end']) && (!isset($value['beg']) || !strlen($value['beg']))) { |
276 | - $value = [ 'lte' => $value['end'] ]; |
|
273 | + $value = ['lte' => $value['end']]; |
|
277 | 274 | } |
278 | 275 | if (isset($value['beg']) && isset($value['end'])) { |
279 | 276 | return $negate ? |
@@ -283,8 +280,7 @@ discard block |
||
283 | 280 | $this->normalizeValue($column, $value['beg']), |
284 | 281 | $this->normalizeValue($column, $value['end']) |
285 | 282 | ] |
286 | - ] : |
|
287 | - [ |
|
283 | + ] : [ |
|
288 | 284 | $name.' BETWEEN ? AND ?', |
289 | 285 | [ |
290 | 286 | $this->normalizeValue($column, $value['beg']), |
@@ -296,38 +292,38 @@ discard block |
||
296 | 292 | $sql = []; |
297 | 293 | $par = []; |
298 | 294 | if (isset($value['gt'])) { |
299 | - $sql[] = $name. ' ' . ($negate ? '<=' : '>') . ' ?'; |
|
295 | + $sql[] = $name.' '.($negate ? '<=' : '>').' ?'; |
|
300 | 296 | $par[] = $this->normalizeValue($column, $value['gt']); |
301 | 297 | } |
302 | 298 | if (isset($value['gte'])) { |
303 | - $sql[] = $name. ' ' . ($negate ? '<' : '>=') . ' ?'; |
|
299 | + $sql[] = $name.' '.($negate ? '<' : '>=').' ?'; |
|
304 | 300 | $par[] = $this->normalizeValue($column, $value['gte']); |
305 | 301 | } |
306 | 302 | if (isset($value['lt'])) { |
307 | - $sql[] = $name. ' ' . ($negate ? '>=' : '<') . ' ?'; |
|
303 | + $sql[] = $name.' '.($negate ? '>=' : '<').' ?'; |
|
308 | 304 | $par[] = $this->normalizeValue($column, $value['lt']); |
309 | 305 | } |
310 | 306 | if (isset($value['lte'])) { |
311 | - $sql[] = $name. ' ' . ($negate ? '>' : '<=') . ' ?'; |
|
307 | + $sql[] = $name.' '.($negate ? '>' : '<=').' ?'; |
|
312 | 308 | $par[] = $this->normalizeValue($column, $value['lte']); |
313 | 309 | } |
314 | 310 | return [ |
315 | - '(' . implode(' AND ', $sql) . ')', |
|
311 | + '('.implode(' AND ', $sql).')', |
|
316 | 312 | $par |
317 | 313 | ]; |
318 | 314 | } |
319 | 315 | return $negate ? |
320 | 316 | [ |
321 | - $name . ' NOT IN (??)', |
|
322 | - [ array_map(function ($v) use ($column) { |
|
317 | + $name.' NOT IN (??)', |
|
318 | + [array_map(function($v) use ($column) { |
|
323 | 319 | return $this->normalizeValue($column, $v); |
324 | - }, $value) ] |
|
320 | + }, $value)] |
|
325 | 321 | ] : |
326 | 322 | [ |
327 | - $name . ' IN (??)', |
|
328 | - [ array_map(function ($v) use ($column) { |
|
323 | + $name.' IN (??)', |
|
324 | + [array_map(function($v) use ($column) { |
|
329 | 325 | return $this->normalizeValue($column, $v); |
330 | - }, $value) ] |
|
326 | + }, $value)] |
|
331 | 327 | ]; |
332 | 328 | } |
333 | 329 | /** |
@@ -358,7 +354,7 @@ discard block |
||
358 | 354 | $par = array_merge($par, $temp[1]); |
359 | 355 | } |
360 | 356 | } |
361 | - return $this->where('(' . implode(' OR ', $sql) . ')', $par); |
|
357 | + return $this->where('('.implode(' OR ', $sql).')', $par); |
|
362 | 358 | } |
363 | 359 | /** |
364 | 360 | * Filter the results matching all of the criteria |
@@ -376,7 +372,7 @@ discard block |
||
376 | 372 | $par = array_merge($par, $temp[1]); |
377 | 373 | } |
378 | 374 | } |
379 | - return $this->where('(' . implode(' AND ', $sql) . ')', $par); |
|
375 | + return $this->where('('.implode(' AND ', $sql).')', $par); |
|
380 | 376 | } |
381 | 377 | /** |
382 | 378 | * Sort by a column |
@@ -386,7 +382,7 @@ discard block |
||
386 | 382 | */ |
387 | 383 | public function sort(string $column, bool $desc = false) : self |
388 | 384 | { |
389 | - return $this->order($this->getColumn($column)['name'] . ' ' . ($desc ? 'DESC' : 'ASC')); |
|
385 | + return $this->order($this->getColumn($column)['name'].' '.($desc ? 'DESC' : 'ASC')); |
|
390 | 386 | } |
391 | 387 | /** |
392 | 388 | * Group by a column (or columns) |
@@ -396,7 +392,7 @@ discard block |
||
396 | 392 | public function group($column) : self |
397 | 393 | { |
398 | 394 | if (!is_array($column)) { |
399 | - $column = [ $column ]; |
|
395 | + $column = [$column]; |
|
400 | 396 | } |
401 | 397 | foreach ($column as $k => $v) { |
402 | 398 | $column[$k] = $this->getColumn($v)['name']; |
@@ -438,7 +434,7 @@ discard block |
||
438 | 434 | $this->order = []; |
439 | 435 | $this->having = []; |
440 | 436 | $this->aliases = []; |
441 | - $this->li_of = [0,0,0]; |
|
437 | + $this->li_of = [0, 0, 0]; |
|
442 | 438 | $this->qiterator = null; |
443 | 439 | return $this; |
444 | 440 | } |
@@ -451,7 +447,7 @@ discard block |
||
451 | 447 | public function groupBy(string $sql, array $params = []) : self |
452 | 448 | { |
453 | 449 | $this->qiterator = null; |
454 | - $this->group = [ $sql, $params ]; |
|
450 | + $this->group = [$sql, $params]; |
|
455 | 451 | return $this; |
456 | 452 | } |
457 | 453 | /** |
@@ -464,7 +460,7 @@ discard block |
||
464 | 460 | */ |
465 | 461 | public function join($table, array $fields, string $name = null, bool $multiple = true) |
466 | 462 | { |
467 | - $table = $table instanceof Table ? $table : $this->db->definition((string)$table); |
|
463 | + $table = $table instanceof Table ? $table : $this->db->definition((string) $table); |
|
468 | 464 | $name = $name ?? $table->getName(); |
469 | 465 | if (isset($this->joins[$name]) || $this->definition->hasRelation($name)) { |
470 | 466 | throw new DBException('Alias / table name already in use'); |
@@ -473,7 +469,7 @@ discard block |
||
473 | 469 | foreach ($fields as $k => $v) { |
474 | 470 | $k = explode('.', $k, 2); |
475 | 471 | $k = count($k) == 2 ? $k[1] : $k[0]; |
476 | - $this->joins[$name]->keymap[$this->getColumn($name . '.' . $k)['name']] = $this->getColumn($v)['name']; |
|
472 | + $this->joins[$name]->keymap[$this->getColumn($name.'.'.$k)['name']] = $this->getColumn($v)['name']; |
|
477 | 473 | } |
478 | 474 | return $this; |
479 | 475 | } |
@@ -486,7 +482,7 @@ discard block |
||
486 | 482 | public function where(string $sql, array $params = []) : self |
487 | 483 | { |
488 | 484 | $this->qiterator = null; |
489 | - $this->where[] = [ $sql, $params ]; |
|
485 | + $this->where[] = [$sql, $params]; |
|
490 | 486 | return $this; |
491 | 487 | } |
492 | 488 | /** |
@@ -498,7 +494,7 @@ discard block |
||
498 | 494 | public function having(string $sql, array $params = []) : self |
499 | 495 | { |
500 | 496 | $this->qiterator = null; |
501 | - $this->having[] = [ $sql, $params ]; |
|
497 | + $this->having[] = [$sql, $params]; |
|
502 | 498 | return $this; |
503 | 499 | } |
504 | 500 | /** |
@@ -522,7 +518,7 @@ discard block |
||
522 | 518 | $name = null; |
523 | 519 | } |
524 | 520 | } |
525 | - $this->order = [ $sql, $params, $name ]; |
|
521 | + $this->order = [$sql, $params, $name]; |
|
526 | 522 | return $this; |
527 | 523 | } |
528 | 524 | /** |
@@ -534,7 +530,7 @@ discard block |
||
534 | 530 | public function limit(int $limit, int $offset = 0, bool $limitOnMainTable = false) : self |
535 | 531 | { |
536 | 532 | $this->qiterator = null; |
537 | - $this->li_of = [ $limit, $offset, $limitOnMainTable ? 1 : 0 ]; |
|
533 | + $this->li_of = [$limit, $offset, $limitOnMainTable ? 1 : 0]; |
|
538 | 534 | return $this; |
539 | 535 | } |
540 | 536 | /** |
@@ -544,9 +540,9 @@ discard block |
||
544 | 540 | public function count() : int |
545 | 541 | { |
546 | 542 | $aliases = []; |
547 | - $getAlias = function ($name) use (&$aliases) { |
|
543 | + $getAlias = function($name) use (&$aliases) { |
|
548 | 544 | // to bypass use: return $name; |
549 | - return $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases); |
|
545 | + return $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases); |
|
550 | 546 | }; |
551 | 547 | $table = $this->definition->getFullName(); |
552 | 548 | $sql = 'SELECT COUNT(DISTINCT '.$table.'.'.implode(', '.$table.'.', $this->pkey).') FROM '.$table.' '; |
@@ -560,35 +556,35 @@ discard block |
||
560 | 556 | $h = $this->having; |
561 | 557 | $o = $this->order; |
562 | 558 | $g = $this->group; |
563 | - $j = array_map(function ($v) { |
|
559 | + $j = array_map(function($v) { |
|
564 | 560 | return clone $v; |
565 | 561 | }, $this->joins); |
566 | 562 | foreach ($this->definition->getRelations() as $k => $v) { |
567 | 563 | foreach ($w as $kk => $vv) { |
568 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) { |
|
569 | - $relations[$k] = [ $v, $table ]; |
|
570 | - $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]); |
|
564 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) { |
|
565 | + $relations[$k] = [$v, $table]; |
|
566 | + $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]); |
|
571 | 567 | } |
572 | 568 | } |
573 | - if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) { |
|
574 | - $relations[$k] = [ $v, $table ]; |
|
569 | + if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) { |
|
570 | + $relations[$k] = [$v, $table]; |
|
575 | 571 | } |
576 | 572 | foreach ($h as $kk => $vv) { |
577 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) { |
|
578 | - $relations[$k] = [ $v, $table ]; |
|
579 | - $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]); |
|
573 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) { |
|
574 | + $relations[$k] = [$v, $table]; |
|
575 | + $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]); |
|
580 | 576 | } |
581 | 577 | } |
582 | - if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) { |
|
583 | - $relations[$k] = [ $v, $table ]; |
|
584 | - $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]); |
|
578 | + if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) { |
|
579 | + $relations[$k] = [$v, $table]; |
|
580 | + $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]); |
|
585 | 581 | } |
586 | 582 | foreach ($j as $kk => $vv) { |
587 | 583 | foreach ($vv->keymap as $kkk => $vvv) { |
588 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vvv)) { |
|
589 | - $relations[$k] = [ $v, $table ]; |
|
584 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $vvv)) { |
|
585 | + $relations[$k] = [$v, $table]; |
|
590 | 586 | $j[$kk]->keymap[$kkk] = |
591 | - preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vvv); |
|
587 | + preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vvv); |
|
592 | 588 | } |
593 | 589 | } |
594 | 590 | } |
@@ -604,13 +600,13 @@ discard block |
||
604 | 600 | foreach ($v->keymap as $kk => $vv) { |
605 | 601 | $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' '; |
606 | 602 | } |
607 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
603 | + $sql .= implode(' AND ', $tmp).' '; |
|
608 | 604 | $sql .= 'LEFT JOIN '.$v->table->getFullName().' '.$getAlias($k).' ON '; |
609 | 605 | $tmp = []; |
610 | 606 | foreach ($v->pivot_keymap as $kk => $vv) { |
611 | 607 | $tmp[] = $getAlias($k).'.'.$vv.' = '.$alias.'.'.$kk.' '; |
612 | 608 | } |
613 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
609 | + $sql .= implode(' AND ', $tmp).' '; |
|
614 | 610 | } else { |
615 | 611 | $alias = $getAlias($k); |
616 | 612 | $sql .= 'LEFT JOIN '.$v->table->getFullName().' '.$alias.' ON '; |
@@ -619,38 +615,38 @@ discard block |
||
619 | 615 | $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' '; |
620 | 616 | } |
621 | 617 | if ($v->sql) { |
622 | - $tmp[] = $v->sql . ' '; |
|
618 | + $tmp[] = $v->sql.' '; |
|
623 | 619 | $par = array_merge($par, $v->par ?? []); |
624 | 620 | } |
625 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
621 | + $sql .= implode(' AND ', $tmp).' '; |
|
626 | 622 | } |
627 | 623 | } |
628 | 624 | foreach ($j as $k => $v) { |
629 | - $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getFullName().' '.$k.' ON '; |
|
625 | + $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getFullName().' '.$k.' ON '; |
|
630 | 626 | $tmp = []; |
631 | 627 | foreach ($v->keymap as $kk => $vv) { |
632 | 628 | $tmp[] = $kk.' = '.$vv; |
633 | 629 | } |
634 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
630 | + $sql .= implode(' AND ', $tmp).' '; |
|
635 | 631 | } |
636 | 632 | if (count($w)) { |
637 | 633 | $sql .= 'WHERE '; |
638 | 634 | $tmp = []; |
639 | 635 | foreach ($w as $v) { |
640 | - $tmp[] = '(' . $v[0] . ')'; |
|
636 | + $tmp[] = '('.$v[0].')'; |
|
641 | 637 | $par = array_merge($par, $v[1]); |
642 | 638 | } |
643 | 639 | $sql .= implode(' AND ', $tmp).' '; |
644 | 640 | } |
645 | 641 | if (count($g)) { |
646 | - $sql .= 'GROUP BY ' . $g[0] . ' '; |
|
642 | + $sql .= 'GROUP BY '.$g[0].' '; |
|
647 | 643 | $par = array_merge($par, $g[1]); |
648 | 644 | } |
649 | 645 | if (count($h)) { |
650 | 646 | $sql .= 'HAVING '; |
651 | 647 | $tmp = []; |
652 | 648 | foreach ($h as $v) { |
653 | - $tmp[] = '(' . $v[0] . ')'; |
|
649 | + $tmp[] = '('.$v[0].')'; |
|
654 | 650 | $par = array_merge($par, $v[1]); |
655 | 651 | } |
656 | 652 | $sql .= implode(' AND ', $tmp).' '; |
@@ -684,7 +680,7 @@ discard block |
||
684 | 680 | $this->with(implode('.', $temp)); |
685 | 681 | $table = array_reduce( |
686 | 682 | $temp, |
687 | - function ($carry, $item) use (&$table) { |
|
683 | + function($carry, $item) use (&$table) { |
|
688 | 684 | return $table->getRelation($item)->table; |
689 | 685 | } |
690 | 686 | ); |
@@ -693,7 +689,7 @@ discard block |
||
693 | 689 | } |
694 | 690 | unset($fields[$k]); |
695 | 691 | foreach ($cols as $col) { |
696 | - $fields[] = $table . '.' . $col; |
|
692 | + $fields[] = $table.'.'.$col; |
|
697 | 693 | } |
698 | 694 | } |
699 | 695 | } |
@@ -727,9 +723,9 @@ discard block |
||
727 | 723 | return $this->qiterator; |
728 | 724 | } |
729 | 725 | $aliases = []; |
730 | - $getAlias = function ($name) use (&$aliases) { |
|
726 | + $getAlias = function($name) use (&$aliases) { |
|
731 | 727 | // to bypass use: return $name; |
732 | - return $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases); |
|
728 | + return $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases); |
|
733 | 729 | }; |
734 | 730 | $table = $this->definition->getName(); |
735 | 731 | if ($fields !== null) { |
@@ -745,7 +741,7 @@ discard block |
||
745 | 741 | $h = $this->having; |
746 | 742 | $o = $this->order; |
747 | 743 | $g = $this->group; |
748 | - $j = array_map(function ($v) { |
|
744 | + $j = array_map(function($v) { |
|
749 | 745 | return clone $v; |
750 | 746 | }, $this->joins); |
751 | 747 | |
@@ -756,38 +752,38 @@ discard block |
||
756 | 752 | |
757 | 753 | foreach ($this->definition->getRelations() as $k => $relation) { |
758 | 754 | foreach ($f as $kk => $field) { |
759 | - if (strpos($field, $k . '.') === 0) { |
|
760 | - $relations[$k] = [ $relation, $table ]; |
|
761 | - $f[$kk] = str_replace($k . '.', $getAlias($k) . '.', $field); |
|
755 | + if (strpos($field, $k.'.') === 0) { |
|
756 | + $relations[$k] = [$relation, $table]; |
|
757 | + $f[$kk] = str_replace($k.'.', $getAlias($k).'.', $field); |
|
762 | 758 | } |
763 | 759 | } |
764 | 760 | foreach ($w as $kk => $v) { |
765 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) { |
|
766 | - $relations[$k] = [ $relation, $table ]; |
|
767 | - $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]); |
|
761 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) { |
|
762 | + $relations[$k] = [$relation, $table]; |
|
763 | + $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]); |
|
768 | 764 | } |
769 | 765 | } |
770 | 766 | foreach ($h as $kk => $v) { |
771 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) { |
|
772 | - $relations[$k] = [ $relation, $table ]; |
|
773 | - $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]); |
|
767 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) { |
|
768 | + $relations[$k] = [$relation, $table]; |
|
769 | + $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]); |
|
774 | 770 | } |
775 | 771 | } |
776 | - if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) { |
|
777 | - $relations[$k] = [ $relation, $table ]; |
|
778 | - $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]); |
|
772 | + if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) { |
|
773 | + $relations[$k] = [$relation, $table]; |
|
774 | + $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]); |
|
779 | 775 | } |
780 | - if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) { |
|
781 | - $relations[$k] = [ $relation, $table ]; |
|
782 | - $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]); |
|
776 | + if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) { |
|
777 | + $relations[$k] = [$relation, $table]; |
|
778 | + $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]); |
|
783 | 779 | } |
784 | 780 | foreach ($j as $kk => $v) { |
785 | 781 | foreach ($v->keymap as $kkk => $vv) { |
786 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) { |
|
787 | - $relations[$k] = [ $relation, $table ]; |
|
782 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) { |
|
783 | + $relations[$k] = [$relation, $table]; |
|
788 | 784 | $j[$kk]->keymap[$kkk] = preg_replace( |
789 | - '(\b'.preg_quote($k . '.'). ')i', |
|
790 | - $getAlias($k) . '.', |
|
785 | + '(\b'.preg_quote($k.'.').')i', |
|
786 | + $getAlias($k).'.', |
|
791 | 787 | $vv |
792 | 788 | ); |
793 | 789 | } |
@@ -796,11 +792,11 @@ discard block |
||
796 | 792 | } |
797 | 793 | $select = []; |
798 | 794 | foreach ($f as $k => $field) { |
799 | - $select[] = $field . (!is_numeric($k) ? ' ' . $k : ''); |
|
795 | + $select[] = $field.(!is_numeric($k) ? ' '.$k : ''); |
|
800 | 796 | } |
801 | 797 | foreach ($this->withr as $name => $relation) { |
802 | 798 | foreach ($relation[0]->table->getColumns() as $column) { |
803 | - $select[] = $getAlias($name) . '.' . $column . ' ' . $getAlias($name . static::SEP . $column); |
|
799 | + $select[] = $getAlias($name).'.'.$column.' '.$getAlias($name.static::SEP.$column); |
|
804 | 800 | } |
805 | 801 | } |
806 | 802 | $sql = 'SELECT '.implode(', ', $select).' FROM '.$this->definition->getFullName().' '; |
@@ -819,13 +815,13 @@ discard block |
||
819 | 815 | foreach ($v->keymap as $kk => $vv) { |
820 | 816 | $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' '; |
821 | 817 | } |
822 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
818 | + $sql .= implode(' AND ', $tmp).' '; |
|
823 | 819 | $sql .= 'LEFT JOIN '.$v->table->getFullName().' '.$getAlias($relation).' ON '; |
824 | 820 | $tmp = []; |
825 | 821 | foreach ($v->pivot_keymap as $kk => $vv) { |
826 | 822 | $tmp[] = $getAlias($relation).'.'.$vv.' = '.$alias.'.'.$kk.' '; |
827 | 823 | } |
828 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
824 | + $sql .= implode(' AND ', $tmp).' '; |
|
829 | 825 | } else { |
830 | 826 | $alias = $getAlias($relation); |
831 | 827 | |
@@ -835,22 +831,22 @@ discard block |
||
835 | 831 | $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' '; |
836 | 832 | } |
837 | 833 | if ($v->sql) { |
838 | - $tmp[] = $v->sql . ' '; |
|
834 | + $tmp[] = $v->sql.' '; |
|
839 | 835 | $par = array_merge($par, $v->par ?? []); |
840 | 836 | } |
841 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
837 | + $sql .= implode(' AND ', $tmp).' '; |
|
842 | 838 | } |
843 | 839 | } |
844 | 840 | foreach ($j as $k => $v) { |
845 | 841 | if ($v->many) { |
846 | 842 | $many = true; |
847 | 843 | } |
848 | - $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON '; |
|
844 | + $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON '; |
|
849 | 845 | $tmp = []; |
850 | 846 | foreach ($v->keymap as $kk => $vv) { |
851 | 847 | $tmp[] = $kk.' = '.$vv; |
852 | 848 | } |
853 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
849 | + $sql .= implode(' AND ', $tmp).' '; |
|
854 | 850 | } |
855 | 851 | if ($many && count($porder) && $this->li_of[2] === 1) { |
856 | 852 | $ids = $this->ids(); |
@@ -858,9 +854,9 @@ discard block |
||
858 | 854 | if (count($porder) > 1) { |
859 | 855 | $pkw = []; |
860 | 856 | foreach ($porder as $name) { |
861 | - $pkw[] = $name . ' = ?'; |
|
857 | + $pkw[] = $name.' = ?'; |
|
862 | 858 | } |
863 | - $pkw = '(' . implode(' AND ', $pkw) . ')'; |
|
859 | + $pkw = '('.implode(' AND ', $pkw).')'; |
|
864 | 860 | $pkp = []; |
865 | 861 | foreach ($ids as $id) { |
866 | 862 | foreach ($id as $p) { |
@@ -872,51 +868,51 @@ discard block |
||
872 | 868 | $pkp |
873 | 869 | ]; |
874 | 870 | } else { |
875 | - $w[] = [ $porder[0] . ' IN ('.implode(',', array_fill(0, count($ids), '?')).')', $ids ]; |
|
871 | + $w[] = [$porder[0].' IN ('.implode(',', array_fill(0, count($ids), '?')).')', $ids]; |
|
876 | 872 | } |
877 | 873 | } else { |
878 | - $w[] = [ '1=0', [] ]; |
|
874 | + $w[] = ['1=0', []]; |
|
879 | 875 | } |
880 | 876 | } |
881 | 877 | if (count($w)) { |
882 | 878 | $sql .= 'WHERE '; |
883 | 879 | $tmp = []; |
884 | 880 | foreach ($w as $v) { |
885 | - $tmp[] = '(' . $v[0] . ')'; |
|
881 | + $tmp[] = '('.$v[0].')'; |
|
886 | 882 | $par = array_merge($par, $v[1]); |
887 | 883 | } |
888 | 884 | $sql .= implode(' AND ', $tmp).' '; |
889 | 885 | } |
890 | 886 | if (count($g)) { |
891 | - $sql .= 'GROUP BY ' . $g[0] . ' '; |
|
887 | + $sql .= 'GROUP BY '.$g[0].' '; |
|
892 | 888 | $par = array_merge($par, $g[1]); |
893 | 889 | } |
894 | 890 | if (count($h)) { |
895 | 891 | $sql .= 'HAVING '; |
896 | 892 | $tmp = []; |
897 | 893 | foreach ($h as $v) { |
898 | - $tmp[] = '(' . $v[0] . ')'; |
|
894 | + $tmp[] = '('.$v[0].')'; |
|
899 | 895 | $par = array_merge($par, $v[1]); |
900 | 896 | } |
901 | 897 | $sql .= implode(' AND ', $tmp).' '; |
902 | 898 | } |
903 | 899 | if (count($o)) { |
904 | - $sql .= 'ORDER BY ' . $o[0] . ' '; |
|
900 | + $sql .= 'ORDER BY '.$o[0].' '; |
|
905 | 901 | $par = array_merge($par, $o[1]); |
906 | 902 | } |
907 | 903 | if (!count($g) && count($porder)) { |
908 | 904 | $pdir = (count($o) && strpos($o[0], 'DESC') !== false) ? 'DESC' : 'ASC'; |
909 | - $porder = array_map(function ($v) use ($pdir) { |
|
910 | - return $v . ' ' . $pdir; |
|
905 | + $porder = array_map(function($v) use ($pdir) { |
|
906 | + return $v.' '.$pdir; |
|
911 | 907 | }, $porder); |
912 | - $sql .= (count($o) ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' '; |
|
908 | + $sql .= (count($o) ? ', ' : 'ORDER BY ').implode(', ', $porder).' '; |
|
913 | 909 | } |
914 | 910 | if ((!$many || $this->li_of[2] === 0 || !count($porder)) && $this->li_of[0]) { |
915 | 911 | if ($this->db->driverName() === 'oracle') { |
916 | - if ((int)$this->db->driverOption('version', 0) >= 12) { |
|
917 | - $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY'; |
|
912 | + if ((int) $this->db->driverOption('version', 0) >= 12) { |
|
913 | + $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY'; |
|
918 | 914 | } else { |
919 | - $f = array_map(function ($v) { |
|
915 | + $f = array_map(function($v) { |
|
920 | 916 | $v = explode(' ', trim($v), 2); |
921 | 917 | if (count($v) === 2) { |
922 | 918 | return $v[1]; |
@@ -924,16 +920,16 @@ discard block |
||
924 | 920 | $v = explode('.', $v[0], 2); |
925 | 921 | return count($v) === 2 ? $v[1] : $v[0]; |
926 | 922 | }, $select); |
927 | - $sql = "SELECT " . implode(', ', $f) . " |
|
923 | + $sql = "SELECT ".implode(', ', $f)." |
|
928 | 924 | FROM ( |
929 | 925 | SELECT tbl__.*, rownum rnum__ FROM ( |
930 | - " . $sql . " |
|
926 | + " . $sql." |
|
931 | 927 | ) tbl__ |
932 | - WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . " |
|
928 | + WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])." |
|
933 | 929 | ) WHERE rnum__ > " . $this->li_of[1]; |
934 | 930 | } |
935 | 931 | } else { |
936 | - $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1]; |
|
932 | + $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1]; |
|
937 | 933 | } |
938 | 934 | } |
939 | 935 | return $this->qiterator = new TableQueryIterator( |
@@ -983,8 +979,8 @@ discard block |
||
983 | 979 | $ret[$k] = str_repeat(' ', 255); |
984 | 980 | $par[] = &$ret[$k]; |
985 | 981 | } |
986 | - $sql .= ' RETURNING ' . implode(',', $primary) . |
|
987 | - ' INTO ' . implode(',', array_fill(0, count($primary), '?')); |
|
982 | + $sql .= ' RETURNING '.implode(',', $primary). |
|
983 | + ' INTO '.implode(',', array_fill(0, count($primary), '?')); |
|
988 | 984 | $this->db->query($sql, $par); |
989 | 985 | return $ret; |
990 | 986 | } else { |
@@ -1016,9 +1012,9 @@ discard block |
||
1016 | 1012 | } |
1017 | 1013 | $sql = 'UPDATE '.$table.' SET '; |
1018 | 1014 | $par = []; |
1019 | - $sql .= implode(', ', array_map(function ($v) { |
|
1020 | - return $v . ' = ?'; |
|
1021 | - }, array_keys($update))) . ' '; |
|
1015 | + $sql .= implode(', ', array_map(function($v) { |
|
1016 | + return $v.' = ?'; |
|
1017 | + }, array_keys($update))).' '; |
|
1022 | 1018 | $par = array_merge($par, array_values($update)); |
1023 | 1019 | if (count($this->where)) { |
1024 | 1020 | $sql .= 'WHERE '; |
@@ -1027,7 +1023,7 @@ discard block |
||
1027 | 1023 | $tmp[] = $v[0]; |
1028 | 1024 | $par = array_merge($par, $v[1]); |
1029 | 1025 | } |
1030 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
1026 | + $sql .= implode(' AND ', $tmp).' '; |
|
1031 | 1027 | } |
1032 | 1028 | if (count($this->order)) { |
1033 | 1029 | $sql .= $this->order[0]; |
@@ -1051,7 +1047,7 @@ discard block |
||
1051 | 1047 | $tmp[] = $v[0]; |
1052 | 1048 | $par = array_merge($par, $v[1]); |
1053 | 1049 | } |
1054 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
1050 | + $sql .= implode(' AND ', $tmp).' '; |
|
1055 | 1051 | } |
1056 | 1052 | if (count($this->order)) { |
1057 | 1053 | $sql .= $this->order[0]; |
@@ -1070,18 +1066,18 @@ discard block |
||
1070 | 1066 | $table = $this->definition; |
1071 | 1067 | if ($table->hasRelation($relation)) { |
1072 | 1068 | $temp = $table->getRelation($relation); |
1073 | - $this->withr[$relation] = [ $temp, $table->getName() ]; |
|
1069 | + $this->withr[$relation] = [$temp, $table->getName()]; |
|
1074 | 1070 | } else { |
1075 | 1071 | $parts = explode('.', $relation); |
1076 | 1072 | array_reduce( |
1077 | 1073 | $parts, |
1078 | - function ($carry, $item) use (&$table) { |
|
1074 | + function($carry, $item) use (&$table) { |
|
1079 | 1075 | if (!$table->hasRelation($item)) { |
1080 | - throw new DBException('Invalid relation name: '.$table->getName().' -> ' . $item); |
|
1076 | + throw new DBException('Invalid relation name: '.$table->getName().' -> '.$item); |
|
1081 | 1077 | } |
1082 | 1078 | $relation = $table->getRelation($item); |
1083 | - $name = $carry ? $carry . static::SEP . $item : $item; |
|
1084 | - $this->withr[$name] = [ $relation, $carry ?? $table->getName() ]; |
|
1079 | + $name = $carry ? $carry.static::SEP.$item : $item; |
|
1080 | + $this->withr[$name] = [$relation, $carry ?? $table->getName()]; |
|
1085 | 1081 | $table = $relation->table; |
1086 | 1082 | return $name; |
1087 | 1083 | } |
@@ -1127,9 +1123,9 @@ discard block |
||
1127 | 1123 | } |
1128 | 1124 | |
1129 | 1125 | $aliases = []; |
1130 | - $getAlias = function ($name) use (&$aliases) { |
|
1126 | + $getAlias = function($name) use (&$aliases) { |
|
1131 | 1127 | // to bypass use: return $name; |
1132 | - return $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases); |
|
1128 | + return $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases); |
|
1133 | 1129 | }; |
1134 | 1130 | |
1135 | 1131 | $table = $this->definition->getName(); |
@@ -1141,65 +1137,65 @@ discard block |
||
1141 | 1137 | $h = $this->having; |
1142 | 1138 | $o = $this->order; |
1143 | 1139 | $g = $this->group; |
1144 | - $j = array_map(function ($v) { |
|
1140 | + $j = array_map(function($v) { |
|
1145 | 1141 | return clone $v; |
1146 | 1142 | }, $this->joins); |
1147 | 1143 | foreach ($this->definition->getRelations() as $k => $v) { |
1148 | 1144 | foreach ($w as $kk => $vv) { |
1149 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) { |
|
1150 | - $relations[$k] = [ $v, $table ]; |
|
1151 | - $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]); |
|
1145 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) { |
|
1146 | + $relations[$k] = [$v, $table]; |
|
1147 | + $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]); |
|
1152 | 1148 | } |
1153 | 1149 | } |
1154 | - if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) { |
|
1155 | - $relations[$k] = [ $v, $table ]; |
|
1156 | - $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]); |
|
1157 | - $o[2] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[2]); |
|
1150 | + if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) { |
|
1151 | + $relations[$k] = [$v, $table]; |
|
1152 | + $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]); |
|
1153 | + $o[2] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[2]); |
|
1158 | 1154 | } |
1159 | 1155 | foreach ($h as $kk => $vv) { |
1160 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) { |
|
1161 | - $relations[$k] = [ $v, $table ]; |
|
1162 | - $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]); |
|
1156 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) { |
|
1157 | + $relations[$k] = [$v, $table]; |
|
1158 | + $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]); |
|
1163 | 1159 | } |
1164 | 1160 | } |
1165 | - if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) { |
|
1166 | - $relations[$k] = [ $v, $table ]; |
|
1167 | - $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]); |
|
1161 | + if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) { |
|
1162 | + $relations[$k] = [$v, $table]; |
|
1163 | + $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]); |
|
1168 | 1164 | } |
1169 | 1165 | foreach ($j as $kk => $vv) { |
1170 | 1166 | foreach ($vv->keymap as $kkk => $vvv) { |
1171 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vvv)) { |
|
1172 | - $relations[$k] = [ $v, $table ]; |
|
1167 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $vvv)) { |
|
1168 | + $relations[$k] = [$v, $table]; |
|
1173 | 1169 | $j[$kk]->keymap[$kkk] = |
1174 | - preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vvv); |
|
1170 | + preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vvv); |
|
1175 | 1171 | } |
1176 | 1172 | } |
1177 | 1173 | } |
1178 | 1174 | } |
1179 | 1175 | |
1180 | - $key = array_map(function ($v) use ($table) { |
|
1181 | - return $table . '.' . $v; |
|
1176 | + $key = array_map(function($v) use ($table) { |
|
1177 | + return $table.'.'.$v; |
|
1182 | 1178 | }, $this->pkey); |
1183 | 1179 | $own = false; |
1184 | 1180 | $dir = 'ASC'; |
1185 | 1181 | if (count($o)) { |
1186 | 1182 | $dir = strpos($o[0], ' DESC') ? 'DESC' : 'ASC'; |
1187 | - $own = strpos($o[2], $table . '.') === 0; |
|
1183 | + $own = strpos($o[2], $table.'.') === 0; |
|
1188 | 1184 | } |
1189 | 1185 | |
1190 | 1186 | $dst = $key; |
1191 | 1187 | if (count($o)) { |
1192 | 1188 | if ($own) { |
1193 | 1189 | // if using own table - do not use max/min in order - that will prevent index usage |
1194 | - $dst[] = $o[2] . ' orderbyfix___'; |
|
1190 | + $dst[] = $o[2].' orderbyfix___'; |
|
1195 | 1191 | } else { |
1196 | - $dst[] = 'MAX(' . $o[2] . ') orderbyfix___'; |
|
1192 | + $dst[] = 'MAX('.$o[2].') orderbyfix___'; |
|
1197 | 1193 | } |
1198 | 1194 | } |
1199 | 1195 | $dst = array_unique($dst); |
1200 | 1196 | |
1201 | 1197 | $par = []; |
1202 | - $sql = 'SELECT DISTINCT '.implode(', ', $dst).' FROM '.$this->definition->getFullName().' '; |
|
1198 | + $sql = 'SELECT DISTINCT '.implode(', ', $dst).' FROM '.$this->definition->getFullName().' '; |
|
1203 | 1199 | foreach ($relations as $k => $v) { |
1204 | 1200 | $table = $v[1] !== $this->definition->getName() ? $getAlias($v[1]) : $v[1]; |
1205 | 1201 | $v = $v[0]; |
@@ -1210,13 +1206,13 @@ discard block |
||
1210 | 1206 | foreach ($v->keymap as $kk => $vv) { |
1211 | 1207 | $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' '; |
1212 | 1208 | } |
1213 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
1209 | + $sql .= implode(' AND ', $tmp).' '; |
|
1214 | 1210 | $sql .= 'LEFT JOIN '.$v->table->getName().' '.$getAlias($k).' ON '; |
1215 | 1211 | $tmp = []; |
1216 | 1212 | foreach ($v->pivot_keymap as $kk => $vv) { |
1217 | 1213 | $tmp[] = $getAlias($k).'.'.$vv.' = '.$alias.'.'.$kk.' '; |
1218 | 1214 | } |
1219 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
1215 | + $sql .= implode(' AND ', $tmp).' '; |
|
1220 | 1216 | } else { |
1221 | 1217 | $alias = $getAlias($k); |
1222 | 1218 | $sql .= 'LEFT JOIN '.$v->table->getName().' '.$alias.' ON '; |
@@ -1225,37 +1221,37 @@ discard block |
||
1225 | 1221 | $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' '; |
1226 | 1222 | } |
1227 | 1223 | if ($v->sql) { |
1228 | - $tmp[] = $v->sql . ' '; |
|
1224 | + $tmp[] = $v->sql.' '; |
|
1229 | 1225 | $par = array_merge($par, $v->par ?? []); |
1230 | 1226 | } |
1231 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
1227 | + $sql .= implode(' AND ', $tmp).' '; |
|
1232 | 1228 | } |
1233 | 1229 | } |
1234 | 1230 | foreach ($j as $k => $v) { |
1235 | - $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON '; |
|
1231 | + $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON '; |
|
1236 | 1232 | $tmp = []; |
1237 | 1233 | foreach ($v->keymap as $kk => $vv) { |
1238 | 1234 | $tmp[] = $kk.' = '.$vv; |
1239 | 1235 | } |
1240 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
1236 | + $sql .= implode(' AND ', $tmp).' '; |
|
1241 | 1237 | } |
1242 | 1238 | if (count($w)) { |
1243 | 1239 | $sql .= 'WHERE '; |
1244 | 1240 | $tmp = []; |
1245 | 1241 | foreach ($w as $v) { |
1246 | - $tmp[] = '(' . $v[0] . ')'; |
|
1242 | + $tmp[] = '('.$v[0].')'; |
|
1247 | 1243 | $par = array_merge($par, $v[1]); |
1248 | 1244 | } |
1249 | 1245 | $sql .= implode(' AND ', $tmp).' '; |
1250 | 1246 | } |
1251 | 1247 | if (!$own) { |
1252 | - $sql .= 'GROUP BY ' . implode(', ', $key) . ' '; |
|
1248 | + $sql .= 'GROUP BY '.implode(', ', $key).' '; |
|
1253 | 1249 | } |
1254 | 1250 | if (count($h)) { |
1255 | 1251 | $sql .= 'HAVING '; |
1256 | 1252 | $tmp = []; |
1257 | 1253 | foreach ($h as $v) { |
1258 | - $tmp[] = '(' . $v[0] . ')'; |
|
1254 | + $tmp[] = '('.$v[0].')'; |
|
1259 | 1255 | $par = array_merge($par, $v[1]); |
1260 | 1256 | } |
1261 | 1257 | $sql .= implode(' AND ', $tmp).' '; |
@@ -1263,38 +1259,38 @@ discard block |
||
1263 | 1259 | if (count($o)) { |
1264 | 1260 | $sql .= 'ORDER BY '; |
1265 | 1261 | if ($own) { |
1266 | - $sql .= $o[2] . ' ' . $dir; |
|
1262 | + $sql .= $o[2].' '.$dir; |
|
1267 | 1263 | } else { |
1268 | - $sql .= 'MAX('.$o[2].') ' . $dir; |
|
1264 | + $sql .= 'MAX('.$o[2].') '.$dir; |
|
1269 | 1265 | } |
1270 | 1266 | } |
1271 | 1267 | $porder = []; |
1272 | 1268 | $pdir = (count($o) && strpos($o[0], 'DESC') !== false) ? 'DESC' : 'ASC'; |
1273 | 1269 | foreach ($this->definition->getPrimaryKey() as $field) { |
1274 | - $porder[] = $this->getColumn($field)['name'] . ' ' . $pdir; |
|
1270 | + $porder[] = $this->getColumn($field)['name'].' '.$pdir; |
|
1275 | 1271 | } |
1276 | 1272 | if (count($porder)) { |
1277 | - $sql .= (count($o) ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' '; |
|
1273 | + $sql .= (count($o) ? ', ' : 'ORDER BY ').implode(', ', $porder).' '; |
|
1278 | 1274 | } |
1279 | 1275 | |
1280 | 1276 | if ($this->li_of[0]) { |
1281 | 1277 | if ($this->db->driverName() === 'oracle') { |
1282 | - if ((int)$this->db->driverOption('version', 0) >= 12) { |
|
1283 | - $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY'; |
|
1278 | + if ((int) $this->db->driverOption('version', 0) >= 12) { |
|
1279 | + $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY'; |
|
1284 | 1280 | } else { |
1285 | - $sql = "SELECT " . implode(', ', $dst) . " |
|
1281 | + $sql = "SELECT ".implode(', ', $dst)." |
|
1286 | 1282 | FROM ( |
1287 | 1283 | SELECT tbl__.*, rownum rnum__ FROM ( |
1288 | - " . $sql . " |
|
1284 | + " . $sql." |
|
1289 | 1285 | ) tbl__ |
1290 | - WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . " |
|
1286 | + WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])." |
|
1291 | 1287 | ) WHERE rnum__ > " . $this->li_of[1]; |
1292 | 1288 | } |
1293 | 1289 | } else { |
1294 | - $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1]; |
|
1290 | + $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1]; |
|
1295 | 1291 | } |
1296 | 1292 | } |
1297 | - return array_map(function ($v) { |
|
1293 | + return array_map(function($v) { |
|
1298 | 1294 | if (array_key_exists('orderbyfix___', $v)) { |
1299 | 1295 | unset($v['orderbyfix___']); |
1300 | 1296 | } |