@@ -117,7 +117,6 @@ discard block |
||
117 | 117 | /** |
118 | 118 | * Run a query (prepare & execute). |
119 | 119 | * @param string $sql SQL query |
120 | - * @param array $data parameters (optional) |
|
121 | 120 | * @return ResultInterface the result of the execution |
122 | 121 | */ |
123 | 122 | public function query(string $sql, $par = null) : ResultInterface |
@@ -170,7 +169,6 @@ discard block |
||
170 | 169 | * Run a SELECT query and get a single row |
171 | 170 | * @param string $sql SQL query |
172 | 171 | * @param array $par parameters |
173 | - * @param callable $keys an optional mutator to pass each row's keys through (the column names) |
|
174 | 172 | * @param bool $opti if a single column is returned - do not use an array wrapper (defaults to `true`) |
175 | 173 | * @return Collection the result of the execution |
176 | 174 | */ |
@@ -184,7 +182,6 @@ discard block |
||
184 | 182 | * @param array $par parameters |
185 | 183 | * @param string $key column name to use as the array index |
186 | 184 | * @param bool $skip do not include the column used as index in the value (defaults to `false`) |
187 | - * @param callable $keys an optional mutator to pass each row's keys through (the column names) |
|
188 | 185 | * @param bool $opti if a single column is returned - do not use an array wrapper (defaults to `true`) |
189 | 186 | * @return Collection the result of the execution |
190 | 187 | */ |
@@ -73,8 +73,7 @@ discard block |
||
73 | 73 | } |
74 | 74 | $connection['name'] = $connectionString; |
75 | 75 | $connection['type'] = isset($aliases[$connection['type']]) ? |
76 | - $aliases[$connection['type']] : |
|
77 | - $connection['type']; |
|
76 | + $aliases[$connection['type']] : $connection['type']; |
|
78 | 77 | $tmp = '\\vakata\\database\\driver\\'.strtolower($connection['type']).'\\Driver'; |
79 | 78 | return new $tmp($connection); |
80 | 79 | } |
@@ -94,7 +93,7 @@ discard block |
||
94 | 93 | $new = ''; |
95 | 94 | $par = array_values($par); |
96 | 95 | if (substr_count($sql, '?') === 2 && !is_array($par[0])) { |
97 | - $par = [ $par ]; |
|
96 | + $par = [$par]; |
|
98 | 97 | } |
99 | 98 | $parts = explode('??', $sql); |
100 | 99 | $index = 0; |
@@ -104,7 +103,7 @@ discard block |
||
104 | 103 | $index += count($tmp) - 1; |
105 | 104 | if (isset($par[$index])) { |
106 | 105 | if (!is_array($par[$index])) { |
107 | - $par[$index] = [ $par[$index] ]; |
|
106 | + $par[$index] = [$par[$index]]; |
|
108 | 107 | } |
109 | 108 | $params = $par[$index]; |
110 | 109 | array_splice($par, $index, 1, $params); |
@@ -112,7 +111,7 @@ discard block |
||
112 | 111 | $new .= implode(',', array_fill(0, count($params), '?')); |
113 | 112 | } |
114 | 113 | } |
115 | - return [ $new, $par ]; |
|
114 | + return [$new, $par]; |
|
116 | 115 | } |
117 | 116 | /** |
118 | 117 | * Run a query (prepare & execute). |
@@ -144,7 +143,7 @@ discard block |
||
144 | 143 | { |
145 | 144 | $coll = Collection::from($this->query($sql, $par)); |
146 | 145 | if (($keys = $this->driver->option('mode')) && in_array($keys, ['strtoupper', 'strtolower'])) { |
147 | - $coll->map(function ($v) use ($keys) { |
|
146 | + $coll->map(function($v) use ($keys) { |
|
148 | 147 | $new = []; |
149 | 148 | foreach ($v as $k => $vv) { |
150 | 149 | $new[call_user_func($keys, $k)] = $vv; |
@@ -153,16 +152,16 @@ discard block |
||
153 | 152 | }); |
154 | 153 | } |
155 | 154 | if ($key) { |
156 | - $coll->mapKey(function ($v) use ($key) { return $v[$key]; }); |
|
155 | + $coll->mapKey(function($v) use ($key) { return $v[$key]; }); |
|
157 | 156 | } |
158 | 157 | if ($skip) { |
159 | - $coll->map(function ($v) use ($key) { unset($v[$key]); return $v; }); |
|
158 | + $coll->map(function($v) use ($key) { unset($v[$key]); return $v; }); |
|
160 | 159 | } |
161 | 160 | if ($opti) { |
162 | - $coll->map(function ($v) { return count($v) === 1 ? current($v) : $v; }); |
|
161 | + $coll->map(function($v) { return count($v) === 1 ? current($v) : $v; }); |
|
163 | 162 | } |
164 | 163 | if ($keys) { |
165 | - $coll->map(function ($v) use ($key) { unset($v[$key]); return $v; }); |
|
164 | + $coll->map(function($v) use ($key) { unset($v[$key]); return $v; }); |
|
166 | 165 | } |
167 | 166 | return $coll; |
168 | 167 | } |
@@ -237,8 +236,7 @@ discard block |
||
237 | 236 | public function definition(string $table, bool $detectRelations = true) : Table |
238 | 237 | { |
239 | 238 | return isset($this->tables[$table]) ? |
240 | - $this->tables[$table] : |
|
241 | - $this->driver->table($table, $detectRelations); |
|
239 | + $this->tables[$table] : $this->driver->table($table, $detectRelations); |
|
242 | 240 | } |
243 | 241 | /** |
244 | 242 | * Parse all tables from the database. |
@@ -255,12 +253,12 @@ discard block |
||
255 | 253 | */ |
256 | 254 | public function getSchema($asPlainArray = true) |
257 | 255 | { |
258 | - return !$asPlainArray ? $this->tables : array_map(function ($table) { |
|
256 | + return !$asPlainArray ? $this->tables : array_map(function($table) { |
|
259 | 257 | return [ |
260 | 258 | 'name' => $table->getName(), |
261 | 259 | 'pkey' => $table->getPrimaryKey(), |
262 | 260 | 'comment' => $table->getComment(), |
263 | - 'columns' => array_map(function ($column) { |
|
261 | + 'columns' => array_map(function($column) { |
|
264 | 262 | return [ |
265 | 263 | 'name' => $column->getName(), |
266 | 264 | 'type' => $column->getType(), |
@@ -270,13 +268,13 @@ discard block |
||
270 | 268 | 'nullable' => $column->isNullable() |
271 | 269 | ]; |
272 | 270 | }, $table->getFullColumns()), |
273 | - 'relations' => array_map(function ($rel) { |
|
271 | + 'relations' => array_map(function($rel) { |
|
274 | 272 | $relation = clone $rel; |
275 | 273 | $relation->table = $relation->table->getName(); |
276 | 274 | if ($relation->pivot) { |
277 | 275 | $relation->pivot = $relation->pivot->getName(); |
278 | 276 | } |
279 | - return (array)$relation; |
|
277 | + return (array) $relation; |
|
280 | 278 | }, $table->getRelations()) |
281 | 279 | ]; |
282 | 280 | }, $this->tables); |
@@ -15,6 +15,9 @@ |
||
15 | 15 | protected $iid = null; |
16 | 16 | protected $aff = 0; |
17 | 17 | |
18 | + /** |
|
19 | + * @param integer $aff |
|
20 | + */ |
|
18 | 21 | public function __construct($statement, $iid, $aff) |
19 | 22 | { |
20 | 23 | $this->statement = $statement; |
@@ -62,7 +62,7 @@ |
||
62 | 62 | } |
63 | 63 | public function next() |
64 | 64 | { |
65 | - $this->fetched ++; |
|
65 | + $this->fetched++; |
|
66 | 66 | $this->last = \pg_fetch_array($this->statement, null, \PGSQL_ASSOC); |
67 | 67 | } |
68 | 68 | public function valid() |
@@ -15,6 +15,10 @@ |
||
15 | 15 | protected $iid = null; |
16 | 16 | protected $aff = 0; |
17 | 17 | |
18 | + /** |
|
19 | + * @param integer $iid |
|
20 | + * @param integer $aff |
|
21 | + */ |
|
18 | 22 | public function __construct(\SQLite3Result $statement, $iid, $aff) |
19 | 23 | { |
20 | 24 | $this->statement = $statement; |
@@ -62,7 +62,7 @@ |
||
62 | 62 | } |
63 | 63 | public function next() |
64 | 64 | { |
65 | - $this->fetched ++; |
|
65 | + $this->fetched++; |
|
66 | 66 | $this->last = $this->statement->fetchArray(\SQLITE3_ASSOC); |
67 | 67 | } |
68 | 68 | public function valid() |
@@ -35,7 +35,6 @@ discard block |
||
35 | 35 | /** |
36 | 36 | * Run a query (prepare & execute). |
37 | 37 | * @param string $sql SQL query |
38 | - * @param array $data parameters (optional) |
|
39 | 38 | * @return ResultInterface the result of the execution |
40 | 39 | */ |
41 | 40 | public function query(string $sql, $par = null) : ResultInterface |
@@ -50,6 +49,13 @@ discard block |
||
50 | 49 | { |
51 | 50 | return $this->connection['name']; |
52 | 51 | } |
52 | + |
|
53 | + /** |
|
54 | + * @param string $key |
|
55 | + * @param string $default |
|
56 | + * |
|
57 | + * @return string |
|
58 | + */ |
|
53 | 59 | public function option($key, $default = null) |
54 | 60 | { |
55 | 61 | return isset($this->connection['opts'][$key]) ? $this->connection['opts'][$key] : $default; |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | $new = ''; |
13 | 13 | $par = array_values($par); |
14 | 14 | if (substr_count($sql, '?') === 2 && !is_array($par[0])) { |
15 | - $par = [ $par ]; |
|
15 | + $par = [$par]; |
|
16 | 16 | } |
17 | 17 | $parts = explode('??', $sql); |
18 | 18 | $index = 0; |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | $index += count($tmp) - 1; |
23 | 23 | if (isset($par[$index])) { |
24 | 24 | if (!is_array($par[$index])) { |
25 | - $par[$index] = [ $par[$index] ]; |
|
25 | + $par[$index] = [$par[$index]]; |
|
26 | 26 | } |
27 | 27 | $params = $par[$index]; |
28 | 28 | array_splice($par, $index, 1, $params); |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | $new .= implode(',', array_fill(0, count($params), '?')); |
31 | 31 | } |
32 | 32 | } |
33 | - return [ $new, $par ]; |
|
33 | + return [$new, $par]; |
|
34 | 34 | } |
35 | 35 | /** |
36 | 36 | * Run a query (prepare & execute). |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | /** |
57 | 57 | * Create an instance |
58 | 58 | * @param DBInterface $db the database connection |
59 | - * @param Table|string $definition the name or definition of the main table in the query |
|
59 | + * @param Table $table |
|
60 | 60 | */ |
61 | 61 | public function __construct(DBInterface $db, $table) |
62 | 62 | { |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | } |
192 | 192 | /** |
193 | 193 | * Group by a column (or columns) |
194 | - * @param string|array $column the column name (or names) to group by |
|
194 | + * @param string $column the column name (or names) to group by |
|
195 | 195 | * @return $this |
196 | 196 | */ |
197 | 197 | public function group($column) : TableQuery |
@@ -3,7 +3,6 @@ |
||
3 | 3 | |
4 | 4 | use vakata\database\DBInterface; |
5 | 5 | use vakata\database\DBException; |
6 | -use vakata\database\ResultInterface; |
|
7 | 6 | |
8 | 7 | /** |
9 | 8 | * A database query class |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | /** |
43 | 43 | * @var int[] |
44 | 44 | */ |
45 | - protected $li_of = [0,0]; |
|
45 | + protected $li_of = [0, 0]; |
|
46 | 46 | protected $fields = []; |
47 | 47 | /** |
48 | 48 | * @var array |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | public function __construct(DBInterface $db, $table) |
62 | 62 | { |
63 | 63 | $this->db = $db; |
64 | - $this->definition = $table instanceof Table ? $table : $this->db->definition((string)$table); |
|
64 | + $this->definition = $table instanceof Table ? $table : $this->db->definition((string) $table); |
|
65 | 65 | $this->columns($this->definition->getColumns()); |
66 | 66 | } |
67 | 67 | public function __clone() |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | { |
82 | 82 | $column = explode('.', $column, 2); |
83 | 83 | if (count($column) === 1) { |
84 | - $column = [ $this->definition->getName(), $column[0] ]; |
|
84 | + $column = [$this->definition->getName(), $column[0]]; |
|
85 | 85 | } |
86 | 86 | if ($column[0] === $this->definition->getName()) { |
87 | 87 | $col = $this->definition->getColumn($column[1]); |
@@ -100,10 +100,10 @@ discard block |
||
100 | 100 | throw new DBException('Invalid column name in related table'); |
101 | 101 | } |
102 | 102 | } else { |
103 | - throw new DBException('Invalid foreign table name: ' . implode(',', $column)); |
|
103 | + throw new DBException('Invalid foreign table name: '.implode(',', $column)); |
|
104 | 104 | } |
105 | 105 | } |
106 | - return [ 'name' => implode('.', $column), 'data' => $col ]; |
|
106 | + return ['name' => implode('.', $column), 'data' => $col]; |
|
107 | 107 | } |
108 | 108 | protected function normalizeValue(TableColumn $col, $value) |
109 | 109 | { |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | } |
143 | 143 | return $value; |
144 | 144 | case 'int': |
145 | - return (int)$value; |
|
145 | + return (int) $value; |
|
146 | 146 | default: |
147 | 147 | return $value; |
148 | 148 | } |
@@ -157,12 +157,12 @@ discard block |
||
157 | 157 | { |
158 | 158 | list($name, $column) = array_values($this->getColumn($column)); |
159 | 159 | if (is_null($value)) { |
160 | - return $this->where($name . ' IS NULL'); |
|
160 | + return $this->where($name.' IS NULL'); |
|
161 | 161 | } |
162 | 162 | if (!is_array($value)) { |
163 | 163 | return $this->where( |
164 | - $name . ' = ?', |
|
165 | - [ $this->normalizeValue($column, $value) ] |
|
164 | + $name.' = ?', |
|
165 | + [$this->normalizeValue($column, $value)] |
|
166 | 166 | ); |
167 | 167 | } |
168 | 168 | if (isset($value['beg']) && isset($value['end'])) { |
@@ -175,8 +175,8 @@ discard block |
||
175 | 175 | ); |
176 | 176 | } |
177 | 177 | return $this->where( |
178 | - $name . ' IN (??)', |
|
179 | - [ array_map(function ($v) use ($column) { return $this->normalizeValue($column, $v); }, $value) ] |
|
178 | + $name.' IN (??)', |
|
179 | + [array_map(function($v) use ($column) { return $this->normalizeValue($column, $v); }, $value)] |
|
180 | 180 | ); |
181 | 181 | } |
182 | 182 | /** |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | */ |
188 | 188 | public function sort(string $column, bool $desc = false) : TableQuery |
189 | 189 | { |
190 | - return $this->order($this->getColumn($column)['name'] . ' ' . ($desc ? 'DESC' : 'ASC')); |
|
190 | + return $this->order($this->getColumn($column)['name'].' '.($desc ? 'DESC' : 'ASC')); |
|
191 | 191 | } |
192 | 192 | /** |
193 | 193 | * Group by a column (or columns) |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | public function group($column) : TableQuery |
198 | 198 | { |
199 | 199 | if (!is_array($column)) { |
200 | - $column = [ $column ]; |
|
200 | + $column = [$column]; |
|
201 | 201 | } |
202 | 202 | foreach ($column as $k => $v) { |
203 | 203 | $column[$k] = $this->getColumn($v)['name']; |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | $this->withr = []; |
239 | 239 | $this->order = []; |
240 | 240 | $this->having = []; |
241 | - $this->li_of = [0,0]; |
|
241 | + $this->li_of = [0, 0]; |
|
242 | 242 | $this->qiterator = null; |
243 | 243 | return $this; |
244 | 244 | } |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | public function groupBy(string $sql, array $params = []) : TableQuery |
252 | 252 | { |
253 | 253 | $this->qiterator = null; |
254 | - $this->group = [ $sql, $params ]; |
|
254 | + $this->group = [$sql, $params]; |
|
255 | 255 | return $this; |
256 | 256 | } |
257 | 257 | /** |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | */ |
265 | 265 | public function join($table, array $fields, string $name = null, bool $multiple = true) |
266 | 266 | { |
267 | - $table = $table instanceof Table ? $table : $this->db->definition((string)$table); |
|
267 | + $table = $table instanceof Table ? $table : $this->db->definition((string) $table); |
|
268 | 268 | $name = $name ?? $table->getName(); |
269 | 269 | if (isset($this->joins[$name]) || $this->definition->hasRelation($name)) { |
270 | 270 | throw new DBException('Alias / table name already in use'); |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | foreach ($fields as $k => $v) { |
274 | 274 | $k = explode('.', $k, 2); |
275 | 275 | $k = count($k) == 2 ? $k[1] : $k[0]; |
276 | - $this->joins[$name]->keymap[$this->getColumn($name . '.' . $k)['name']] = $this->getColumn($v)['name']; |
|
276 | + $this->joins[$name]->keymap[$this->getColumn($name.'.'.$k)['name']] = $this->getColumn($v)['name']; |
|
277 | 277 | } |
278 | 278 | return $this; |
279 | 279 | } |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | public function where(string $sql, array $params = []) : TableQuery |
287 | 287 | { |
288 | 288 | $this->qiterator = null; |
289 | - $this->where[] = [ $sql, $params ]; |
|
289 | + $this->where[] = [$sql, $params]; |
|
290 | 290 | return $this; |
291 | 291 | } |
292 | 292 | /** |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | public function having(string $sql, array $params = []) : TableQuery |
299 | 299 | { |
300 | 300 | $this->qiterator = null; |
301 | - $this->having[] = [ $sql, $params ]; |
|
301 | + $this->having[] = [$sql, $params]; |
|
302 | 302 | return $this; |
303 | 303 | } |
304 | 304 | /** |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | public function order(string $sql, array $params = []) : TableQuery |
311 | 311 | { |
312 | 312 | $this->qiterator = null; |
313 | - $this->order = [ $sql, $params ]; |
|
313 | + $this->order = [$sql, $params]; |
|
314 | 314 | return $this; |
315 | 315 | } |
316 | 316 | /** |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | public function limit(int $limit, int $offset = 0) : TableQuery |
323 | 323 | { |
324 | 324 | $this->qiterator = null; |
325 | - $this->li_of = [ $limit, $offset ]; |
|
325 | + $this->li_of = [$limit, $offset]; |
|
326 | 326 | return $this; |
327 | 327 | } |
328 | 328 | /** |
@@ -339,22 +339,22 @@ discard block |
||
339 | 339 | $relations = $this->withr; |
340 | 340 | foreach ($this->definition->getRelations() as $k => $v) { |
341 | 341 | foreach ($this->where as $vv) { |
342 | - if (strpos($vv[0], $k . '.') !== false) { |
|
342 | + if (strpos($vv[0], $k.'.') !== false) { |
|
343 | 343 | $relations[] = $k; |
344 | 344 | } |
345 | 345 | } |
346 | - if (isset($this->order[0]) && strpos($this->order[0], $k . '.') !== false) { |
|
346 | + if (isset($this->order[0]) && strpos($this->order[0], $k.'.') !== false) { |
|
347 | 347 | $relations[] = $k; |
348 | 348 | } |
349 | 349 | } |
350 | 350 | |
351 | 351 | foreach ($this->joins as $k => $v) { |
352 | - $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON '; |
|
352 | + $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON '; |
|
353 | 353 | $tmp = []; |
354 | 354 | foreach ($v->keymap as $kk => $vv) { |
355 | 355 | $tmp[] = $kk.' = '.$vv; |
356 | 356 | } |
357 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
357 | + $sql .= implode(' AND ', $tmp).' '; |
|
358 | 358 | } |
359 | 359 | foreach (array_unique($relations) as $k) { |
360 | 360 | $v = $this->definition->getRelation($k); |
@@ -364,13 +364,13 @@ discard block |
||
364 | 364 | foreach ($v->keymap as $kk => $vv) { |
365 | 365 | $tmp[] = $table.'.'.$kk.' = '.$k.'_pivot.'.$vv.' '; |
366 | 366 | } |
367 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
367 | + $sql .= implode(' AND ', $tmp).' '; |
|
368 | 368 | $sql .= 'LEFT JOIN '.$v->table->getName().' '.$k.' ON '; |
369 | 369 | $tmp = []; |
370 | 370 | foreach ($v->pivot_keymap as $kk => $vv) { |
371 | 371 | $tmp[] = $k.'.'.$vv.' = '.$k.'_pivot.'.$kk.' '; |
372 | 372 | } |
373 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
373 | + $sql .= implode(' AND ', $tmp).' '; |
|
374 | 374 | } else { |
375 | 375 | $sql .= 'LEFT JOIN '.$v->table->getName().' '.$k.' ON '; |
376 | 376 | $tmp = []; |
@@ -378,30 +378,30 @@ discard block |
||
378 | 378 | $tmp[] = $table.'.'.$kk.' = '.$k.'.'.$vv.' '; |
379 | 379 | } |
380 | 380 | if ($v->sql) { |
381 | - $tmp[] = $v->sql . ' '; |
|
381 | + $tmp[] = $v->sql.' '; |
|
382 | 382 | $par = array_merge($par, $v->par ?? []); |
383 | 383 | } |
384 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
384 | + $sql .= implode(' AND ', $tmp).' '; |
|
385 | 385 | } |
386 | 386 | } |
387 | 387 | if (count($this->where)) { |
388 | 388 | $sql .= 'WHERE '; |
389 | 389 | $tmp = []; |
390 | 390 | foreach ($this->where as $v) { |
391 | - $tmp[] = '(' . $v[0] . ')'; |
|
391 | + $tmp[] = '('.$v[0].')'; |
|
392 | 392 | $par = array_merge($par, $v[1]); |
393 | 393 | } |
394 | 394 | $sql .= implode(' AND ', $tmp).' '; |
395 | 395 | } |
396 | 396 | if (count($this->group)) { |
397 | - $sql .= 'GROUP BY ' . $this->group[0] . ' '; |
|
397 | + $sql .= 'GROUP BY '.$this->group[0].' '; |
|
398 | 398 | $par = array_merge($par, $this->group[1]); |
399 | 399 | } |
400 | 400 | if (count($this->having)) { |
401 | 401 | $sql .= 'HAVING '; |
402 | 402 | $tmp = []; |
403 | 403 | foreach ($this->having as $v) { |
404 | - $tmp[] = '(' . $v[0] . ')'; |
|
404 | + $tmp[] = '('.$v[0].')'; |
|
405 | 405 | $par = array_merge($par, $v[1]); |
406 | 406 | } |
407 | 407 | $sql .= implode(' AND ', $tmp).' '; |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | throw new DBException('Invalid foreign table name'); |
433 | 433 | } |
434 | 434 | foreach ($cols as $col) { |
435 | - $fields[] = $table . '.' . $col; |
|
435 | + $fields[] = $table.'.'.$col; |
|
436 | 436 | } |
437 | 437 | unset($fields[$k]); |
438 | 438 | } |
@@ -472,37 +472,37 @@ discard block |
||
472 | 472 | $relations = $this->withr; |
473 | 473 | foreach ($this->definition->getRelations() as $k => $v) { |
474 | 474 | foreach ($this->fields as $field) { |
475 | - if (strpos($field, $k . '.') === 0) { |
|
475 | + if (strpos($field, $k.'.') === 0) { |
|
476 | 476 | $relations[] = $k; |
477 | 477 | } |
478 | 478 | } |
479 | 479 | foreach ($this->where as $v) { |
480 | - if (strpos($v[0], $k . '.') !== false) { |
|
480 | + if (strpos($v[0], $k.'.') !== false) { |
|
481 | 481 | $relations[] = $k; |
482 | 482 | } |
483 | 483 | } |
484 | - if (isset($this->order[0]) && strpos($this->order[0], $k . '.') !== false) { |
|
484 | + if (isset($this->order[0]) && strpos($this->order[0], $k.'.') !== false) { |
|
485 | 485 | $relations[] = $k; |
486 | 486 | } |
487 | 487 | } |
488 | 488 | $select = []; |
489 | 489 | foreach ($this->fields as $k => $field) { |
490 | - $select[] = $field . (!is_numeric($k) ? ' ' . $k : ''); |
|
490 | + $select[] = $field.(!is_numeric($k) ? ' '.$k : ''); |
|
491 | 491 | } |
492 | 492 | foreach ($this->withr as $relation) { |
493 | 493 | foreach ($this->definition->getRelation($relation)->table->getColumns() as $column) { |
494 | - $select[] = $relation . '.' . $column . ' ' . $relation . '___' . $column; |
|
494 | + $select[] = $relation.'.'.$column.' '.$relation.'___'.$column; |
|
495 | 495 | } |
496 | 496 | } |
497 | 497 | $sql = 'SELECT '.implode(', ', $select).' FROM '.$table.' '; |
498 | 498 | $par = []; |
499 | 499 | foreach ($this->joins as $k => $v) { |
500 | - $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON '; |
|
500 | + $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON '; |
|
501 | 501 | $tmp = []; |
502 | 502 | foreach ($v->keymap as $kk => $vv) { |
503 | 503 | $tmp[] = $kk.' = '.$vv; |
504 | 504 | } |
505 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
505 | + $sql .= implode(' AND ', $tmp).' '; |
|
506 | 506 | } |
507 | 507 | foreach (array_unique($relations) as $relation) { |
508 | 508 | $v = $this->definition->getRelation($relation); |
@@ -512,13 +512,13 @@ discard block |
||
512 | 512 | foreach ($v->keymap as $kk => $vv) { |
513 | 513 | $tmp[] = $table.'.'.$kk.' = '.$relation.'_pivot.'.$vv.' '; |
514 | 514 | } |
515 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
515 | + $sql .= implode(' AND ', $tmp).' '; |
|
516 | 516 | $sql .= 'LEFT JOIN '.$v->table->getName().' '.$relation.' ON '; |
517 | 517 | $tmp = []; |
518 | 518 | foreach ($v->pivot_keymap as $kk => $vv) { |
519 | 519 | $tmp[] = $relation.'.'.$vv.' = '.$relation.'_pivot.'.$kk.' '; |
520 | 520 | } |
521 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
521 | + $sql .= implode(' AND ', $tmp).' '; |
|
522 | 522 | } else { |
523 | 523 | $sql .= 'LEFT JOIN '.$v->table->getName().' '.$relation.' ON '; |
524 | 524 | $tmp = []; |
@@ -526,30 +526,30 @@ discard block |
||
526 | 526 | $tmp[] = $table.'.'.$kk.' = '.$relation.'.'.$vv.' '; |
527 | 527 | } |
528 | 528 | if ($v->sql) { |
529 | - $tmp[] = $v->sql . ' '; |
|
529 | + $tmp[] = $v->sql.' '; |
|
530 | 530 | $par = array_merge($par, $v->par ?? []); |
531 | 531 | } |
532 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
532 | + $sql .= implode(' AND ', $tmp).' '; |
|
533 | 533 | } |
534 | 534 | } |
535 | 535 | if (count($this->where)) { |
536 | 536 | $sql .= 'WHERE '; |
537 | 537 | $tmp = []; |
538 | 538 | foreach ($this->where as $v) { |
539 | - $tmp[] = '(' . $v[0] . ')'; |
|
539 | + $tmp[] = '('.$v[0].')'; |
|
540 | 540 | $par = array_merge($par, $v[1]); |
541 | 541 | } |
542 | 542 | $sql .= implode(' AND ', $tmp).' '; |
543 | 543 | } |
544 | 544 | if (count($this->group)) { |
545 | - $sql .= 'GROUP BY ' . $this->group[0] . ' '; |
|
545 | + $sql .= 'GROUP BY '.$this->group[0].' '; |
|
546 | 546 | $par = array_merge($par, $this->group[1]); |
547 | 547 | } |
548 | 548 | if (count($this->having)) { |
549 | 549 | $sql .= 'HAVING '; |
550 | 550 | $tmp = []; |
551 | 551 | foreach ($this->having as $v) { |
552 | - $tmp[] = '(' . $v[0] . ')'; |
|
552 | + $tmp[] = '('.$v[0].')'; |
|
553 | 553 | $par = array_merge($par, $v[1]); |
554 | 554 | } |
555 | 555 | $sql .= implode(' AND ', $tmp).' '; |
@@ -558,36 +558,36 @@ discard block |
||
558 | 558 | // $sql .= 'GROUP BY '.$table.'.'.implode(', '.$table.'.', $primary).' '; |
559 | 559 | //} |
560 | 560 | if (count($this->order)) { |
561 | - $sql .= 'ORDER BY ' . $this->order[0] . ' '; |
|
561 | + $sql .= 'ORDER BY '.$this->order[0].' '; |
|
562 | 562 | $par = array_merge($par, $this->order[1]); |
563 | 563 | } |
564 | 564 | $porder = []; |
565 | 565 | foreach ($primary as $field) { |
566 | 566 | $porder[] = $this->getColumn($field)['name']; |
567 | 567 | } |
568 | - $sql .= (count($this->order) ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' '; |
|
568 | + $sql .= (count($this->order) ? ', ' : 'ORDER BY ').implode(', ', $porder).' '; |
|
569 | 569 | |
570 | 570 | if ($this->li_of[0]) { |
571 | 571 | if ($this->db->driver() === 'oracle') { |
572 | - if ((int)($this->db->settings()->options['version'] ?? 0) >= 12) { |
|
573 | - $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY'; |
|
572 | + if ((int) ($this->db->settings()->options['version'] ?? 0) >= 12) { |
|
573 | + $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY'; |
|
574 | 574 | } else { |
575 | - $f = array_map(function ($v) { |
|
575 | + $f = array_map(function($v) { |
|
576 | 576 | $v = explode(' ', trim($v), 2); |
577 | 577 | if (count($v) === 2) { return $v[1]; } |
578 | 578 | $v = explode('.', $v[0], 2); |
579 | 579 | return count($v) === 2 ? $v[1] : $v[0]; |
580 | 580 | }, $select); |
581 | - $sql = "SELECT " . implode(', ', $f) . " |
|
581 | + $sql = "SELECT ".implode(', ', $f)." |
|
582 | 582 | FROM ( |
583 | 583 | SELECT tbl__.*, rownum rnum__ FROM ( |
584 | - " . $sql . " |
|
584 | + " . $sql." |
|
585 | 585 | ) tbl__ |
586 | - WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . " |
|
586 | + WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])." |
|
587 | 587 | ) WHERE rnum__ > " . $this->li_of[1]; |
588 | 588 | } |
589 | 589 | } else { |
590 | - $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1]; |
|
590 | + $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1]; |
|
591 | 591 | } |
592 | 592 | } |
593 | 593 | return $this->qiterator = new TableQueryIterator( |
@@ -595,7 +595,7 @@ discard block |
||
595 | 595 | $this->definition->getPrimaryKey(), |
596 | 596 | array_combine( |
597 | 597 | $this->withr, |
598 | - array_map(function ($relation) { |
|
598 | + array_map(function($relation) { |
|
599 | 599 | return $this->definition->getRelation($relation); |
600 | 600 | }, $this->withr) |
601 | 601 | ) |
@@ -642,7 +642,7 @@ discard block |
||
642 | 642 | $ret[$k] = str_repeat(' ', 255); |
643 | 643 | $par[] = &$ret[$k]; |
644 | 644 | } |
645 | - $sql .= ' RETURNING ' . implode(',', $primary) . ' INTO ' . implode(',', array_fill(0, count($primary), '?')); |
|
645 | + $sql .= ' RETURNING '.implode(',', $primary).' INTO '.implode(',', array_fill(0, count($primary), '?')); |
|
646 | 646 | $this->db->query($sql, $par); |
647 | 647 | return $ret; |
648 | 648 | } else { |
@@ -674,7 +674,7 @@ discard block |
||
674 | 674 | } |
675 | 675 | $sql = 'UPDATE '.$table.' SET '; |
676 | 676 | $par = []; |
677 | - $sql .= implode(', ', array_map(function ($v) { return $v . ' = ?'; }, array_keys($update))) . ' '; |
|
677 | + $sql .= implode(', ', array_map(function($v) { return $v.' = ?'; }, array_keys($update))).' '; |
|
678 | 678 | $par = array_merge($par, array_values($update)); |
679 | 679 | if (count($this->where)) { |
680 | 680 | $sql .= 'WHERE '; |
@@ -683,7 +683,7 @@ discard block |
||
683 | 683 | $tmp[] = $v[0]; |
684 | 684 | $par = array_merge($par, $v[1]); |
685 | 685 | } |
686 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
686 | + $sql .= implode(' AND ', $tmp).' '; |
|
687 | 687 | } |
688 | 688 | if (count($this->order)) { |
689 | 689 | $sql .= $this->order[0]; |
@@ -707,7 +707,7 @@ discard block |
||
707 | 707 | $tmp[] = $v[0]; |
708 | 708 | $par = array_merge($par, $v[1]); |
709 | 709 | } |
710 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
710 | + $sql .= implode(' AND ', $tmp).' '; |
|
711 | 711 | } |
712 | 712 | if (count($this->order)) { |
713 | 713 | $sql .= $this->order[0]; |
@@ -23,8 +23,7 @@ |
||
23 | 23 | $data = array(); |
24 | 24 | } |
25 | 25 | $temp = (is_array($data) && count($data)) ? |
26 | - \pg_query_params($this->driver, $this->statement, $data) : |
|
27 | - \pg_query_params($this->driver, $this->statement, array()); |
|
26 | + \pg_query_params($this->driver, $this->statement, $data) : \pg_query_params($this->driver, $this->statement, array()); |
|
28 | 27 | if (!$temp) { |
29 | 28 | throw new DBException('Could not execute query : '.\pg_last_error($this->driver).' <'.$this->statement.'>'); |
30 | 29 | } |
@@ -64,7 +64,7 @@ |
||
64 | 64 | } |
65 | 65 | public function next() |
66 | 66 | { |
67 | - $this->fetched ++; |
|
67 | + $this->fetched++; |
|
68 | 68 | $this->last = \oci_fetch_array($this->statement, \OCI_ASSOC + \OCI_RETURN_NULLS + \OCI_RETURN_LOBS); |
69 | 69 | } |
70 | 70 | public function valid() |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | |
76 | 76 | public function begin() : bool |
77 | 77 | { |
78 | - return $this->transaction = true; |
|
78 | + return $this->transaction = true; |
|
79 | 79 | } |
80 | 80 | public function commit() : bool |
81 | 81 | { |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | } |
200 | 200 | return $new; |
201 | 201 | }) |
202 | - as $relation |
|
202 | + as $relation |
|
203 | 203 | ) { |
204 | 204 | $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_NAME']; |
205 | 205 | $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int)$relation['POSITION']-1]] = $relation['COLUMN_NAME']; |
@@ -125,16 +125,16 @@ discard block |
||
125 | 125 | $columns = Collection::from($this |
126 | 126 | ->query( |
127 | 127 | "SELECT * FROM all_tab_cols WHERE table_name = ? AND owner = ?", |
128 | - [ strtoupper($table), $this->name() ] |
|
128 | + [strtoupper($table), $this->name()] |
|
129 | 129 | )) |
130 | - ->map(function ($v) { |
|
130 | + ->map(function($v) { |
|
131 | 131 | $new = []; |
132 | 132 | foreach ($v as $kk => $vv) { |
133 | 133 | $new[strtoupper($kk)] = $vv; |
134 | 134 | } |
135 | 135 | return $new; |
136 | 136 | }) |
137 | - ->mapKey(function ($v) { return $v['COLUMN_NAME']; }) |
|
137 | + ->mapKey(function($v) { return $v['COLUMN_NAME']; }) |
|
138 | 138 | ->toArray(); |
139 | 139 | if (!count($columns)) { |
140 | 140 | throw new DBException('Table not found by name'); |
@@ -144,9 +144,9 @@ discard block |
||
144 | 144 | ->query( |
145 | 145 | "SELECT constraint_name FROM all_constraints |
146 | 146 | WHERE table_name = ? AND constraint_type = ? AND owner = ?", |
147 | - [ strtoupper($table), 'P', $owner ] |
|
147 | + [strtoupper($table), 'P', $owner] |
|
148 | 148 | )) |
149 | - ->map(function ($v) { |
|
149 | + ->map(function($v) { |
|
150 | 150 | $new = []; |
151 | 151 | foreach ($v as $kk => $vv) { |
152 | 152 | $new[strtoupper($kk)] = $vv; |
@@ -161,9 +161,9 @@ discard block |
||
161 | 161 | ->query( |
162 | 162 | "SELECT column_name FROM all_cons_columns |
163 | 163 | WHERE table_name = ? AND constraint_name = ? AND owner = ?", |
164 | - [ strtoupper($table), $pkname, $owner ] |
|
164 | + [strtoupper($table), $pkname, $owner] |
|
165 | 165 | )) |
166 | - ->map(function ($v) { |
|
166 | + ->map(function($v) { |
|
167 | 167 | $new = []; |
168 | 168 | foreach ($v as $kk => $vv) { |
169 | 169 | $new[strtoupper($kk)] = $vv; |
@@ -190,9 +190,9 @@ discard block |
||
190 | 190 | LEFT JOIN all_cons_columns cc ON cc.OWNER = ac.OWNER AND cc.CONSTRAINT_NAME = ac.CONSTRAINT_NAME |
191 | 191 | WHERE ac.OWNER = ? AND ac.R_OWNER = ? AND ac.R_CONSTRAINT_NAME = ? AND ac.CONSTRAINT_TYPE = ? |
192 | 192 | ORDER BY cc.POSITION", |
193 | - [ $owner, $owner, $pkname, 'R' ] |
|
193 | + [$owner, $owner, $pkname, 'R'] |
|
194 | 194 | )) |
195 | - ->map(function ($v) { |
|
195 | + ->map(function($v) { |
|
196 | 196 | $new = []; |
197 | 197 | foreach ($v as $kk => $vv) { |
198 | 198 | $new[strtoupper($kk)] = $vv; |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | as $relation |
203 | 203 | ) { |
204 | 204 | $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_NAME']; |
205 | - $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int)$relation['POSITION']-1]] = $relation['COLUMN_NAME']; |
|
205 | + $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int) $relation['POSITION'] - 1]] = $relation['COLUMN_NAME']; |
|
206 | 206 | } |
207 | 207 | foreach ($relations as $data) { |
208 | 208 | $rtable = $this->table($data['table'], true); // ?? $this->addTableByName($data['table'], false); |
@@ -226,9 +226,9 @@ discard block |
||
226 | 226 | ac.OWNER = ? AND ac.R_OWNER = ? AND ac.TABLE_NAME = ? AND ac.CONSTRAINT_TYPE = ? AND |
227 | 227 | cc.COLUMN_NAME IN (??) |
228 | 228 | ORDER BY POSITION", |
229 | - [ $owner, $owner, $data['table'], 'R', $columns ] |
|
229 | + [$owner, $owner, $data['table'], 'R', $columns] |
|
230 | 230 | )) |
231 | - ->map(function ($v) { |
|
231 | + ->map(function($v) { |
|
232 | 232 | $new = []; |
233 | 233 | foreach ($v as $kk => $vv) { |
234 | 234 | $new[strtoupper($kk)] = $vv; |
@@ -246,9 +246,9 @@ discard block |
||
246 | 246 | $rcolumns = Collection::from($this |
247 | 247 | ->query( |
248 | 248 | "SELECT COLUMN_NAME FROM all_cons_columns WHERE OWNER = ? AND CONSTRAINT_NAME = ? ORDER BY POSITION", |
249 | - [ $owner, current($foreign['keymap']) ] |
|
249 | + [$owner, current($foreign['keymap'])] |
|
250 | 250 | )) |
251 | - ->map(function ($v) { |
|
251 | + ->map(function($v) { |
|
252 | 252 | $new = []; |
253 | 253 | foreach ($v as $kk => $vv) { |
254 | 254 | $new[strtoupper($kk)] = $vv; |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | $relname = $foreign['table']; |
264 | 264 | $cntr = 1; |
265 | 265 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
266 | - $relname = $foreign['table'] . '_' . (++ $cntr); |
|
266 | + $relname = $foreign['table'].'_'.(++$cntr); |
|
267 | 267 | } |
268 | 268 | $definition->addRelation( |
269 | 269 | new TableRelation( |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | $relname = $data['table']; |
280 | 280 | $cntr = 1; |
281 | 281 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
282 | - $relname = $data['table'] . '_' . (++ $cntr); |
|
282 | + $relname = $data['table'].'_'.(++$cntr); |
|
283 | 283 | } |
284 | 284 | $definition->addRelation( |
285 | 285 | new TableRelation( |
@@ -303,9 +303,9 @@ discard block |
||
303 | 303 | LEFT JOIN all_cons_columns cc ON cc.OWNER = ac.OWNER AND cc.CONSTRAINT_NAME = ac.CONSTRAINT_NAME |
304 | 304 | WHERE ac.OWNER = ? AND ac.R_OWNER = ? AND ac.TABLE_NAME = ? AND ac.CONSTRAINT_TYPE = ? |
305 | 305 | ORDER BY cc.POSITION", |
306 | - [ $owner, $owner, strtoupper($table), 'R' ] |
|
306 | + [$owner, $owner, strtoupper($table), 'R'] |
|
307 | 307 | )) |
308 | - ->map(function ($v) { |
|
308 | + ->map(function($v) { |
|
309 | 309 | $new = []; |
310 | 310 | foreach ($v as $kk => $vv) { |
311 | 311 | $new[strtoupper($kk)] = $vv; |
@@ -321,9 +321,9 @@ discard block |
||
321 | 321 | $rcolumns = Collection::from($this |
322 | 322 | ->query( |
323 | 323 | "SELECT COLUMN_NAME FROM all_cons_columns WHERE OWNER = ? AND CONSTRAINT_NAME = ? ORDER BY POSITION", |
324 | - [ $owner, current($data['keymap']) ] |
|
324 | + [$owner, current($data['keymap'])] |
|
325 | 325 | )) |
326 | - ->map(function ($v) { |
|
326 | + ->map(function($v) { |
|
327 | 327 | $new = []; |
328 | 328 | foreach ($v as $kk => $vv) { |
329 | 329 | $new[strtoupper($kk)] = $vv; |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | $relname = $data['table']; |
339 | 339 | $cntr = 1; |
340 | 340 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
341 | - $relname = $data['table'] . '_' . (++ $cntr); |
|
341 | + $relname = $data['table'].'_'.(++$cntr); |
|
342 | 342 | } |
343 | 343 | $definition->addRelation( |
344 | 344 | new TableRelation( |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | "SELECT TABLE_NAME FROM ALL_TABLES where OWNER = ?", |
360 | 360 | [$this->connection['name']] |
361 | 361 | )) |
362 | - ->map(function ($v) { |
|
362 | + ->map(function($v) { |
|
363 | 363 | $new = []; |
364 | 364 | foreach ($v as $kk => $vv) { |
365 | 365 | $new[strtoupper($kk)] = $vv; |
@@ -367,7 +367,7 @@ discard block |
||
367 | 367 | return $new; |
368 | 368 | }) |
369 | 369 | ->pluck('TABLE_NAME') |
370 | - ->map(function ($v) { |
|
370 | + ->map(function($v) { |
|
371 | 371 | return $this->table($v); |
372 | 372 | }) |
373 | 373 | ->toArray(); |
@@ -22,7 +22,7 @@ |
||
22 | 22 | parse_str($temp[1], $connection['opts']); |
23 | 23 | $connection['name'] = $temp[0]; |
24 | 24 | if (!is_file($connection['name']) && is_file('/'.$connection['name'])) { |
25 | - $connection['name'] = '/'.$connection['name']; |
|
25 | + $connection['name'] = '/'.$connection['name']; |
|
26 | 26 | } |
27 | 27 | $this->connection = $connection; |
28 | 28 | } |