@@ -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 | } |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | $definition = $entity->definition(); |
137 | 137 | foreach ($definition->getColumns() as $column) { |
138 | 138 | if (!array_key_exists($column, $data)) { |
139 | - $entity->__lazyProperty($column, function () use ($definition, $primary, $column) { |
|
139 | + $entity->__lazyProperty($column, function() use ($definition, $primary, $column) { |
|
140 | 140 | $query = $this->db->table($definition->getFullName()); |
141 | 141 | foreach ($primary as $k => $v) { |
142 | 142 | $query->filter($k, $v); |
@@ -150,18 +150,18 @@ discard block |
||
150 | 150 | $name, |
151 | 151 | array_key_exists($name, $data) && isset($data[$name]) ? |
152 | 152 | ($relation->many ? |
153 | - array_map(function ($v) use ($relation) { |
|
153 | + array_map(function($v) use ($relation) { |
|
154 | 154 | return $this->entity($relation->table, $v); |
155 | 155 | }, $data[$name]) : |
156 | 156 | $this->entity($relation->table, $data[$name]) |
157 | 157 | ) : |
158 | - function (array $columns = null, string $order = null, bool $desc = false) use ($entity, $definition, $relation, $data) { |
|
158 | + function(array $columns = null, string $order = null, bool $desc = false) use ($entity, $definition, $relation, $data) { |
|
159 | 159 | $query = $this->db->tableMapped($relation->table->getFullName()); |
160 | 160 | if ($columns !== null) { |
161 | 161 | $query->columns($columns); |
162 | 162 | } |
163 | 163 | if ($relation->sql) { |
164 | - $query->where($relation->sql, $relation->par?:[]); |
|
164 | + $query->where($relation->sql, $relation->par ?: []); |
|
165 | 165 | } |
166 | 166 | if ($relation->pivot) { |
167 | 167 | $nm = null; |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | ); |
182 | 182 | } |
183 | 183 | foreach ($definition->getPrimaryKey() as $v) { |
184 | - $query->filter($nm . '.' . $v, $data[$v] ?? null); |
|
184 | + $query->filter($nm.'.'.$v, $data[$v] ?? null); |
|
185 | 185 | } |
186 | 186 | } else { |
187 | 187 | foreach ($relation->keymap as $k => $v) { |
@@ -192,8 +192,7 @@ discard block |
||
192 | 192 | $query->sort($order, $desc); |
193 | 193 | } |
194 | 194 | return $relation->many ? |
195 | - $query->iterator() : |
|
196 | - $query[0]; |
|
195 | + $query->iterator() : $query[0]; |
|
197 | 196 | } |
198 | 197 | ); |
199 | 198 | } |
@@ -37,8 +37,7 @@ discard block |
||
37 | 37 | $temp = @\pg_query( |
38 | 38 | $this->driver, |
39 | 39 | $sequence ? |
40 | - 'SELECT currval('.@\pg_escape_string($this->driver, $sequence).')' : |
|
41 | - 'SELECT lastval()' |
|
40 | + 'SELECT currval('.@\pg_escape_string($this->driver, $sequence).')' : 'SELECT lastval()' |
|
42 | 41 | ); |
43 | 42 | if ($temp) { |
44 | 43 | $res = \pg_fetch_row($temp); |
@@ -76,8 +75,8 @@ discard block |
||
76 | 75 | } |
77 | 76 | public function next(): void |
78 | 77 | { |
79 | - $this->fetched ++; |
|
80 | - $this->last = \pg_fetch_array($this->statement, null, \PGSQL_ASSOC)?:null; |
|
78 | + $this->fetched++; |
|
79 | + $this->last = \pg_fetch_array($this->statement, null, \PGSQL_ASSOC) ?: null; |
|
81 | 80 | if (is_array($this->last) && count($this->last)) { |
82 | 81 | $this->cast(); |
83 | 82 | } |
@@ -102,15 +101,15 @@ discard block |
||
102 | 101 | case 'int2': |
103 | 102 | case 'int4': |
104 | 103 | case 'int8': |
105 | - $this->last[$k] = (int)$v; |
|
104 | + $this->last[$k] = (int) $v; |
|
106 | 105 | break; |
107 | 106 | case 'bit': |
108 | 107 | case 'bool': |
109 | - $this->last[$k] = $v !== 'f' && (int)$v ? true : false; |
|
108 | + $this->last[$k] = $v !== 'f' && (int) $v ? true : false; |
|
110 | 109 | break; |
111 | 110 | case 'float4': |
112 | 111 | case 'float8': |
113 | - $this->last[$k] = (float)$v; |
|
112 | + $this->last[$k] = (float) $v; |
|
114 | 113 | case 'money': |
115 | 114 | case 'numeric': |
116 | 115 | // TODO: |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | } |
25 | 25 | public function affected() : int |
26 | 26 | { |
27 | - return (int)\oci_num_rows($this->statement); |
|
27 | + return (int) \oci_num_rows($this->statement); |
|
28 | 28 | } |
29 | 29 | public function insertID(string $sequence = null): mixed |
30 | 30 | { |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | |
38 | 38 | public function count(): int |
39 | 39 | { |
40 | - return (int)\oci_num_rows($this->statement); |
|
40 | + return (int) \oci_num_rows($this->statement); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | public function key(): mixed |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | } |
66 | 66 | public function next(): void |
67 | 67 | { |
68 | - $this->fetched ++; |
|
69 | - $this->last = \oci_fetch_array($this->statement, \OCI_ASSOC + \OCI_RETURN_NULLS + \OCI_RETURN_LOBS)?:null; |
|
68 | + $this->fetched++; |
|
69 | + $this->last = \oci_fetch_array($this->statement, \OCI_ASSOC +\OCI_RETURN_NULLS +\OCI_RETURN_LOBS) ?: null; |
|
70 | 70 | if (is_array($this->last) && count($this->last)) { |
71 | 71 | $this->cast(); |
72 | 72 | } |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | $this->types[$v] = \oci_field_type($this->statement, $k + 1); |
83 | 83 | if ($this->types[$v] === 'NUMBER') { |
84 | 84 | $size = \oci_field_size($this->statement, $k + 1); |
85 | - if ((int)(explode(',', $size, 2)[1] ?? '') > 0) { |
|
85 | + if ((int) (explode(',', $size, 2)[1] ?? '') > 0) { |
|
86 | 86 | $this->types[$v] === 'FLOAT'; |
87 | 87 | } |
88 | 88 | } |
@@ -94,10 +94,10 @@ discard block |
||
94 | 94 | } |
95 | 95 | switch ($this->types[$k]) { |
96 | 96 | case 'NUMBER': |
97 | - $this->last[$k] = (int)$v; |
|
97 | + $this->last[$k] = (int) $v; |
|
98 | 98 | break; |
99 | 99 | case 'FLOAT': |
100 | - $this->last[$k] = (float)$v; |
|
100 | + $this->last[$k] = (float) $v; |
|
101 | 101 | break; |
102 | 102 | } |
103 | 103 | } |
@@ -69,18 +69,18 @@ discard block |
||
69 | 69 | ]; |
70 | 70 | } |
71 | 71 | } |
72 | - $connection['type'] = isset($temp['scheme']) && strlen((string)$temp['scheme']) ? $temp['scheme'] : null; |
|
73 | - $connection['user'] = isset($temp['user']) && strlen((string)$temp['user']) ? $temp['user'] : null; |
|
74 | - $connection['pass'] = isset($temp['pass']) && strlen((string)$temp['pass']) ? $temp['pass'] : null; |
|
75 | - $connection['host'] = isset($temp['host']) && strlen((string)$temp['host']) ? $temp['host'] : null; |
|
76 | - $connection['name'] = isset($temp['path']) && strlen((string)$temp['path']) ? trim((string)$temp['path'], '/') : null; |
|
77 | - $connection['port'] = isset($temp['port']) && (int)$temp['port'] ? (int)$temp['port'] : null; |
|
78 | - if (isset($temp['query']) && strlen((string)$temp['query'])) { |
|
79 | - parse_str((string)$temp['query'], $connection['opts']); |
|
72 | + $connection['type'] = isset($temp['scheme']) && strlen((string) $temp['scheme']) ? $temp['scheme'] : null; |
|
73 | + $connection['user'] = isset($temp['user']) && strlen((string) $temp['user']) ? $temp['user'] : null; |
|
74 | + $connection['pass'] = isset($temp['pass']) && strlen((string) $temp['pass']) ? $temp['pass'] : null; |
|
75 | + $connection['host'] = isset($temp['host']) && strlen((string) $temp['host']) ? $temp['host'] : null; |
|
76 | + $connection['name'] = isset($temp['path']) && strlen((string) $temp['path']) ? trim((string) $temp['path'], '/') : null; |
|
77 | + $connection['port'] = isset($temp['port']) && (int) $temp['port'] ? (int) $temp['port'] : null; |
|
78 | + if (isset($temp['query']) && strlen((string) $temp['query'])) { |
|
79 | + parse_str((string) $temp['query'], $connection['opts']); |
|
80 | 80 | } |
81 | 81 | // create the driver |
82 | 82 | $connection['type'] = $aliases[$connection['type']] ?? $connection['type']; |
83 | - $tmp = '\\vakata\\database\\driver\\'.strtolower((string)$connection['type']).'\\Driver'; |
|
83 | + $tmp = '\\vakata\\database\\driver\\'.strtolower((string) $connection['type']).'\\Driver'; |
|
84 | 84 | if (!class_exists($tmp)) { |
85 | 85 | throw new DBException('Unknown DB backend'); |
86 | 86 | } |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | $new = ''; |
119 | 119 | $par = array_values($par); |
120 | 120 | if (substr_count($sql, '?') === 2 && !is_array($par[0])) { |
121 | - $par = [ $par ]; |
|
121 | + $par = [$par]; |
|
122 | 122 | } |
123 | 123 | $parts = explode('??', $sql); |
124 | 124 | $index = 0; |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | $index += count($tmp) - 1; |
129 | 129 | if (isset($par[$index])) { |
130 | 130 | if (!is_array($par[$index])) { |
131 | - $par[$index] = [ $par[$index] ]; |
|
131 | + $par[$index] = [$par[$index]]; |
|
132 | 132 | } |
133 | 133 | $params = $par[$index]; |
134 | 134 | array_splice($par, $index, 1, $params); |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | $new .= implode(',', array_fill(0, count($params), '?')); |
137 | 137 | } |
138 | 138 | } |
139 | - return [ $new, $par ]; |
|
139 | + return [$new, $par]; |
|
140 | 140 | } |
141 | 141 | /** |
142 | 142 | * Run a query (prepare & execute). |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | ): Collection { |
186 | 186 | $coll = Collection::from($this->query($sql, $par, $buff)); |
187 | 187 | if (($keys = $this->driver->option('mode')) && in_array($keys, ['strtoupper', 'strtolower'])) { |
188 | - $coll->map(function ($v) use ($keys) { |
|
188 | + $coll->map(function($v) use ($keys) { |
|
189 | 189 | $new = []; |
190 | 190 | foreach ($v as $k => $vv) { |
191 | 191 | $new[call_user_func($keys, $k)] = $vv; |
@@ -194,18 +194,18 @@ discard block |
||
194 | 194 | }); |
195 | 195 | } |
196 | 196 | if ($key !== null) { |
197 | - $coll->mapKey(function ($v) use ($key) { |
|
197 | + $coll->mapKey(function($v) use ($key) { |
|
198 | 198 | return $v[$key]; |
199 | 199 | }); |
200 | 200 | } |
201 | 201 | if ($skip) { |
202 | - $coll->map(function ($v) use ($key) { |
|
202 | + $coll->map(function($v) use ($key) { |
|
203 | 203 | unset($v[$key]); |
204 | 204 | return $v; |
205 | 205 | }); |
206 | 206 | } |
207 | 207 | if ($opti) { |
208 | - $coll->map(function ($v) { |
|
208 | + $coll->map(function($v) { |
|
209 | 209 | return count($v) === 1 ? current($v) : $v; |
210 | 210 | }); |
211 | 211 | } |
@@ -324,13 +324,13 @@ discard block |
||
324 | 324 | */ |
325 | 325 | public function getSchema(bool $asPlainArray = true): array |
326 | 326 | { |
327 | - return !$asPlainArray ? $this->tables : array_map(function ($table) { |
|
327 | + return !$asPlainArray ? $this->tables : array_map(function($table) { |
|
328 | 328 | return [ |
329 | 329 | 'name' => $table->getName(), |
330 | 330 | 'schema' => $table->getSchema(), |
331 | 331 | 'pkey' => $table->getPrimaryKey(), |
332 | 332 | 'comment' => $table->getComment(), |
333 | - 'columns' => array_map(function ($column) { |
|
333 | + 'columns' => array_map(function($column) { |
|
334 | 334 | return [ |
335 | 335 | 'name' => $column->getName(), |
336 | 336 | 'type' => $column->getType(), |
@@ -341,9 +341,9 @@ discard block |
||
341 | 341 | 'nullable' => $column->isNullable() |
342 | 342 | ]; |
343 | 343 | }, $table->getFullColumns()), |
344 | - 'relations' => array_map(function ($rel) { |
|
344 | + 'relations' => array_map(function($rel) { |
|
345 | 345 | $relation = clone $rel; |
346 | - $relation = (array)$relation; |
|
346 | + $relation = (array) $relation; |
|
347 | 347 | $relation['table'] = $rel->table->getName(); |
348 | 348 | if ($rel->pivot) { |
349 | 349 | $relation['pivot'] = $rel->pivot->getName(); |
@@ -405,11 +405,10 @@ discard block |
||
405 | 405 | { |
406 | 406 | return new TableQueryMapped($this, $this->definition($table), $findRelations); |
407 | 407 | } |
408 | - public function __call(string $method, array $args): TableQuery|TableQueryMapped |
|
408 | + public function __call(string $method, array $args): TableQuery | TableQueryMapped |
|
409 | 409 | { |
410 | 410 | return ($args[0] ?? false) ? |
411 | - $this->tableMapped($method, $args[1] ?? false) : |
|
412 | - $this->table($method, $args[1] ?? false); |
|
411 | + $this->tableMapped($method, $args[1] ?? false) : $this->table($method, $args[1] ?? false); |
|
413 | 412 | } |
414 | 413 | public function findRelation(string $start, string $end): array |
415 | 414 | { |
@@ -442,12 +441,12 @@ discard block |
||
442 | 441 | $relations[$t] = $w; |
443 | 442 | } |
444 | 443 | if (!isset($schema[$name])) { |
445 | - $schema[$name] = [ 'edges' => [] ]; |
|
444 | + $schema[$name] = ['edges' => []]; |
|
446 | 445 | } |
447 | 446 | foreach ($relations as $t => $w) { |
448 | 447 | $schema[$name]['edges'][$t] = $w; |
449 | 448 | if (!isset($schema[$t])) { |
450 | - $schema[$t] = [ 'edges' => [] ]; |
|
449 | + $schema[$t] = ['edges' => []]; |
|
451 | 450 | } |
452 | 451 | $schema[$t]['edges'][$name] = $w; |
453 | 452 | } |
@@ -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,20 +123,20 @@ 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; |
130 | 130 | }) |
131 | 131 | ->toArray(); |
132 | 132 | if (!count($columns)) { |
133 | - throw new DBException('Table not found by name: ' . implode('.', [$schema,$table])); |
|
133 | + throw new DBException('Table not found by name: '.implode('.', [$schema, $table])); |
|
134 | 134 | } |
135 | 135 | $pkname = Collection::from($this |
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(''); |
@@ -161,8 +161,8 @@ discard block |
||
161 | 161 | // assuming current table is on the "one" end having "many" records in the referencing table |
162 | 162 | // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected) |
163 | 163 | $relations = []; |
164 | - foreach ($relationsR[$schema . '.' . $table] ?? [] as $relation) { |
|
165 | - $relations[$relation['constraint_name']]['table'] = $relation['table_schema'] . '.' . $relation['table_name']; |
|
164 | + foreach ($relationsR[$schema.'.'.$table] ?? [] as $relation) { |
|
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']; |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | $definition->getName() == $relname || |
203 | 203 | $definition->getColumn($relname) |
204 | 204 | ) { |
205 | - $relname = $orig . '_' . (++ $cntr); |
|
205 | + $relname = $orig.'_'.(++$cntr); |
|
206 | 206 | } |
207 | 207 | $definition->addRelation( |
208 | 208 | new TableRelation( |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | $definition->getName() == $relname || |
228 | 228 | $definition->getColumn($relname) |
229 | 229 | ) { |
230 | - $relname = $orig . '_' . (++ $cntr); |
|
230 | + $relname = $orig.'_'.(++$cntr); |
|
231 | 231 | } |
232 | 232 | $definition->addRelation( |
233 | 233 | new TableRelation( |
@@ -243,8 +243,8 @@ discard block |
||
243 | 243 | // assuming current table is linked to "one" record in the referenced table |
244 | 244 | // resulting in a "belongsTo" relationship |
245 | 245 | $relations = []; |
246 | - foreach ($relationsT[$schema . '.' . $table] ?? [] as $relation) { |
|
247 | - $relations[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' . $relation['referenced_table_name']; |
|
246 | + foreach ($relationsT[$schema.'.'.$table] ?? [] as $relation) { |
|
247 | + $relations[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'.$relation['referenced_table_name']; |
|
248 | 248 | $relations[$relation['constraint_name']]['keymap'][$relation['column_name']] = |
249 | 249 | $relation['referenced_column_name']; |
250 | 250 | } |
@@ -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( |
@@ -280,19 +280,19 @@ discard block |
||
280 | 280 | $tables = Collection::from($this |
281 | 281 | ->query( |
282 | 282 | "SELECT table_name FROM information_schema.tables where table_schema = ? AND table_catalog = ?", |
283 | - [ $this->connection['opts']['schema'] ?? 'public', $this->connection['name'] ] |
|
283 | + [$this->connection['opts']['schema'] ?? 'public', $this->connection['name']] |
|
284 | 284 | )) |
285 | - ->mapKey(function ($v) { |
|
285 | + ->mapKey(function($v) { |
|
286 | 286 | return strtolower($v['table_name']); |
287 | 287 | }) |
288 | 288 | ->pluck('table_name') |
289 | - ->map(function ($v) { |
|
289 | + ->map(function($v) { |
|
290 | 290 | return $this->table($v)->toLowerCase(); |
291 | 291 | }) |
292 | 292 | ->toArray(); |
293 | 293 | |
294 | 294 | foreach (array_keys($tables) as $k) { |
295 | - $tables[($this->connection['opts']['schema'] ?? 'public') . '.' . $k] = &$tables[$k]; |
|
295 | + $tables[($this->connection['opts']['schema'] ?? 'public').'.'.$k] = &$tables[$k]; |
|
296 | 296 | } |
297 | 297 | return $tables; |
298 | 298 | } |
@@ -27,8 +27,8 @@ discard block |
||
27 | 27 | $table = $temp[1]; |
28 | 28 | } |
29 | 29 | |
30 | - if (isset($tables[$schema . '.' . $table])) { |
|
31 | - return $tables[$schema . '.' . $table]; |
|
30 | + if (isset($tables[$schema.'.'.$table])) { |
|
31 | + return $tables[$schema.'.'.$table]; |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | static $comments = []; |
@@ -36,10 +36,10 @@ discard block |
||
36 | 36 | $comments[$schema] = Collection::from( |
37 | 37 | $this->query( |
38 | 38 | "SELECT TABLE_NAME, TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ?", |
39 | - [ $schema ] |
|
39 | + [$schema] |
|
40 | 40 | ) |
41 | 41 | ) |
42 | - ->mapKey(function (array $v): string { |
|
42 | + ->mapKey(function(array $v): string { |
|
43 | 43 | return $v['TABLE_NAME']; |
44 | 44 | }) |
45 | 45 | ->pluck('TABLE_COMMENT') |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | WHERE |
60 | 60 | (TABLE_SCHEMA = ? OR REFERENCED_TABLE_SCHEMA = ?) AND |
61 | 61 | TABLE_NAME IS NOT NULL AND REFERENCED_TABLE_NAME IS NOT NULL", |
62 | - [ $main, $main ] |
|
62 | + [$main, $main] |
|
63 | 63 | ) |
64 | 64 | )->toArray(); |
65 | 65 | foreach ($col as $row) { |
@@ -69,8 +69,8 @@ discard block |
||
69 | 69 | if ($row['REFERENCED_TABLE_SCHEMA'] !== $main) { |
70 | 70 | $additional[] = $row['REFERENCED_TABLE_SCHEMA']; |
71 | 71 | } |
72 | - $relationsT[$row['TABLE_SCHEMA'] . '.' . $row['TABLE_NAME']][] = $row; |
|
73 | - $relationsR[$row['REFERENCED_TABLE_SCHEMA'] . '.' . $row['REFERENCED_TABLE_NAME']][] = $row; |
|
72 | + $relationsT[$row['TABLE_SCHEMA'].'.'.$row['TABLE_NAME']][] = $row; |
|
73 | + $relationsR[$row['REFERENCED_TABLE_SCHEMA'].'.'.$row['REFERENCED_TABLE_NAME']][] = $row; |
|
74 | 74 | } |
75 | 75 | foreach (array_filter(array_unique($additional)) as $s) { |
76 | 76 | $col = Collection::from( |
@@ -80,12 +80,12 @@ discard block |
||
80 | 80 | WHERE |
81 | 81 | TABLE_SCHEMA = ? AND REFERENCED_TABLE_SCHEMA = ? AND |
82 | 82 | TABLE_NAME IS NOT NULL AND REFERENCED_TABLE_NAME IS NOT NULL", |
83 | - [ $s, $s ] |
|
83 | + [$s, $s] |
|
84 | 84 | ) |
85 | 85 | )->toArray(); |
86 | 86 | foreach ($col as $row) { |
87 | - $relationsT[$row['TABLE_SCHEMA'] . '.' . $row['TABLE_NAME']][] = $row; |
|
88 | - $relationsR[$row['REFERENCED_TABLE_SCHEMA'] . '.' . $row['REFERENCED_TABLE_NAME']][] = $row; |
|
87 | + $relationsT[$row['TABLE_SCHEMA'].'.'.$row['TABLE_NAME']][] = $row; |
|
88 | + $relationsR[$row['REFERENCED_TABLE_SCHEMA'].'.'.$row['REFERENCED_TABLE_NAME']][] = $row; |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | } |
@@ -94,14 +94,14 @@ discard block |
||
94 | 94 | if (!count($columns)) { |
95 | 95 | throw new DBException('Table not found by name'); |
96 | 96 | } |
97 | - $tables[$schema . '.' . $table] = $definition = (new Table($table, $schema)) |
|
97 | + $tables[$schema.'.'.$table] = $definition = (new Table($table, $schema)) |
|
98 | 98 | ->addColumns( |
99 | 99 | $columns |
100 | 100 | ->clone() |
101 | - ->mapKey(function (array $v): string { |
|
101 | + ->mapKey(function(array $v): string { |
|
102 | 102 | return $v['Field']; |
103 | 103 | }) |
104 | - ->map(function (array $v): array { |
|
104 | + ->map(function(array $v): array { |
|
105 | 105 | $v['length'] = null; |
106 | 106 | if (!isset($v['Type'])) { |
107 | 107 | return $v; |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | default: |
124 | 124 | if (strpos($type, 'char') !== false && strpos($type, '(') !== false) { |
125 | 125 | // extract length from varchar |
126 | - $v['length'] = (int)explode(')', explode('(', $type)[1])[0]; |
|
126 | + $v['length'] = (int) explode(')', explode('(', $type)[1])[0]; |
|
127 | 127 | $v['length'] = $v['length'] > 0 ? $v['length'] : null; |
128 | 128 | } |
129 | 129 | break; |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | ->setPrimaryKey( |
136 | 136 | $columns |
137 | 137 | ->clone() |
138 | - ->filter(function (array $v): bool { |
|
138 | + ->filter(function(array $v): bool { |
|
139 | 139 | return $v['Key'] === 'PRI'; |
140 | 140 | }) |
141 | 141 | ->pluck('Field') |
@@ -149,8 +149,8 @@ discard block |
||
149 | 149 | // assuming current table is on the "one" end having "many" records in the referencing table |
150 | 150 | // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected) |
151 | 151 | $relations = []; |
152 | - foreach ($relationsR[$schema . '.' . $table] ?? [] as $relation) { |
|
153 | - $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_SCHEMA'] . '.' . $relation['TABLE_NAME']; |
|
152 | + foreach ($relationsR[$schema.'.'.$table] ?? [] as $relation) { |
|
153 | + $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_SCHEMA'].'.'.$relation['TABLE_NAME']; |
|
154 | 154 | $relations[$relation['CONSTRAINT_NAME']]['keymap'][$relation['REFERENCED_COLUMN_NAME']] = |
155 | 155 | $relation['COLUMN_NAME']; |
156 | 156 | } |
@@ -166,10 +166,10 @@ discard block |
||
166 | 166 | $usedcol = []; |
167 | 167 | if (count($columns)) { |
168 | 168 | foreach (Collection::from($relationsT[$data['table']] ?? []) |
169 | - ->filter(function (array $v) use ($columns): bool { |
|
169 | + ->filter(function(array $v) use ($columns): bool { |
|
170 | 170 | return in_array($v['COLUMN_NAME'], $columns); |
171 | 171 | }) |
172 | - ->map(function (array $v): array { |
|
172 | + ->map(function(array $v): array { |
|
173 | 173 | $new = []; |
174 | 174 | foreach ($v as $kk => $vv) { |
175 | 175 | $new[strtoupper($kk)] = $vv; |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | return $new; |
178 | 178 | }) as $relation |
179 | 179 | ) { |
180 | - $foreign[$relation['CONSTRAINT_NAME']]['table'] = $relation['REFERENCED_TABLE_SCHEMA'] . '.' . $relation['REFERENCED_TABLE_NAME']; |
|
180 | + $foreign[$relation['CONSTRAINT_NAME']]['table'] = $relation['REFERENCED_TABLE_SCHEMA'].'.'.$relation['REFERENCED_TABLE_NAME']; |
|
181 | 181 | $foreign[$relation['CONSTRAINT_NAME']]['keymap'][$relation['COLUMN_NAME']] = |
182 | 182 | $relation['REFERENCED_COLUMN_NAME']; |
183 | 183 | $usedcol[] = $relation['COLUMN_NAME']; |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | $orig = $relname; |
194 | 194 | $cntr = 1; |
195 | 195 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
196 | - $relname = $orig . '_' . (++ $cntr); |
|
196 | + $relname = $orig.'_'.(++$cntr); |
|
197 | 197 | } |
198 | 198 | $definition->addRelation( |
199 | 199 | new TableRelation( |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | $orig = $relname; |
215 | 215 | $cntr = 1; |
216 | 216 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
217 | - $relname = $orig . '_' . (++ $cntr); |
|
217 | + $relname = $orig.'_'.(++$cntr); |
|
218 | 218 | } |
219 | 219 | $definition->addRelation( |
220 | 220 | new TableRelation( |
@@ -230,8 +230,8 @@ discard block |
||
230 | 230 | // assuming current table is linked to "one" record in the referenced table |
231 | 231 | // resulting in a "belongsTo" relationship |
232 | 232 | $relations = []; |
233 | - foreach (Collection::from($relationsT[$schema . '.' . $table] ?? []) |
|
234 | - ->map(function (array $v): array { |
|
233 | + foreach (Collection::from($relationsT[$schema.'.'.$table] ?? []) |
|
234 | + ->map(function(array $v): array { |
|
235 | 235 | $new = []; |
236 | 236 | foreach ($v as $kk => $vv) { |
237 | 237 | $new[strtoupper($kk)] = $vv; |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | return $new; |
240 | 240 | }) as $relation |
241 | 241 | ) { |
242 | - $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['REFERENCED_TABLE_SCHEMA'] . '.' . $relation['REFERENCED_TABLE_NAME']; |
|
242 | + $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['REFERENCED_TABLE_SCHEMA'].'.'.$relation['REFERENCED_TABLE_NAME']; |
|
243 | 243 | $relations[$relation['CONSTRAINT_NAME']]['keymap'][$relation['COLUMN_NAME']] = |
244 | 244 | $relation['REFERENCED_COLUMN_NAME']; |
245 | 245 | } |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | $orig = $relname; |
253 | 253 | $cntr = 1; |
254 | 254 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
255 | - $relname = $orig . '_' . (++ $cntr); |
|
255 | + $relname = $orig.'_'.(++$cntr); |
|
256 | 256 | } |
257 | 257 | $definition->addRelation( |
258 | 258 | new TableRelation( |
@@ -273,23 +273,23 @@ discard block |
||
273 | 273 | "SELECT table_name FROM information_schema.tables where table_schema = ?", |
274 | 274 | [$this->connection['opts']['schema'] ?? $this->connection['name']] |
275 | 275 | )) |
276 | - ->map(function (array $v): array { |
|
276 | + ->map(function(array $v): array { |
|
277 | 277 | $new = []; |
278 | 278 | foreach ($v as $kk => $vv) { |
279 | 279 | $new[strtoupper($kk)] = $vv; |
280 | 280 | } |
281 | 281 | return $new; |
282 | 282 | }) |
283 | - ->mapKey(function (array $v): string { |
|
283 | + ->mapKey(function(array $v): string { |
|
284 | 284 | return strtolower($v['TABLE_NAME']); |
285 | 285 | }) |
286 | 286 | ->pluck('TABLE_NAME') |
287 | - ->map(function (string $v): Table { |
|
287 | + ->map(function(string $v): Table { |
|
288 | 288 | return $this->table($v)->toLowerCase(); |
289 | 289 | }) |
290 | 290 | ->toArray(); |
291 | 291 | foreach (array_keys($tables) as $k) { |
292 | - $tables[($this->connection['opts']['schema'] ?? $this->connection['name']) . '.' . $k] = &$tables[$k]; |
|
292 | + $tables[($this->connection['opts']['schema'] ?? $this->connection['name']).'.'.$k] = &$tables[$k]; |
|
293 | 293 | } |
294 | 294 | return $tables; |
295 | 295 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | $instance->setLength($data['length']); |
52 | 52 | } |
53 | 53 | if ($instance->getBasicType() === 'enum' && strpos($instance->getType(), 'enum(') === 0) { |
54 | - $temp = array_map(function ($v) { |
|
54 | + $temp = array_map(function($v) { |
|
55 | 55 | return str_replace("''", "'", $v); |
56 | 56 | }, explode("','", substr($instance->getType(), 6, -2))); |
57 | 57 | $instance->setValues($temp); |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | $instance->setDefault(null); |
81 | 81 | } |
82 | 82 | } |
83 | - if ($instance->getBasicType() === 'text' && isset($data['CHAR_LENGTH']) && (int)$data['CHAR_LENGTH']) { |
|
83 | + if ($instance->getBasicType() === 'text' && isset($data['CHAR_LENGTH']) && (int) $data['CHAR_LENGTH']) { |
|
84 | 84 | $instance->setLength($data['CHAR_LENGTH']); |
85 | 85 | } |
86 | 86 | return $instance; |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | } |
175 | 175 | public function getLength(): int |
176 | 176 | { |
177 | - return (int)$this->length; |
|
177 | + return (int) $this->length; |
|
178 | 178 | } |
179 | 179 | public function setLength(int $length): static |
180 | 180 | { |
@@ -127,7 +127,7 @@ |
||
127 | 127 | $this->btype = 'enum'; |
128 | 128 | } elseif (strpos($type, 'json') !== false) { |
129 | 129 | $this->btype = 'json'; |
130 | - } elseif (strpos($type, 'text') !== false || strpos($type, 'char') !== false) { |
|
130 | + } elseif (strpos($type, 'text') !== false || strpos($type, 'char') !== false) { |
|
131 | 131 | $this->btype = 'text'; |
132 | 132 | } elseif (strpos($type, 'int') !== false || |
133 | 133 | strpos($type, 'bit') !== false || |
@@ -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,0]; |
|
25 | + protected array $li_of = [0, 0, 0]; |
|
26 | 26 | protected array $fields = []; |
27 | 27 | protected array $withr = []; |
28 | 28 | protected array $joins = []; |
@@ -36,11 +36,11 @@ discard block |
||
36 | 36 | * @param Table|string $table the name or definition of the main table in the query |
37 | 37 | * @param bool $findRelations should the query builder try to find missing joins |
38 | 38 | */ |
39 | - public function __construct(DBInterface $db, Table|string $table, bool $findRelations = false) |
|
39 | + public function __construct(DBInterface $db, Table | string $table, bool $findRelations = false) |
|
40 | 40 | { |
41 | 41 | $this->db = $db; |
42 | 42 | $this->findRelations = $findRelations; |
43 | - $this->definition = $table instanceof Table ? $table : $this->db->definition((string)$table); |
|
43 | + $this->definition = $table instanceof Table ? $table : $this->db->definition((string) $table); |
|
44 | 44 | $primary = $this->definition->getPrimaryKey(); |
45 | 45 | $columns = $this->definition->getColumns(); |
46 | 46 | $this->pkey = count($primary) ? $primary : $columns; |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | { |
64 | 64 | $column = explode('.', $column); |
65 | 65 | if (count($column) === 1) { |
66 | - $column = [ $this->definition->getFullName(), $column[0] ]; |
|
66 | + $column = [$this->definition->getFullName(), $column[0]]; |
|
67 | 67 | $col = $this->definition->getColumn($column[1]); |
68 | 68 | if (!$col) { |
69 | 69 | throw new DBException('Invalid column name in own table'); |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | $path = $this->db->findRelation($this->definition->getName(), $column[0]); |
103 | 103 | } |
104 | 104 | if (!count($path)) { |
105 | - throw new DBException('Invalid foreign table / column name: ' . implode(',', $column)); |
|
105 | + throw new DBException('Invalid foreign table / column name: '.implode(',', $column)); |
|
106 | 106 | } |
107 | 107 | unset($path[0]); |
108 | 108 | $this->with(implode('.', $path), false); |
@@ -115,26 +115,26 @@ discard block |
||
115 | 115 | if ($this->definition->hasRelation(implode('.', $column))) { |
116 | 116 | $this->with(implode('.', $column), false); |
117 | 117 | $col = $this->definition->getRelation(implode('.', $column))?->table?->getColumn($name); |
118 | - $column = [ implode('.', $column), $name ]; |
|
118 | + $column = [implode('.', $column), $name]; |
|
119 | 119 | } else { |
120 | 120 | $this->with(implode('.', $column), false); |
121 | 121 | $table = $this->definition; |
122 | 122 | $table = array_reduce( |
123 | 123 | $column, |
124 | - function ($carry, $item) use (&$table) { |
|
124 | + function($carry, $item) use (&$table) { |
|
125 | 125 | $table = $table->getRelation($item)->table; |
126 | 126 | return $table; |
127 | 127 | } |
128 | 128 | ); |
129 | 129 | $col = $table->getColumn($name); |
130 | - $column = [ implode(static::SEP, $column), $name ]; |
|
130 | + $column = [implode(static::SEP, $column), $name]; |
|
131 | 131 | } |
132 | 132 | } |
133 | - return [ 'name' => implode('.', $column), 'data' => $col ]; |
|
133 | + return ['name' => implode('.', $column), 'data' => $col]; |
|
134 | 134 | } |
135 | 135 | protected function normalizeValue(TableColumn $col, mixed $value): mixed |
136 | 136 | { |
137 | - $strict = (int)$this->db->driverOption('strict', 0) > 0; |
|
137 | + $strict = (int) $this->db->driverOption('strict', 0) > 0; |
|
138 | 138 | if ($value === null && $col->isNullable()) { |
139 | 139 | return null; |
140 | 140 | } |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | $temp = strtotime($value); |
145 | 145 | if (!$temp) { |
146 | 146 | if ($strict) { |
147 | - throw new DBException('Invalid value for date column ' . $col->getName()); |
|
147 | + throw new DBException('Invalid value for date column '.$col->getName()); |
|
148 | 148 | } |
149 | 149 | return null; |
150 | 150 | } |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | return $value->format('Y-m-d'); |
158 | 158 | } |
159 | 159 | if ($strict) { |
160 | - throw new DBException('Invalid value (unknown data type) for date column ' . $col->getName()); |
|
160 | + throw new DBException('Invalid value (unknown data type) for date column '.$col->getName()); |
|
161 | 161 | } |
162 | 162 | return $value; |
163 | 163 | case 'datetime': |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | $temp = strtotime($value); |
166 | 166 | if (!$temp) { |
167 | 167 | if ($strict) { |
168 | - throw new DBException('Invalid value for datetime column ' . $col->getName()); |
|
168 | + throw new DBException('Invalid value for datetime column '.$col->getName()); |
|
169 | 169 | } |
170 | 170 | return null; |
171 | 171 | } |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | return $value->format('Y-m-d H:i:s'); |
179 | 179 | } |
180 | 180 | if ($strict) { |
181 | - throw new DBException('Invalid value (unknown data type) for datetime column ' . $col->getName()); |
|
181 | + throw new DBException('Invalid value (unknown data type) for datetime column '.$col->getName()); |
|
182 | 182 | } |
183 | 183 | return $value; |
184 | 184 | case 'enum': |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | if (is_int($value)) { |
187 | 187 | if (!isset($values[$value])) { |
188 | 188 | if ($strict) { |
189 | - throw new DBException('Invalid value (using integer) for enum ' . $col->getName()); |
|
189 | + throw new DBException('Invalid value (using integer) for enum '.$col->getName()); |
|
190 | 190 | } |
191 | 191 | return $value; |
192 | 192 | } |
@@ -194,23 +194,23 @@ discard block |
||
194 | 194 | } |
195 | 195 | if (!in_array($value, $col->getValues())) { |
196 | 196 | if ($strict) { |
197 | - throw new DBException('Invalid value for enum ' . $col->getName()); |
|
197 | + throw new DBException('Invalid value for enum '.$col->getName()); |
|
198 | 198 | } |
199 | 199 | return 0; |
200 | 200 | } |
201 | 201 | return $value; |
202 | 202 | case 'int': |
203 | 203 | $temp = preg_replace('([^+\-0-9]+)', '', $value); |
204 | - return is_string($temp) ? (int)$temp : 0; |
|
204 | + return is_string($temp) ? (int) $temp : 0; |
|
205 | 205 | case 'float': |
206 | 206 | $temp = preg_replace('([^+\-0-9.]+)', '', str_replace(',', '.', $value)); |
207 | - return is_string($temp) ? (float)$temp : 0; |
|
207 | + return is_string($temp) ? (float) $temp : 0; |
|
208 | 208 | case 'text': |
209 | 209 | // check using strlen first, in order to avoid hitting mb_ functions which might be polyfilled |
210 | 210 | // because the polyfill is quite slow |
211 | 211 | if ($col->hasLength() && strlen($value) > $col->getLength() && mb_strlen($value) > $col->getLength()) { |
212 | 212 | if ($strict) { |
213 | - throw new DBException('Invalid value for text column ' . $col->getName()); |
|
213 | + throw new DBException('Invalid value for text column '.$col->getName()); |
|
214 | 214 | } |
215 | 215 | return mb_substr($value, 0, $col->getLength()); |
216 | 216 | } |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | if ($column->getBasicType() !== 'text') { |
236 | 236 | switch ($this->db->driverName()) { |
237 | 237 | case 'oracle': |
238 | - $name = 'CAST(' . $name . ' AS NVARCHAR(500))'; |
|
238 | + $name = 'CAST('.$name.' AS NVARCHAR(500))'; |
|
239 | 239 | break; |
240 | 240 | case 'postgre': |
241 | 241 | $name = $name.'::text'; |
@@ -243,58 +243,54 @@ discard block |
||
243 | 243 | } |
244 | 244 | } |
245 | 245 | $mode = array_keys($value)[0]; |
246 | - $value = str_replace(['%', '_'], ['\\%','\\_'], array_values($value)[0]) . '%'; |
|
246 | + $value = str_replace(['%', '_'], ['\\%', '\\_'], array_values($value)[0]).'%'; |
|
247 | 247 | if ($mode === 'contains' || $mode === 'icontains') { |
248 | - $value = '%' . $value; |
|
248 | + $value = '%'.$value; |
|
249 | 249 | } |
250 | 250 | if ($mode === 'icontains' || $mode === 'ilike') { |
251 | 251 | $value = mb_strtoupper($value); |
252 | - $name = 'UPPER(' . $name . ')'; |
|
252 | + $name = 'UPPER('.$name.')'; |
|
253 | 253 | } |
254 | 254 | return $negate ? |
255 | 255 | [ |
256 | - $name . ' NOT LIKE ?', |
|
257 | - [ (string)$value ] |
|
258 | - ] : |
|
259 | - [ |
|
260 | - $name . ' LIKE ?', |
|
261 | - [ (string)$value ] |
|
256 | + $name.' NOT LIKE ?', |
|
257 | + [(string) $value] |
|
258 | + ] : [ |
|
259 | + $name.' LIKE ?', |
|
260 | + [(string) $value] |
|
262 | 261 | ]; |
263 | 262 | } |
264 | 263 | if (is_array($value) && count($value) === 1 && isset($value['contains'])) { |
265 | 264 | $value = $value['contains']; |
266 | - $value = '%' . str_replace(['%', '_'], ['\\%','\\_'], $value) . '%'; |
|
265 | + $value = '%'.str_replace(['%', '_'], ['\\%', '\\_'], $value).'%'; |
|
267 | 266 | return $negate ? |
268 | 267 | [ |
269 | - $name . ' NOT LIKE ?', |
|
270 | - [ $this->normalizeValue($column, $value) ] |
|
271 | - ] : |
|
272 | - [ |
|
273 | - $name . ' LIKE ?', |
|
274 | - [ $this->normalizeValue($column, $value) ] |
|
268 | + $name.' NOT LIKE ?', |
|
269 | + [$this->normalizeValue($column, $value)] |
|
270 | + ] : [ |
|
271 | + $name.' LIKE ?', |
|
272 | + [$this->normalizeValue($column, $value)] |
|
275 | 273 | ]; |
276 | 274 | } |
277 | 275 | if (is_null($value)) { |
278 | 276 | return $negate ? |
279 | - [ $name . ' IS NOT NULL', [] ]: |
|
280 | - [ $name . ' IS NULL', [] ]; |
|
277 | + [$name.' IS NOT NULL', []] : [$name.' IS NULL', []]; |
|
281 | 278 | } |
282 | 279 | if (!is_array($value)) { |
283 | 280 | return $negate ? |
284 | 281 | [ |
285 | - $name . ' <> ?', |
|
286 | - [ $this->normalizeValue($column, $value) ] |
|
287 | - ] : |
|
288 | - [ |
|
289 | - $name . ' = ?', |
|
290 | - [ $this->normalizeValue($column, $value) ] |
|
282 | + $name.' <> ?', |
|
283 | + [$this->normalizeValue($column, $value)] |
|
284 | + ] : [ |
|
285 | + $name.' = ?', |
|
286 | + [$this->normalizeValue($column, $value)] |
|
291 | 287 | ]; |
292 | 288 | } |
293 | 289 | if (isset($value['beg']) && strlen($value['beg']) && (!isset($value['end']) || !strlen($value['end']))) { |
294 | - $value = [ 'gte' => $value['beg'] ]; |
|
290 | + $value = ['gte' => $value['beg']]; |
|
295 | 291 | } |
296 | 292 | if (isset($value['end']) && strlen($value['end']) && (!isset($value['beg']) || !strlen($value['beg']))) { |
297 | - $value = [ 'lte' => $value['end'] ]; |
|
293 | + $value = ['lte' => $value['end']]; |
|
298 | 294 | } |
299 | 295 | if (isset($value['beg']) && isset($value['end'])) { |
300 | 296 | return $negate ? |
@@ -304,8 +300,7 @@ discard block |
||
304 | 300 | $this->normalizeValue($column, $value['beg']), |
305 | 301 | $this->normalizeValue($column, $value['end']) |
306 | 302 | ] |
307 | - ] : |
|
308 | - [ |
|
303 | + ] : [ |
|
309 | 304 | $name.' BETWEEN ? AND ?', |
310 | 305 | [ |
311 | 306 | $this->normalizeValue($column, $value['beg']), |
@@ -317,42 +312,42 @@ discard block |
||
317 | 312 | $sql = []; |
318 | 313 | $par = []; |
319 | 314 | if (isset($value['gt'])) { |
320 | - $sql[] = $name. ' ' . ($negate ? '<=' : '>') . ' ?'; |
|
315 | + $sql[] = $name.' '.($negate ? '<=' : '>').' ?'; |
|
321 | 316 | $par[] = $this->normalizeValue($column, $value['gt']); |
322 | 317 | } |
323 | 318 | if (isset($value['gte'])) { |
324 | - $sql[] = $name. ' ' . ($negate ? '<' : '>=') . ' ?'; |
|
319 | + $sql[] = $name.' '.($negate ? '<' : '>=').' ?'; |
|
325 | 320 | $par[] = $this->normalizeValue($column, $value['gte']); |
326 | 321 | } |
327 | 322 | if (isset($value['lt'])) { |
328 | - $sql[] = $name. ' ' . ($negate ? '>=' : '<') . ' ?'; |
|
323 | + $sql[] = $name.' '.($negate ? '>=' : '<').' ?'; |
|
329 | 324 | $par[] = $this->normalizeValue($column, $value['lt']); |
330 | 325 | } |
331 | 326 | if (isset($value['lte'])) { |
332 | - $sql[] = $name. ' ' . ($negate ? '>' : '<=') . ' ?'; |
|
327 | + $sql[] = $name.' '.($negate ? '>' : '<=').' ?'; |
|
333 | 328 | $par[] = $this->normalizeValue($column, $value['lte']); |
334 | 329 | } |
335 | 330 | return [ |
336 | - '(' . implode(' AND ', $sql) . ')', |
|
331 | + '('.implode(' AND ', $sql).')', |
|
337 | 332 | $par |
338 | 333 | ]; |
339 | 334 | } |
340 | 335 | |
341 | - $value = array_values(array_map(function ($v) use ($column) { |
|
336 | + $value = array_values(array_map(function($v) use ($column) { |
|
342 | 337 | return $this->normalizeValue($column, $v); |
343 | 338 | }, $value)); |
344 | 339 | if ($this->db->driverName() === 'oracle') { |
345 | 340 | $sql = []; |
346 | 341 | $par = []; |
347 | 342 | for ($i = 0; $i < count($value); $i += 500) { |
348 | - $sql[] = $negate ? $name . ' NOT IN (??)' : $name . ' IN (??)'; |
|
343 | + $sql[] = $negate ? $name.' NOT IN (??)' : $name.' IN (??)'; |
|
349 | 344 | $par[] = array_slice($value, $i, 500); |
350 | 345 | } |
351 | - $sql = '(' . implode($negate ? ' AND ' : ' OR ', $sql) . ')'; |
|
352 | - return [ $sql, $par ]; |
|
346 | + $sql = '('.implode($negate ? ' AND ' : ' OR ', $sql).')'; |
|
347 | + return [$sql, $par]; |
|
353 | 348 | } |
354 | 349 | return [ |
355 | - $negate ? $name . ' NOT IN (??)' : $name . ' IN (??)', |
|
350 | + $negate ? $name.' NOT IN (??)' : $name.' IN (??)', |
|
356 | 351 | [$value] |
357 | 352 | ]; |
358 | 353 | } |
@@ -384,7 +379,7 @@ discard block |
||
384 | 379 | $par = array_merge($par, $temp[1]); |
385 | 380 | } |
386 | 381 | } |
387 | - return $this->where('(' . implode(' OR ', $sql) . ')', $par); |
|
382 | + return $this->where('('.implode(' OR ', $sql).')', $par); |
|
388 | 383 | } |
389 | 384 | /** |
390 | 385 | * Filter the results matching all of the criteria |
@@ -402,7 +397,7 @@ discard block |
||
402 | 397 | $par = array_merge($par, $temp[1]); |
403 | 398 | } |
404 | 399 | } |
405 | - return $this->where('(' . implode(' AND ', $sql) . ')', $par); |
|
400 | + return $this->where('('.implode(' AND ', $sql).')', $par); |
|
406 | 401 | } |
407 | 402 | /** |
408 | 403 | * Sort by a column |
@@ -417,7 +412,7 @@ discard block |
||
417 | 412 | } catch (DBException $e) { |
418 | 413 | throw new DBException('Invalid sort column'); |
419 | 414 | } |
420 | - return $this->order($column . ' ' . ($desc ? 'DESC' : 'ASC')); |
|
415 | + return $this->order($column.' '.($desc ? 'DESC' : 'ASC')); |
|
421 | 416 | } |
422 | 417 | /** |
423 | 418 | * Group by a column (or columns) |
@@ -427,7 +422,7 @@ discard block |
||
427 | 422 | public function group($column) : self |
428 | 423 | { |
429 | 424 | if (!is_array($column)) { |
430 | - $column = [ $column ]; |
|
425 | + $column = [$column]; |
|
431 | 426 | } |
432 | 427 | foreach ($column as $k => $v) { |
433 | 428 | $column[$k] = $this->getColumn($v)['name']; |
@@ -470,7 +465,7 @@ discard block |
||
470 | 465 | $this->order = []; |
471 | 466 | $this->having = []; |
472 | 467 | $this->aliases = []; |
473 | - $this->li_of = [0,0,0]; |
|
468 | + $this->li_of = [0, 0, 0]; |
|
474 | 469 | $this->qiterator = null; |
475 | 470 | return $this; |
476 | 471 | } |
@@ -483,7 +478,7 @@ discard block |
||
483 | 478 | public function groupBy(string $sql, array $params = []) : self |
484 | 479 | { |
485 | 480 | $this->qiterator = null; |
486 | - $this->group = [ $sql, $params ]; |
|
481 | + $this->group = [$sql, $params]; |
|
487 | 482 | return $this; |
488 | 483 | } |
489 | 484 | /** |
@@ -497,7 +492,7 @@ discard block |
||
497 | 492 | public function join($table, array $fields, string $name = null, bool $multiple = true) |
498 | 493 | { |
499 | 494 | $this->qiterator = null; |
500 | - $table = $table instanceof Table ? $table : $this->db->definition((string)$table); |
|
495 | + $table = $table instanceof Table ? $table : $this->db->definition((string) $table); |
|
501 | 496 | $name = $name ?? $table->getName(); |
502 | 497 | if (isset($this->joins[$name]) || $this->definition->hasRelation($name)) { |
503 | 498 | throw new DBException('Alias / table name already in use'); |
@@ -506,7 +501,7 @@ discard block |
||
506 | 501 | foreach ($fields as $k => $v) { |
507 | 502 | $k = explode('.', $k, 2); |
508 | 503 | $k = count($k) == 2 ? $k[1] : $k[0]; |
509 | - $this->joins[$name]->keymap[$this->getColumn($name . '.' . $k)['name']] = $this->getColumn($v)['name']; |
|
504 | + $this->joins[$name]->keymap[$this->getColumn($name.'.'.$k)['name']] = $this->getColumn($v)['name']; |
|
510 | 505 | } |
511 | 506 | return $this; |
512 | 507 | } |
@@ -519,7 +514,7 @@ discard block |
||
519 | 514 | public function where(string $sql, array $params = []) : self |
520 | 515 | { |
521 | 516 | $this->qiterator = null; |
522 | - $this->where[] = [ $sql, $params ]; |
|
517 | + $this->where[] = [$sql, $params]; |
|
523 | 518 | return $this; |
524 | 519 | } |
525 | 520 | /** |
@@ -531,7 +526,7 @@ discard block |
||
531 | 526 | public function having(string $sql, array $params = []) : self |
532 | 527 | { |
533 | 528 | $this->qiterator = null; |
534 | - $this->having[] = [ $sql, $params ]; |
|
529 | + $this->having[] = [$sql, $params]; |
|
535 | 530 | return $this; |
536 | 531 | } |
537 | 532 | /** |
@@ -551,12 +546,12 @@ discard block |
||
551 | 546 | throw new \Exception(); |
552 | 547 | } |
553 | 548 | $name = $this->getColumn(trim($name))['name']; |
554 | - $sql = $name . ' ' . (strpos(strtolower($sql), ' desc') ? 'DESC' : 'ASC'); |
|
549 | + $sql = $name.' '.(strpos(strtolower($sql), ' desc') ? 'DESC' : 'ASC'); |
|
555 | 550 | } catch (\Exception $e) { |
556 | 551 | $name = null; |
557 | 552 | } |
558 | 553 | } |
559 | - $this->order = [ $sql, $params, $name ]; |
|
554 | + $this->order = [$sql, $params, $name]; |
|
560 | 555 | return $this; |
561 | 556 | } |
562 | 557 | /** |
@@ -568,7 +563,7 @@ discard block |
||
568 | 563 | public function limit(int $limit, int $offset = 0, bool $limitOnMainTable = false) : self |
569 | 564 | { |
570 | 565 | $this->qiterator = null; |
571 | - $this->li_of = [ $limit, $offset, $limitOnMainTable ? 1 : 0 ]; |
|
566 | + $this->li_of = [$limit, $offset, $limitOnMainTable ? 1 : 0]; |
|
572 | 567 | return $this; |
573 | 568 | } |
574 | 569 | /** |
@@ -579,9 +574,9 @@ discard block |
||
579 | 574 | { |
580 | 575 | $aliases = []; |
581 | 576 | $aliases_ext = []; |
582 | - $getAlias = function ($name) use (&$aliases, &$aliases_ext) { |
|
577 | + $getAlias = function($name) use (&$aliases, &$aliases_ext) { |
|
583 | 578 | // to bypass use: return $name; |
584 | - $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases); |
|
579 | + $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases); |
|
585 | 580 | if (isset($aliases_ext[$name])) { |
586 | 581 | unset($aliases_ext[$name]); |
587 | 582 | } |
@@ -604,7 +599,7 @@ discard block |
||
604 | 599 | $h = $this->having; |
605 | 600 | $o = $this->order; |
606 | 601 | $g = $this->group; |
607 | - $j = array_map(function ($v) { |
|
602 | + $j = array_map(function($v) { |
|
608 | 603 | return clone $v; |
609 | 604 | }, $this->joins); |
610 | 605 | |
@@ -614,28 +609,28 @@ discard block |
||
614 | 609 | continue; |
615 | 610 | } |
616 | 611 | foreach ($w as $kk => $v) { |
617 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) { |
|
612 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) { |
|
618 | 613 | $used_relations[] = $k; |
619 | - $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]); |
|
614 | + $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]); |
|
620 | 615 | } |
621 | 616 | } |
622 | 617 | foreach ($h as $kk => $v) { |
623 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) { |
|
618 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) { |
|
624 | 619 | $used_relations[] = $k; |
625 | - $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]); |
|
620 | + $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]); |
|
626 | 621 | } |
627 | 622 | } |
628 | - if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) { |
|
623 | + if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) { |
|
629 | 624 | $used_relations[] = $k; |
630 | - $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]); |
|
625 | + $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]); |
|
631 | 626 | } |
632 | 627 | foreach ($j as $kk => $v) { |
633 | 628 | foreach ($v->keymap as $kkk => $vv) { |
634 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) { |
|
629 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) { |
|
635 | 630 | $used_relations[] = $k; |
636 | 631 | $j[$kk]->keymap[$kkk] = preg_replace( |
637 | - '(\b'.preg_quote($k . '.'). ')i', |
|
638 | - $getAlias($k) . '.', |
|
632 | + '(\b'.preg_quote($k.'.').')i', |
|
633 | + $getAlias($k).'.', |
|
639 | 634 | $vv |
640 | 635 | ); |
641 | 636 | } |
@@ -644,65 +639,65 @@ discard block |
||
644 | 639 | } |
645 | 640 | foreach ($this->definition->getRelations() as $k => $v) { |
646 | 641 | foreach ($w as $kk => $vv) { |
647 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) { |
|
648 | - $relations[$k] = [ $v, $table ]; |
|
642 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) { |
|
643 | + $relations[$k] = [$v, $table]; |
|
649 | 644 | $used_relations[] = $k; |
650 | - $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]); |
|
645 | + $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]); |
|
651 | 646 | } |
652 | 647 | } |
653 | - if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) { |
|
654 | - $relations[$k] = [ $v, $table ]; |
|
648 | + if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) { |
|
649 | + $relations[$k] = [$v, $table]; |
|
655 | 650 | } |
656 | 651 | foreach ($h as $kk => $vv) { |
657 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) { |
|
658 | - $relations[$k] = [ $v, $table ]; |
|
652 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) { |
|
653 | + $relations[$k] = [$v, $table]; |
|
659 | 654 | $used_relations[] = $k; |
660 | - $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]); |
|
655 | + $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]); |
|
661 | 656 | } |
662 | 657 | } |
663 | - if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) { |
|
664 | - $relations[$k] = [ $v, $table ]; |
|
658 | + if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) { |
|
659 | + $relations[$k] = [$v, $table]; |
|
665 | 660 | $used_relations[] = $k; |
666 | - $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]); |
|
661 | + $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]); |
|
667 | 662 | } |
668 | 663 | foreach ($j as $kk => $vv) { |
669 | 664 | foreach ($vv->keymap as $kkk => $vvv) { |
670 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vvv)) { |
|
671 | - $relations[$k] = [ $v, $table ]; |
|
665 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $vvv)) { |
|
666 | + $relations[$k] = [$v, $table]; |
|
672 | 667 | $used_relations[] = $k; |
673 | 668 | $j[$kk]->keymap[$kkk] = |
674 | - preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vvv); |
|
669 | + preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vvv); |
|
675 | 670 | } |
676 | 671 | } |
677 | 672 | } |
678 | 673 | } |
679 | 674 | foreach ($aliases_ext as $k => $alias) { |
680 | 675 | foreach ($w as $kk => $v) { |
681 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) { |
|
682 | - $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $v[0]); |
|
676 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) { |
|
677 | + $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $v[0]); |
|
683 | 678 | $used_relations[] = $k; |
684 | 679 | } |
685 | 680 | } |
686 | 681 | foreach ($h as $kk => $v) { |
687 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) { |
|
688 | - $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $v[0]); |
|
682 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) { |
|
683 | + $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $v[0]); |
|
689 | 684 | $used_relations[] = $k; |
690 | 685 | } |
691 | 686 | } |
692 | - if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) { |
|
687 | + if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) { |
|
693 | 688 | $used_relations[] = $k; |
694 | 689 | } |
695 | - if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) { |
|
696 | - $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $g[0]); |
|
690 | + if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) { |
|
691 | + $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $g[0]); |
|
697 | 692 | $used_relations[] = $k; |
698 | 693 | } |
699 | 694 | foreach ($j as $kk => $v) { |
700 | 695 | foreach ($v->keymap as $kkk => $vv) { |
701 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) { |
|
696 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) { |
|
702 | 697 | $used_relations[] = $k; |
703 | 698 | $j[$kk]->keymap[$kkk] = preg_replace( |
704 | - '(\b'.preg_quote($k . '.'). ')i', |
|
705 | - $alias . '.', |
|
699 | + '(\b'.preg_quote($k.'.').')i', |
|
700 | + $alias.'.', |
|
706 | 701 | $vv |
707 | 702 | ); |
708 | 703 | } |
@@ -720,13 +715,13 @@ discard block |
||
720 | 715 | foreach ($v->keymap as $kk => $vv) { |
721 | 716 | $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' '; |
722 | 717 | } |
723 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
718 | + $sql .= implode(' AND ', $tmp).' '; |
|
724 | 719 | $sql .= 'LEFT JOIN '.$v->table->getFullName().' '.$getAlias($k).' ON '; |
725 | 720 | $tmp = []; |
726 | 721 | foreach ($v->pivot_keymap as $kk => $vv) { |
727 | 722 | $tmp[] = $getAlias($k).'.'.$vv.' = '.$alias.'.'.$kk.' '; |
728 | 723 | } |
729 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
724 | + $sql .= implode(' AND ', $tmp).' '; |
|
730 | 725 | } else { |
731 | 726 | $alias = $getAlias($k); |
732 | 727 | $sql .= 'LEFT JOIN '.$v->table->getFullName().' '.$alias.' ON '; |
@@ -735,19 +730,19 @@ discard block |
||
735 | 730 | $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' '; |
736 | 731 | } |
737 | 732 | if ($v->sql) { |
738 | - $tmp[] = $v->sql . ' '; |
|
733 | + $tmp[] = $v->sql.' '; |
|
739 | 734 | $par = array_merge($par, $v->par ?? []); |
740 | 735 | } |
741 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
736 | + $sql .= implode(' AND ', $tmp).' '; |
|
742 | 737 | } |
743 | 738 | } |
744 | 739 | foreach ($j as $k => $v) { |
745 | - $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getFullName().' '.$k.' ON '; |
|
740 | + $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getFullName().' '.$k.' ON '; |
|
746 | 741 | $tmp = []; |
747 | 742 | foreach ($v->keymap as $kk => $vv) { |
748 | 743 | $tmp[] = $kk.' = '.$vv; |
749 | 744 | } |
750 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
745 | + $sql .= implode(' AND ', $tmp).' '; |
|
751 | 746 | } |
752 | 747 | } else { |
753 | 748 | $sql = str_replace('COUNT(DISTINCT ', 'COUNT(', $sql); |
@@ -756,20 +751,20 @@ discard block |
||
756 | 751 | $sql .= 'WHERE '; |
757 | 752 | $tmp = []; |
758 | 753 | foreach ($w as $v) { |
759 | - $tmp[] = '(' . $v[0] . ')'; |
|
754 | + $tmp[] = '('.$v[0].')'; |
|
760 | 755 | $par = array_merge($par, $v[1]); |
761 | 756 | } |
762 | 757 | $sql .= implode(' AND ', $tmp).' '; |
763 | 758 | } |
764 | 759 | if (count($g)) { |
765 | - $sql .= 'GROUP BY ' . $g[0] . ' '; |
|
760 | + $sql .= 'GROUP BY '.$g[0].' '; |
|
766 | 761 | $par = array_merge($par, $g[1]); |
767 | 762 | } |
768 | 763 | if (count($h)) { |
769 | 764 | $sql .= 'HAVING '; |
770 | 765 | $tmp = []; |
771 | 766 | foreach ($h as $v) { |
772 | - $tmp[] = '(' . $v[0] . ')'; |
|
767 | + $tmp[] = '('.$v[0].')'; |
|
773 | 768 | $par = array_merge($par, $v[1]); |
774 | 769 | } |
775 | 770 | $sql .= implode(' AND ', $tmp).' '; |
@@ -804,7 +799,7 @@ discard block |
||
804 | 799 | $this->with(implode('.', $temp)); |
805 | 800 | $table = array_reduce( |
806 | 801 | $temp, |
807 | - function ($carry, $item) use (&$table) { |
|
802 | + function($carry, $item) use (&$table) { |
|
808 | 803 | return $table->getRelation($item)->table; |
809 | 804 | } |
810 | 805 | ); |
@@ -813,7 +808,7 @@ discard block |
||
813 | 808 | } |
814 | 809 | unset($fields[$k]); |
815 | 810 | foreach ($cols as $col) { |
816 | - $fields[] = $table . '.' . $col; |
|
811 | + $fields[] = $table.'.'.$col; |
|
817 | 812 | } |
818 | 813 | } |
819 | 814 | } |
@@ -848,9 +843,9 @@ discard block |
||
848 | 843 | } |
849 | 844 | $aliases = []; |
850 | 845 | $aliases_ext = []; |
851 | - $getAlias = function ($name) use (&$aliases, &$aliases_ext) { |
|
846 | + $getAlias = function($name) use (&$aliases, &$aliases_ext) { |
|
852 | 847 | // to bypass use: return $name; |
853 | - $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases); |
|
848 | + $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases); |
|
854 | 849 | if (isset($aliases_ext[$name])) { |
855 | 850 | unset($aliases_ext[$name]); |
856 | 851 | } |
@@ -875,7 +870,7 @@ discard block |
||
875 | 870 | $h = $this->having; |
876 | 871 | $o = $this->order; |
877 | 872 | $g = $this->group; |
878 | - $j = array_map(function ($v) { |
|
873 | + $j = array_map(function($v) { |
|
879 | 874 | return clone $v; |
880 | 875 | }, $this->joins); |
881 | 876 | |
@@ -889,32 +884,32 @@ discard block |
||
889 | 884 | continue; |
890 | 885 | } |
891 | 886 | foreach ($f as $kk => $field) { |
892 | - if (strpos($field, $k . '.') === 0) { |
|
893 | - $f[$kk] = str_replace($k . '.', $getAlias($k) . '.', $field); |
|
887 | + if (strpos($field, $k.'.') === 0) { |
|
888 | + $f[$kk] = str_replace($k.'.', $getAlias($k).'.', $field); |
|
894 | 889 | } |
895 | 890 | } |
896 | 891 | foreach ($w as $kk => $v) { |
897 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) { |
|
898 | - $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]); |
|
892 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) { |
|
893 | + $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]); |
|
899 | 894 | } |
900 | 895 | } |
901 | 896 | foreach ($h as $kk => $v) { |
902 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) { |
|
903 | - $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]); |
|
897 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) { |
|
898 | + $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]); |
|
904 | 899 | } |
905 | 900 | } |
906 | - if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) { |
|
907 | - $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]); |
|
901 | + if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) { |
|
902 | + $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]); |
|
908 | 903 | } |
909 | - if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) { |
|
910 | - $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]); |
|
904 | + if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) { |
|
905 | + $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]); |
|
911 | 906 | } |
912 | 907 | foreach ($j as $kk => $v) { |
913 | 908 | foreach ($v->keymap as $kkk => $vv) { |
914 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) { |
|
909 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) { |
|
915 | 910 | $j[$kk]->keymap[$kkk] = preg_replace( |
916 | - '(\b'.preg_quote($k . '.'). ')i', |
|
917 | - $getAlias($k) . '.', |
|
911 | + '(\b'.preg_quote($k.'.').')i', |
|
912 | + $getAlias($k).'.', |
|
918 | 913 | $vv |
919 | 914 | ); |
920 | 915 | } |
@@ -923,38 +918,38 @@ discard block |
||
923 | 918 | } |
924 | 919 | foreach ($this->definition->getRelations() as $k => $relation) { |
925 | 920 | foreach ($f as $kk => $field) { |
926 | - if (strpos($field, $k . '.') === 0) { |
|
927 | - $relations[$k] = [ $relation, $table ]; |
|
928 | - $f[$kk] = str_replace($k . '.', $getAlias($k) . '.', $field); |
|
921 | + if (strpos($field, $k.'.') === 0) { |
|
922 | + $relations[$k] = [$relation, $table]; |
|
923 | + $f[$kk] = str_replace($k.'.', $getAlias($k).'.', $field); |
|
929 | 924 | } |
930 | 925 | } |
931 | 926 | foreach ($w as $kk => $v) { |
932 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) { |
|
933 | - $relations[$k] = [ $relation, $table ]; |
|
934 | - $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]); |
|
927 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) { |
|
928 | + $relations[$k] = [$relation, $table]; |
|
929 | + $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]); |
|
935 | 930 | } |
936 | 931 | } |
937 | 932 | foreach ($h as $kk => $v) { |
938 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) { |
|
939 | - $relations[$k] = [ $relation, $table ]; |
|
940 | - $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]); |
|
933 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) { |
|
934 | + $relations[$k] = [$relation, $table]; |
|
935 | + $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]); |
|
941 | 936 | } |
942 | 937 | } |
943 | - if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) { |
|
944 | - $relations[$k] = [ $relation, $table ]; |
|
945 | - $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]); |
|
938 | + if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) { |
|
939 | + $relations[$k] = [$relation, $table]; |
|
940 | + $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]); |
|
946 | 941 | } |
947 | - if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) { |
|
948 | - $relations[$k] = [ $relation, $table ]; |
|
949 | - $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $g[0]); |
|
942 | + if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) { |
|
943 | + $relations[$k] = [$relation, $table]; |
|
944 | + $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $g[0]); |
|
950 | 945 | } |
951 | 946 | foreach ($j as $kk => $v) { |
952 | 947 | foreach ($v->keymap as $kkk => $vv) { |
953 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) { |
|
954 | - $relations[$k] = [ $relation, $table ]; |
|
948 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) { |
|
949 | + $relations[$k] = [$relation, $table]; |
|
955 | 950 | $j[$kk]->keymap[$kkk] = preg_replace( |
956 | - '(\b'.preg_quote($k . '.'). ')i', |
|
957 | - $getAlias($k) . '.', |
|
951 | + '(\b'.preg_quote($k.'.').')i', |
|
952 | + $getAlias($k).'.', |
|
958 | 953 | $vv |
959 | 954 | ); |
960 | 955 | } |
@@ -963,32 +958,32 @@ discard block |
||
963 | 958 | } |
964 | 959 | foreach ($aliases_ext as $k => $alias) { |
965 | 960 | foreach ($f as $kk => $field) { |
966 | - if (strpos($field, $k . '.') === 0) { |
|
967 | - $f[$kk] = str_replace($k . '.', $alias . '.', $field); |
|
961 | + if (strpos($field, $k.'.') === 0) { |
|
962 | + $f[$kk] = str_replace($k.'.', $alias.'.', $field); |
|
968 | 963 | } |
969 | 964 | } |
970 | 965 | foreach ($w as $kk => $v) { |
971 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) { |
|
972 | - $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $v[0]); |
|
966 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) { |
|
967 | + $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $v[0]); |
|
973 | 968 | } |
974 | 969 | } |
975 | 970 | foreach ($h as $kk => $v) { |
976 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) { |
|
977 | - $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $v[0]); |
|
971 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) { |
|
972 | + $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $v[0]); |
|
978 | 973 | } |
979 | 974 | } |
980 | - if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) { |
|
981 | - $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $o[0]); |
|
975 | + if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) { |
|
976 | + $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $o[0]); |
|
982 | 977 | } |
983 | - if (isset($g[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $g[0])) { |
|
984 | - $g[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $g[0]); |
|
978 | + if (isset($g[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $g[0])) { |
|
979 | + $g[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $g[0]); |
|
985 | 980 | } |
986 | 981 | foreach ($j as $kk => $v) { |
987 | 982 | foreach ($v->keymap as $kkk => $vv) { |
988 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) { |
|
983 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) { |
|
989 | 984 | $j[$kk]->keymap[$kkk] = preg_replace( |
990 | - '(\b'.preg_quote($k . '.'). ')i', |
|
991 | - $alias . '.', |
|
985 | + '(\b'.preg_quote($k.'.').')i', |
|
986 | + $alias.'.', |
|
992 | 987 | $vv |
993 | 988 | ); |
994 | 989 | } |
@@ -997,12 +992,12 @@ discard block |
||
997 | 992 | } |
998 | 993 | $select = []; |
999 | 994 | foreach ($f as $k => $field) { |
1000 | - $select[] = $field . (!is_numeric($k) ? ' ' . $k : ''); |
|
995 | + $select[] = $field.(!is_numeric($k) ? ' '.$k : ''); |
|
1001 | 996 | } |
1002 | 997 | foreach ($this->withr as $name => $relation) { |
1003 | 998 | if ($relation[2]) { |
1004 | 999 | foreach ($relation[0]->table->getColumns() as $column) { |
1005 | - $select[] = $getAlias($name) . '.' . $column . ' ' . $getAlias($name . static::SEP . $column); |
|
1000 | + $select[] = $getAlias($name).'.'.$column.' '.$getAlias($name.static::SEP.$column); |
|
1006 | 1001 | } |
1007 | 1002 | } |
1008 | 1003 | } |
@@ -1022,13 +1017,13 @@ discard block |
||
1022 | 1017 | foreach ($v->keymap as $kk => $vv) { |
1023 | 1018 | $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' '; |
1024 | 1019 | } |
1025 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
1020 | + $sql .= implode(' AND ', $tmp).' '; |
|
1026 | 1021 | $sql .= 'LEFT JOIN '.$v->table->getFullName().' '.$getAlias($relation).' ON '; |
1027 | 1022 | $tmp = []; |
1028 | 1023 | foreach ($v->pivot_keymap as $kk => $vv) { |
1029 | 1024 | $tmp[] = $getAlias($relation).'.'.$vv.' = '.$alias.'.'.$kk.' '; |
1030 | 1025 | } |
1031 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
1026 | + $sql .= implode(' AND ', $tmp).' '; |
|
1032 | 1027 | } else { |
1033 | 1028 | $alias = $getAlias($relation); |
1034 | 1029 | |
@@ -1038,22 +1033,22 @@ discard block |
||
1038 | 1033 | $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' '; |
1039 | 1034 | } |
1040 | 1035 | if ($v->sql) { |
1041 | - $tmp[] = $v->sql . ' '; |
|
1036 | + $tmp[] = $v->sql.' '; |
|
1042 | 1037 | $par = array_merge($par, $v->par ?? []); |
1043 | 1038 | } |
1044 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
1039 | + $sql .= implode(' AND ', $tmp).' '; |
|
1045 | 1040 | } |
1046 | 1041 | } |
1047 | 1042 | foreach ($j as $k => $v) { |
1048 | 1043 | if ($v->many) { |
1049 | 1044 | $many = true; |
1050 | 1045 | } |
1051 | - $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON '; |
|
1046 | + $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON '; |
|
1052 | 1047 | $tmp = []; |
1053 | 1048 | foreach ($v->keymap as $kk => $vv) { |
1054 | 1049 | $tmp[] = $kk.' = '.$vv; |
1055 | 1050 | } |
1056 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
1051 | + $sql .= implode(' AND ', $tmp).' '; |
|
1057 | 1052 | } |
1058 | 1053 | if ($many && count($porder) && $this->li_of[2] === 1) { |
1059 | 1054 | $ids = $this->ids(); |
@@ -1061,9 +1056,9 @@ discard block |
||
1061 | 1056 | if (count($porder) > 1) { |
1062 | 1057 | $pkw = []; |
1063 | 1058 | foreach ($porder as $name) { |
1064 | - $pkw[] = $name . ' = ?'; |
|
1059 | + $pkw[] = $name.' = ?'; |
|
1065 | 1060 | } |
1066 | - $pkw = '(' . implode(' AND ', $pkw) . ')'; |
|
1061 | + $pkw = '('.implode(' AND ', $pkw).')'; |
|
1067 | 1062 | $pkp = []; |
1068 | 1063 | foreach ($ids as $id) { |
1069 | 1064 | foreach ($id as $p) { |
@@ -1075,60 +1070,60 @@ discard block |
||
1075 | 1070 | $pkp |
1076 | 1071 | ]; |
1077 | 1072 | } else { |
1078 | - $w[] = [ $porder[0] . ' IN ('.implode(',', array_fill(0, count($ids), '?')).')', $ids ]; |
|
1073 | + $w[] = [$porder[0].' IN ('.implode(',', array_fill(0, count($ids), '?')).')', $ids]; |
|
1079 | 1074 | } |
1080 | 1075 | } else { |
1081 | - $w[] = [ '1=0', [] ]; |
|
1076 | + $w[] = ['1=0', []]; |
|
1082 | 1077 | } |
1083 | 1078 | } |
1084 | 1079 | if (count($w)) { |
1085 | 1080 | $sql .= 'WHERE '; |
1086 | 1081 | $tmp = []; |
1087 | 1082 | foreach ($w as $v) { |
1088 | - $tmp[] = '(' . $v[0] . ')'; |
|
1083 | + $tmp[] = '('.$v[0].')'; |
|
1089 | 1084 | $par = array_merge($par, $v[1]); |
1090 | 1085 | } |
1091 | 1086 | $sql .= implode(' AND ', $tmp).' '; |
1092 | 1087 | } |
1093 | 1088 | if (count($g)) { |
1094 | - $sql .= 'GROUP BY ' . $g[0] . ' '; |
|
1089 | + $sql .= 'GROUP BY '.$g[0].' '; |
|
1095 | 1090 | $par = array_merge($par, $g[1]); |
1096 | 1091 | } |
1097 | 1092 | if (count($h)) { |
1098 | 1093 | $sql .= 'HAVING '; |
1099 | 1094 | $tmp = []; |
1100 | 1095 | foreach ($h as $v) { |
1101 | - $tmp[] = '(' . $v[0] . ')'; |
|
1096 | + $tmp[] = '('.$v[0].')'; |
|
1102 | 1097 | $par = array_merge($par, $v[1]); |
1103 | 1098 | } |
1104 | 1099 | $sql .= implode(' AND ', $tmp).' '; |
1105 | 1100 | } |
1106 | 1101 | $ordered = false; |
1107 | 1102 | if (count($o)) { |
1108 | - $sql .= 'ORDER BY ' . $o[0] . ' '; |
|
1103 | + $sql .= 'ORDER BY '.$o[0].' '; |
|
1109 | 1104 | $par = array_merge($par, $o[1]); |
1110 | 1105 | $ordered = true; |
1111 | 1106 | } |
1112 | 1107 | if (!count($g) && count($porder)) { |
1113 | 1108 | $pdir = (count($o) && strpos($o[0], 'DESC') !== false) ? 'DESC' : 'ASC'; |
1114 | - $porder = array_map(function ($v) use ($pdir) { |
|
1115 | - return $v . ' ' . $pdir; |
|
1109 | + $porder = array_map(function($v) use ($pdir) { |
|
1110 | + return $v.' '.$pdir; |
|
1116 | 1111 | }, $porder); |
1117 | - $sql .= ($ordered ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' '; |
|
1112 | + $sql .= ($ordered ? ', ' : 'ORDER BY ').implode(', ', $porder).' '; |
|
1118 | 1113 | $ordered = true; |
1119 | 1114 | } |
1120 | 1115 | foreach ($this->withr as $k => $v) { |
1121 | 1116 | if (isset($v[3])) { |
1122 | - $sql .= ($ordered ? ', ' : 'ORDER BY ') . $getAlias($k) . '.' . $v[3] . ' ' . ($v[4] ? 'DESC' : 'ASC'); |
|
1117 | + $sql .= ($ordered ? ', ' : 'ORDER BY ').$getAlias($k).'.'.$v[3].' '.($v[4] ? 'DESC' : 'ASC'); |
|
1123 | 1118 | $ordered = true; |
1124 | 1119 | } |
1125 | 1120 | } |
1126 | 1121 | if ((!$many || $this->li_of[2] === 0 || !count($porder)) && $this->li_of[0]) { |
1127 | 1122 | if ($this->db->driverName() === 'oracle') { |
1128 | - if ((int)$this->db->driverOption('version', 0) >= 12) { |
|
1129 | - $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY'; |
|
1123 | + if ((int) $this->db->driverOption('version', 0) >= 12) { |
|
1124 | + $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY'; |
|
1130 | 1125 | } else { |
1131 | - $f = array_map(function ($v) { |
|
1126 | + $f = array_map(function($v) { |
|
1132 | 1127 | $v = explode(' ', trim($v), 2); |
1133 | 1128 | if (count($v) === 2) { |
1134 | 1129 | return $v[1]; |
@@ -1136,16 +1131,16 @@ discard block |
||
1136 | 1131 | $v = explode('.', $v[0], 2); |
1137 | 1132 | return count($v) === 2 ? $v[1] : $v[0]; |
1138 | 1133 | }, $select); |
1139 | - $sql = "SELECT " . implode(', ', $f) . " |
|
1134 | + $sql = "SELECT ".implode(', ', $f)." |
|
1140 | 1135 | FROM ( |
1141 | 1136 | SELECT tbl__.*, rownum rnum__ FROM ( |
1142 | - " . $sql . " |
|
1137 | + " . $sql." |
|
1143 | 1138 | ) tbl__ |
1144 | - WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . " |
|
1139 | + WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])." |
|
1145 | 1140 | ) WHERE rnum__ > " . $this->li_of[1]; |
1146 | 1141 | } |
1147 | 1142 | } else { |
1148 | - $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1]; |
|
1143 | + $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1]; |
|
1149 | 1144 | } |
1150 | 1145 | } |
1151 | 1146 | return $this->qiterator = new TableQueryIterator( |
@@ -1195,12 +1190,12 @@ discard block |
||
1195 | 1190 | $ret[$k] = str_repeat(' ', 255); |
1196 | 1191 | $par[] = &$ret[$k]; |
1197 | 1192 | } |
1198 | - $sql .= ' RETURNING ' . implode(',', $primary) . |
|
1199 | - ' INTO ' . implode(',', array_fill(0, count($primary), '?')); |
|
1193 | + $sql .= ' RETURNING '.implode(',', $primary). |
|
1194 | + ' INTO '.implode(',', array_fill(0, count($primary), '?')); |
|
1200 | 1195 | $this->db->query($sql, $par); |
1201 | 1196 | return $ret; |
1202 | 1197 | } elseif ($this->db->driverName() === 'postgre') { |
1203 | - $sql .= ' RETURNING ' . implode(',', $primary); |
|
1198 | + $sql .= ' RETURNING '.implode(',', $primary); |
|
1204 | 1199 | return $this->db->one($sql, $par, false); |
1205 | 1200 | } else { |
1206 | 1201 | $ret = []; |
@@ -1231,9 +1226,9 @@ discard block |
||
1231 | 1226 | } |
1232 | 1227 | $sql = 'UPDATE '.$table.' SET '; |
1233 | 1228 | $par = []; |
1234 | - $sql .= implode(', ', array_map(function ($v) { |
|
1235 | - return $v . ' = ?'; |
|
1236 | - }, array_keys($update))) . ' '; |
|
1229 | + $sql .= implode(', ', array_map(function($v) { |
|
1230 | + return $v.' = ?'; |
|
1231 | + }, array_keys($update))).' '; |
|
1237 | 1232 | $par = array_merge($par, array_values($update)); |
1238 | 1233 | if (count($this->where)) { |
1239 | 1234 | $sql .= 'WHERE '; |
@@ -1242,7 +1237,7 @@ discard block |
||
1242 | 1237 | $tmp[] = $v[0]; |
1243 | 1238 | $par = array_merge($par, $v[1]); |
1244 | 1239 | } |
1245 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
1240 | + $sql .= implode(' AND ', $tmp).' '; |
|
1246 | 1241 | } |
1247 | 1242 | if (count($this->order)) { |
1248 | 1243 | $sql .= $this->order[0]; |
@@ -1266,7 +1261,7 @@ discard block |
||
1266 | 1261 | $tmp[] = $v[0]; |
1267 | 1262 | $par = array_merge($par, $v[1]); |
1268 | 1263 | } |
1269 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
1264 | + $sql .= implode(' AND ', $tmp).' '; |
|
1270 | 1265 | } |
1271 | 1266 | if (count($this->order)) { |
1272 | 1267 | $sql .= $this->order[0]; |
@@ -1285,21 +1280,21 @@ discard block |
||
1285 | 1280 | $table = $this->definition; |
1286 | 1281 | if ($table->hasRelation($relation)) { |
1287 | 1282 | $temp = $table->getRelation($relation); |
1288 | - $this->withr[$relation] = [ $temp, $table->getName(), $select || ($this->withr[$relation][2] ?? false), $order, $desc ]; |
|
1283 | + $this->withr[$relation] = [$temp, $table->getName(), $select || ($this->withr[$relation][2] ?? false), $order, $desc]; |
|
1289 | 1284 | } else { |
1290 | 1285 | $parts = explode('.', $relation); |
1291 | 1286 | try { |
1292 | 1287 | $name = array_reduce( |
1293 | 1288 | $parts, |
1294 | - function ($carry, $item) use (&$table, $select) { |
|
1289 | + function($carry, $item) use (&$table, $select) { |
|
1295 | 1290 | if (!$table->hasRelation($item)) { |
1296 | - throw new DBException('Invalid relation name: '.$table->getName().' -> ' . $item); |
|
1291 | + throw new DBException('Invalid relation name: '.$table->getName().' -> '.$item); |
|
1297 | 1292 | } |
1298 | 1293 | $relation = $table->getRelation($item); |
1299 | 1294 | if (!$relation) { |
1300 | - throw new DBException('Invalid relation name: '.$table->getName().' -> ' . $item); |
|
1295 | + throw new DBException('Invalid relation name: '.$table->getName().' -> '.$item); |
|
1301 | 1296 | } |
1302 | - $name = $carry ? $carry . static::SEP . $item : $item; |
|
1297 | + $name = $carry ? $carry.static::SEP.$item : $item; |
|
1303 | 1298 | $this->withr[$name] = [ |
1304 | 1299 | $relation, |
1305 | 1300 | $carry ?? $table->getName(), |
@@ -1364,9 +1359,9 @@ discard block |
||
1364 | 1359 | |
1365 | 1360 | $aliases = []; |
1366 | 1361 | $aliases_ext = []; |
1367 | - $getAlias = function ($name) use (&$aliases, &$aliases_ext) { |
|
1362 | + $getAlias = function($name) use (&$aliases, &$aliases_ext) { |
|
1368 | 1363 | // to bypass use: return $name; |
1369 | - $aliases[$name] = $aliases[$name] ?? 'alias' . static::SEP . count($aliases); |
|
1364 | + $aliases[$name] = $aliases[$name] ?? 'alias'.static::SEP.count($aliases); |
|
1370 | 1365 | if (isset($aliases_ext[$name])) { |
1371 | 1366 | unset($aliases_ext[$name]); |
1372 | 1367 | } |
@@ -1386,7 +1381,7 @@ discard block |
||
1386 | 1381 | $w = $this->where; |
1387 | 1382 | $h = $this->having; |
1388 | 1383 | $o = $this->order; |
1389 | - $j = array_map(function ($v) { |
|
1384 | + $j = array_map(function($v) { |
|
1390 | 1385 | return clone $v; |
1391 | 1386 | }, $this->joins); |
1392 | 1387 | |
@@ -1395,24 +1390,24 @@ discard block |
||
1395 | 1390 | continue; |
1396 | 1391 | } |
1397 | 1392 | foreach ($w as $kk => $v) { |
1398 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) { |
|
1399 | - $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]); |
|
1393 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) { |
|
1394 | + $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]); |
|
1400 | 1395 | } |
1401 | 1396 | } |
1402 | 1397 | foreach ($h as $kk => $v) { |
1403 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) { |
|
1404 | - $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $v[0]); |
|
1398 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) { |
|
1399 | + $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $v[0]); |
|
1405 | 1400 | } |
1406 | 1401 | } |
1407 | - if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) { |
|
1408 | - $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]); |
|
1402 | + if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) { |
|
1403 | + $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]); |
|
1409 | 1404 | } |
1410 | 1405 | foreach ($j as $kk => $v) { |
1411 | 1406 | foreach ($v->keymap as $kkk => $vv) { |
1412 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) { |
|
1407 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) { |
|
1413 | 1408 | $j[$kk]->keymap[$kkk] = preg_replace( |
1414 | - '(\b'.preg_quote($k . '.'). ')i', |
|
1415 | - $getAlias($k) . '.', |
|
1409 | + '(\b'.preg_quote($k.'.').')i', |
|
1410 | + $getAlias($k).'.', |
|
1416 | 1411 | $vv |
1417 | 1412 | ); |
1418 | 1413 | } |
@@ -1421,52 +1416,52 @@ discard block |
||
1421 | 1416 | } |
1422 | 1417 | foreach ($this->definition->getRelations() as $k => $v) { |
1423 | 1418 | foreach ($w as $kk => $vv) { |
1424 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) { |
|
1425 | - $relations[$k] = [ $v, $table ]; |
|
1426 | - $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]); |
|
1419 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) { |
|
1420 | + $relations[$k] = [$v, $table]; |
|
1421 | + $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]); |
|
1427 | 1422 | } |
1428 | 1423 | } |
1429 | - if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) { |
|
1430 | - $relations[$k] = [ $v, $table ]; |
|
1431 | - $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[0]); |
|
1432 | - $o[2] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $o[2]); |
|
1424 | + if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) { |
|
1425 | + $relations[$k] = [$v, $table]; |
|
1426 | + $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[0]); |
|
1427 | + $o[2] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $o[2]); |
|
1433 | 1428 | } |
1434 | 1429 | foreach ($h as $kk => $vv) { |
1435 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv[0])) { |
|
1436 | - $relations[$k] = [ $v, $table ]; |
|
1437 | - $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vv[0]); |
|
1430 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $vv[0])) { |
|
1431 | + $relations[$k] = [$v, $table]; |
|
1432 | + $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vv[0]); |
|
1438 | 1433 | } |
1439 | 1434 | } |
1440 | 1435 | foreach ($j as $kk => $vv) { |
1441 | 1436 | foreach ($vv->keymap as $kkk => $vvv) { |
1442 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vvv)) { |
|
1443 | - $relations[$k] = [ $v, $table ]; |
|
1437 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $vvv)) { |
|
1438 | + $relations[$k] = [$v, $table]; |
|
1444 | 1439 | $j[$kk]->keymap[$kkk] = |
1445 | - preg_replace('(\b'.preg_quote($k . '.'). ')i', $getAlias($k) . '.', $vvv); |
|
1440 | + preg_replace('(\b'.preg_quote($k.'.').')i', $getAlias($k).'.', $vvv); |
|
1446 | 1441 | } |
1447 | 1442 | } |
1448 | 1443 | } |
1449 | 1444 | } |
1450 | 1445 | foreach ($aliases_ext as $k => $alias) { |
1451 | 1446 | foreach ($w as $kk => $v) { |
1452 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) { |
|
1453 | - $w[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $v[0]); |
|
1447 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) { |
|
1448 | + $w[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $v[0]); |
|
1454 | 1449 | } |
1455 | 1450 | } |
1456 | 1451 | foreach ($h as $kk => $v) { |
1457 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $v[0])) { |
|
1458 | - $h[$kk][0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $v[0]); |
|
1452 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $v[0])) { |
|
1453 | + $h[$kk][0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $v[0]); |
|
1459 | 1454 | } |
1460 | 1455 | } |
1461 | - if (isset($o[0]) && preg_match('(\b'.preg_quote($k . '.'). ')i', $o[0])) { |
|
1462 | - $o[0] = preg_replace('(\b'.preg_quote($k . '.'). ')i', $alias . '.', $o[0]); |
|
1456 | + if (isset($o[0]) && preg_match('(\b'.preg_quote($k.'.').')i', $o[0])) { |
|
1457 | + $o[0] = preg_replace('(\b'.preg_quote($k.'.').')i', $alias.'.', $o[0]); |
|
1463 | 1458 | } |
1464 | 1459 | foreach ($j as $kk => $v) { |
1465 | 1460 | foreach ($v->keymap as $kkk => $vv) { |
1466 | - if (preg_match('(\b'.preg_quote($k . '.'). ')i', $vv)) { |
|
1461 | + if (preg_match('(\b'.preg_quote($k.'.').')i', $vv)) { |
|
1467 | 1462 | $j[$kk]->keymap[$kkk] = preg_replace( |
1468 | - '(\b'.preg_quote($k . '.'). ')i', |
|
1469 | - $alias . '.', |
|
1463 | + '(\b'.preg_quote($k.'.').')i', |
|
1464 | + $alias.'.', |
|
1470 | 1465 | $vv |
1471 | 1466 | ); |
1472 | 1467 | } |
@@ -1474,29 +1469,29 @@ discard block |
||
1474 | 1469 | } |
1475 | 1470 | } |
1476 | 1471 | |
1477 | - $key = array_map(function ($v) use ($table) { |
|
1478 | - return $table . '.' . $v; |
|
1472 | + $key = array_map(function($v) use ($table) { |
|
1473 | + return $table.'.'.$v; |
|
1479 | 1474 | }, $this->pkey); |
1480 | 1475 | $own = false; |
1481 | 1476 | $dir = 'ASC'; |
1482 | 1477 | if (count($o)) { |
1483 | 1478 | $dir = strpos($o[0], ' DESC') ? 'DESC' : 'ASC'; |
1484 | - $own = strpos($o[2], $table . '.') === 0; |
|
1479 | + $own = strpos($o[2], $table.'.') === 0; |
|
1485 | 1480 | } |
1486 | 1481 | |
1487 | 1482 | $dst = $key; |
1488 | 1483 | if (count($o)) { |
1489 | 1484 | if ($own) { |
1490 | 1485 | // if using own table - do not use max/min in order - that will prevent index usage |
1491 | - $dst[] = $o[2] . ' orderbyfix___'; |
|
1486 | + $dst[] = $o[2].' orderbyfix___'; |
|
1492 | 1487 | } else { |
1493 | - $dst[] = 'MAX(' . $o[2] . ') orderbyfix___'; |
|
1488 | + $dst[] = 'MAX('.$o[2].') orderbyfix___'; |
|
1494 | 1489 | } |
1495 | 1490 | } |
1496 | 1491 | $dst = array_unique($dst); |
1497 | 1492 | |
1498 | 1493 | $par = []; |
1499 | - $sql = 'SELECT DISTINCT '.implode(', ', $dst).' FROM '.$this->definition->getFullName().' '; |
|
1494 | + $sql = 'SELECT DISTINCT '.implode(', ', $dst).' FROM '.$this->definition->getFullName().' '; |
|
1500 | 1495 | foreach ($relations as $k => $v) { |
1501 | 1496 | $table = $v[1] !== $this->definition->getName() ? $getAlias($v[1]) : $v[1]; |
1502 | 1497 | $v = $v[0]; |
@@ -1507,13 +1502,13 @@ discard block |
||
1507 | 1502 | foreach ($v->keymap as $kk => $vv) { |
1508 | 1503 | $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' '; |
1509 | 1504 | } |
1510 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
1505 | + $sql .= implode(' AND ', $tmp).' '; |
|
1511 | 1506 | $sql .= 'LEFT JOIN '.$v->table->getName().' '.$getAlias($k).' ON '; |
1512 | 1507 | $tmp = []; |
1513 | 1508 | foreach ($v->pivot_keymap as $kk => $vv) { |
1514 | 1509 | $tmp[] = $getAlias($k).'.'.$vv.' = '.$alias.'.'.$kk.' '; |
1515 | 1510 | } |
1516 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
1511 | + $sql .= implode(' AND ', $tmp).' '; |
|
1517 | 1512 | } else { |
1518 | 1513 | $alias = $getAlias($k); |
1519 | 1514 | $sql .= 'LEFT JOIN '.$v->table->getName().' '.$alias.' ON '; |
@@ -1522,37 +1517,37 @@ discard block |
||
1522 | 1517 | $tmp[] = $table.'.'.$kk.' = '.$alias.'.'.$vv.' '; |
1523 | 1518 | } |
1524 | 1519 | if ($v->sql) { |
1525 | - $tmp[] = $v->sql . ' '; |
|
1520 | + $tmp[] = $v->sql.' '; |
|
1526 | 1521 | $par = array_merge($par, $v->par ?? []); |
1527 | 1522 | } |
1528 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
1523 | + $sql .= implode(' AND ', $tmp).' '; |
|
1529 | 1524 | } |
1530 | 1525 | } |
1531 | 1526 | foreach ($j as $k => $v) { |
1532 | - $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON '; |
|
1527 | + $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON '; |
|
1533 | 1528 | $tmp = []; |
1534 | 1529 | foreach ($v->keymap as $kk => $vv) { |
1535 | 1530 | $tmp[] = $kk.' = '.$vv; |
1536 | 1531 | } |
1537 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
1532 | + $sql .= implode(' AND ', $tmp).' '; |
|
1538 | 1533 | } |
1539 | 1534 | if (count($w)) { |
1540 | 1535 | $sql .= 'WHERE '; |
1541 | 1536 | $tmp = []; |
1542 | 1537 | foreach ($w as $v) { |
1543 | - $tmp[] = '(' . $v[0] . ')'; |
|
1538 | + $tmp[] = '('.$v[0].')'; |
|
1544 | 1539 | $par = array_merge($par, $v[1]); |
1545 | 1540 | } |
1546 | 1541 | $sql .= implode(' AND ', $tmp).' '; |
1547 | 1542 | } |
1548 | 1543 | if (!$own) { |
1549 | - $sql .= 'GROUP BY ' . implode(', ', $key) . ' '; |
|
1544 | + $sql .= 'GROUP BY '.implode(', ', $key).' '; |
|
1550 | 1545 | } |
1551 | 1546 | if (count($h)) { |
1552 | 1547 | $sql .= 'HAVING '; |
1553 | 1548 | $tmp = []; |
1554 | 1549 | foreach ($h as $v) { |
1555 | - $tmp[] = '(' . $v[0] . ')'; |
|
1550 | + $tmp[] = '('.$v[0].')'; |
|
1556 | 1551 | $par = array_merge($par, $v[1]); |
1557 | 1552 | } |
1558 | 1553 | $sql .= implode(' AND ', $tmp).' '; |
@@ -1560,38 +1555,38 @@ discard block |
||
1560 | 1555 | if (count($o)) { |
1561 | 1556 | $sql .= 'ORDER BY '; |
1562 | 1557 | if ($own) { |
1563 | - $sql .= $o[2] . ' ' . $dir; |
|
1558 | + $sql .= $o[2].' '.$dir; |
|
1564 | 1559 | } else { |
1565 | - $sql .= 'MAX('.$o[2].') ' . $dir; |
|
1560 | + $sql .= 'MAX('.$o[2].') '.$dir; |
|
1566 | 1561 | } |
1567 | 1562 | } |
1568 | 1563 | $porder = []; |
1569 | 1564 | $pdir = (count($o) && strpos($o[0], 'DESC') !== false) ? 'DESC' : 'ASC'; |
1570 | 1565 | foreach ($this->definition->getPrimaryKey() as $field) { |
1571 | - $porder[] = $this->getColumn($field)['name'] . ' ' . $pdir; |
|
1566 | + $porder[] = $this->getColumn($field)['name'].' '.$pdir; |
|
1572 | 1567 | } |
1573 | 1568 | if (count($porder)) { |
1574 | - $sql .= (count($o) ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' '; |
|
1569 | + $sql .= (count($o) ? ', ' : 'ORDER BY ').implode(', ', $porder).' '; |
|
1575 | 1570 | } |
1576 | 1571 | |
1577 | 1572 | if ($this->li_of[0]) { |
1578 | 1573 | if ($this->db->driverName() === 'oracle') { |
1579 | - if ((int)$this->db->driverOption('version', 0) >= 12) { |
|
1580 | - $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY'; |
|
1574 | + if ((int) $this->db->driverOption('version', 0) >= 12) { |
|
1575 | + $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY'; |
|
1581 | 1576 | } else { |
1582 | - $sql = "SELECT " . implode(', ', $dst) . " |
|
1577 | + $sql = "SELECT ".implode(', ', $dst)." |
|
1583 | 1578 | FROM ( |
1584 | 1579 | SELECT tbl__.*, rownum rnum__ FROM ( |
1585 | - " . $sql . " |
|
1580 | + " . $sql." |
|
1586 | 1581 | ) tbl__ |
1587 | - WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . " |
|
1582 | + WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])." |
|
1588 | 1583 | ) WHERE rnum__ > " . $this->li_of[1]; |
1589 | 1584 | } |
1590 | 1585 | } else { |
1591 | - $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1]; |
|
1586 | + $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1]; |
|
1592 | 1587 | } |
1593 | 1588 | } |
1594 | - return array_map(function ($v) { |
|
1589 | + return array_map(function($v) { |
|
1595 | 1590 | if (array_key_exists('orderbyfix___', $v)) { |
1596 | 1591 | unset($v['orderbyfix___']); |
1597 | 1592 | } |
@@ -71,7 +71,7 @@ |
||
71 | 71 | $this->softDetect($sql); |
72 | 72 | $statement = \ibase_prepare($this->transaction !== null ? $this->transaction : $this->lnk, $sql); |
73 | 73 | if ($statement === false) { |
74 | - throw new DBException('Prepare error: ' . \ibase_errmsg()); |
|
74 | + throw new DBException('Prepare error: '.\ibase_errmsg()); |
|
75 | 75 | } |
76 | 76 | return new Statement( |
77 | 77 | $statement, |