@@ -55,7 +55,7 @@ |
||
55 | 55 | } |
56 | 56 | public function next() |
57 | 57 | { |
58 | - $this->fetched ++; |
|
58 | + $this->fetched++; |
|
59 | 59 | $this->last = $this->statement->fetch(\PDO::FETCH_ASSOC); |
60 | 60 | } |
61 | 61 | public function valid() |
@@ -44,7 +44,7 @@ |
||
44 | 44 | isset($this->connection['opts']) ? $this->connection['opts'] : [] |
45 | 45 | ); |
46 | 46 | } catch (\PDOException $e) { |
47 | - throw new DBException('Connect error: ' . $e->getMessage()); |
|
47 | + throw new DBException('Connect error: '.$e->getMessage()); |
|
48 | 48 | } |
49 | 49 | } |
50 | 50 | } |
@@ -47,7 +47,7 @@ |
||
47 | 47 | $instance->setDefault($data['default']); |
48 | 48 | } |
49 | 49 | if ($instance->getBasicType() === 'enum' && strpos($instance->getType(), 'enum(') === 0) { |
50 | - $temp = array_map(function ($v) { |
|
50 | + $temp = array_map(function($v) { |
|
51 | 51 | return str_replace("''", "'", $v); |
52 | 52 | }, explode("','", substr($instance->getType(), 6, -2))); |
53 | 53 | $instance->setValues($temp); |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | public function setPrimaryKey($column) : Table |
79 | 79 | { |
80 | 80 | if (!is_array($column)) { |
81 | - $column = [ $column ]; |
|
81 | + $column = [$column]; |
|
82 | 82 | } |
83 | 83 | $this->data['primary'] = $column; |
84 | 84 | return $this; |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | } |
166 | 166 | |
167 | 167 | if (!isset($name)) { |
168 | - $name = $toTable->getName() . '_' . implode('_', array_keys($keymap)); |
|
168 | + $name = $toTable->getName().'_'.implode('_', array_keys($keymap)); |
|
169 | 169 | } |
170 | 170 | $this->addRelation(new TableRelation( |
171 | 171 | $name, |
@@ -83,7 +83,7 @@ |
||
83 | 83 | } |
84 | 84 | } |
85 | 85 | if (!$this->statement->execute()) { |
86 | - throw new DBException('Prepared execute error: ' . $this->statement->error); |
|
86 | + throw new DBException('Prepared execute error: '.$this->statement->error); |
|
87 | 87 | } |
88 | 88 | return new Result($this->statement); |
89 | 89 | } |
@@ -74,8 +74,7 @@ discard block |
||
74 | 74 | } |
75 | 75 | $connection['name'] = $connectionString; |
76 | 76 | $connection['type'] = isset($aliases[$connection['type']]) ? |
77 | - $aliases[$connection['type']] : |
|
78 | - $connection['type']; |
|
77 | + $aliases[$connection['type']] : $connection['type']; |
|
79 | 78 | $tmp = '\\vakata\\database\\driver\\'.strtolower($connection['type']).'\\Driver'; |
80 | 79 | return new $tmp($connection); |
81 | 80 | } |
@@ -95,7 +94,7 @@ discard block |
||
95 | 94 | $new = ''; |
96 | 95 | $par = array_values($par); |
97 | 96 | if (substr_count($sql, '?') === 2 && !is_array($par[0])) { |
98 | - $par = [ $par ]; |
|
97 | + $par = [$par]; |
|
99 | 98 | } |
100 | 99 | $parts = explode('??', $sql); |
101 | 100 | $index = 0; |
@@ -105,7 +104,7 @@ discard block |
||
105 | 104 | $index += count($tmp) - 1; |
106 | 105 | if (isset($par[$index])) { |
107 | 106 | if (!is_array($par[$index])) { |
108 | - $par[$index] = [ $par[$index] ]; |
|
107 | + $par[$index] = [$par[$index]]; |
|
109 | 108 | } |
110 | 109 | $params = $par[$index]; |
111 | 110 | array_splice($par, $index, 1, $params); |
@@ -113,7 +112,7 @@ discard block |
||
113 | 112 | $new .= implode(',', array_fill(0, count($params), '?')); |
114 | 113 | } |
115 | 114 | } |
116 | - return [ $new, $par ]; |
|
115 | + return [$new, $par]; |
|
117 | 116 | } |
118 | 117 | /** |
119 | 118 | * Run a query (prepare & execute). |
@@ -145,7 +144,7 @@ discard block |
||
145 | 144 | { |
146 | 145 | $coll = Collection::from($this->query($sql, $par)); |
147 | 146 | if (($keys = $this->driver->option('mode')) && in_array($keys, ['strtoupper', 'strtolower'])) { |
148 | - $coll->map(function ($v) use ($keys) { |
|
147 | + $coll->map(function($v) use ($keys) { |
|
149 | 148 | $new = []; |
150 | 149 | foreach ($v as $k => $vv) { |
151 | 150 | $new[call_user_func($keys, $k)] = $vv; |
@@ -154,13 +153,13 @@ discard block |
||
154 | 153 | }); |
155 | 154 | } |
156 | 155 | if ($key !== null) { |
157 | - $coll->mapKey(function ($v) use ($key) { return $v[$key]; }); |
|
156 | + $coll->mapKey(function($v) use ($key) { return $v[$key]; }); |
|
158 | 157 | } |
159 | 158 | if ($skip) { |
160 | - $coll->map(function ($v) use ($key) { unset($v[$key]); return $v; }); |
|
159 | + $coll->map(function($v) use ($key) { unset($v[$key]); return $v; }); |
|
161 | 160 | } |
162 | 161 | if ($opti) { |
163 | - $coll->map(function ($v) { return count($v) === 1 ? current($v) : $v; }); |
|
162 | + $coll->map(function($v) { return count($v) === 1 ? current($v) : $v; }); |
|
164 | 163 | } |
165 | 164 | return $coll; |
166 | 165 | } |
@@ -233,8 +232,7 @@ discard block |
||
233 | 232 | public function definition(string $table, bool $detectRelations = true) : Table |
234 | 233 | { |
235 | 234 | return isset($this->tables[$table]) ? |
236 | - $this->tables[$table] : |
|
237 | - $this->driver->table($table, $detectRelations); |
|
235 | + $this->tables[$table] : $this->driver->table($table, $detectRelations); |
|
238 | 236 | } |
239 | 237 | /** |
240 | 238 | * Parse all tables from the database. |
@@ -251,12 +249,12 @@ discard block |
||
251 | 249 | */ |
252 | 250 | public function getSchema($asPlainArray = true) |
253 | 251 | { |
254 | - return !$asPlainArray ? $this->tables : array_map(function ($table) { |
|
252 | + return !$asPlainArray ? $this->tables : array_map(function($table) { |
|
255 | 253 | return [ |
256 | 254 | 'name' => $table->getName(), |
257 | 255 | 'pkey' => $table->getPrimaryKey(), |
258 | 256 | 'comment' => $table->getComment(), |
259 | - 'columns' => array_map(function ($column) { |
|
257 | + 'columns' => array_map(function($column) { |
|
260 | 258 | return [ |
261 | 259 | 'name' => $column->getName(), |
262 | 260 | 'type' => $column->getType(), |
@@ -266,13 +264,13 @@ discard block |
||
266 | 264 | 'nullable' => $column->isNullable() |
267 | 265 | ]; |
268 | 266 | }, $table->getFullColumns()), |
269 | - 'relations' => array_map(function ($rel) { |
|
267 | + 'relations' => array_map(function($rel) { |
|
270 | 268 | $relation = clone $rel; |
271 | 269 | $relation->table = $relation->table->getName(); |
272 | 270 | if ($relation->pivot) { |
273 | 271 | $relation->pivot = $relation->pivot->getName(); |
274 | 272 | } |
275 | - return (array)$relation; |
|
273 | + return (array) $relation; |
|
276 | 274 | }, $table->getRelations()) |
277 | 275 | ]; |
278 | 276 | }, $this->tables); |
@@ -65,27 +65,27 @@ discard block |
||
65 | 65 | $fields = []; |
66 | 66 | $exists = false; |
67 | 67 | foreach ($relation->table->getColumns() as $column) { |
68 | - $fields[$column] = $row[$name . static::SEP . $column]; |
|
69 | - if (!$exists && $row[$name . static::SEP . $column] !== null) { |
|
68 | + $fields[$column] = $row[$name.static::SEP.$column]; |
|
69 | + if (!$exists && $row[$name.static::SEP.$column] !== null) { |
|
70 | 70 | $exists = true; |
71 | 71 | } |
72 | - $remove[] = $name . static::SEP . $column; |
|
72 | + $remove[] = $name.static::SEP.$column; |
|
73 | 73 | } |
74 | 74 | $temp = &$result; |
75 | 75 | $parts = explode(static::SEP, $name); |
76 | 76 | $name = array_pop($parts); |
77 | 77 | $full = ''; |
78 | 78 | foreach ($parts as $item) { |
79 | - $full = $full ? $full . static::SEP . $item : $item; |
|
79 | + $full = $full ? $full.static::SEP.$item : $item; |
|
80 | 80 | $temp = &$temp[$item]; |
81 | 81 | $rpk = []; |
82 | 82 | foreach ($this->relations[$full][0]->table->getPrimaryKey() as $pkey) { |
83 | - $rpk[$pkey] = $row[$full . static::SEP . $pkey]; |
|
83 | + $rpk[$pkey] = $row[$full.static::SEP.$pkey]; |
|
84 | 84 | } |
85 | 85 | $temp = &$temp[json_encode($rpk)]; |
86 | 86 | } |
87 | 87 | if (!isset($temp[$name])) { |
88 | - $temp[$name] = $relation->many ? [ '___clean' => true ] : null; |
|
88 | + $temp[$name] = $relation->many ? ['___clean' => true] : null; |
|
89 | 89 | } |
90 | 90 | $temp = &$temp[$name]; |
91 | 91 | if ($exists) { |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | return; |
145 | 145 | } |
146 | 146 | } |
147 | - $this->fetched ++; |
|
147 | + $this->fetched++; |
|
148 | 148 | while ($this->result->valid()) { |
149 | 149 | $row = $this->result->current(); |
150 | 150 | $pk = []; |
@@ -124,16 +124,16 @@ discard block |
||
124 | 124 | $columns = Collection::from($this |
125 | 125 | ->query( |
126 | 126 | "SELECT * FROM all_tab_cols WHERE table_name = ? AND owner = ?", |
127 | - [ strtoupper($table), $this->name() ] |
|
127 | + [strtoupper($table), $this->name()] |
|
128 | 128 | )) |
129 | - ->map(function ($v) { |
|
129 | + ->map(function($v) { |
|
130 | 130 | $new = []; |
131 | 131 | foreach ($v as $kk => $vv) { |
132 | 132 | $new[strtoupper($kk)] = $vv; |
133 | 133 | } |
134 | 134 | return $new; |
135 | 135 | }) |
136 | - ->mapKey(function ($v) { return $v['COLUMN_NAME']; }) |
|
136 | + ->mapKey(function($v) { return $v['COLUMN_NAME']; }) |
|
137 | 137 | ->toArray(); |
138 | 138 | if (!count($columns)) { |
139 | 139 | throw new DBException('Table not found by name'); |
@@ -143,9 +143,9 @@ discard block |
||
143 | 143 | ->query( |
144 | 144 | "SELECT constraint_name FROM all_constraints |
145 | 145 | WHERE table_name = ? AND constraint_type = ? AND owner = ?", |
146 | - [ strtoupper($table), 'P', $owner ] |
|
146 | + [strtoupper($table), 'P', $owner] |
|
147 | 147 | )) |
148 | - ->map(function ($v) { |
|
148 | + ->map(function($v) { |
|
149 | 149 | $new = []; |
150 | 150 | foreach ($v as $kk => $vv) { |
151 | 151 | $new[strtoupper($kk)] = $vv; |
@@ -160,9 +160,9 @@ discard block |
||
160 | 160 | ->query( |
161 | 161 | "SELECT column_name FROM all_cons_columns |
162 | 162 | WHERE table_name = ? AND constraint_name = ? AND owner = ?", |
163 | - [ strtoupper($table), $pkname, $owner ] |
|
163 | + [strtoupper($table), $pkname, $owner] |
|
164 | 164 | )) |
165 | - ->map(function ($v) { |
|
165 | + ->map(function($v) { |
|
166 | 166 | $new = []; |
167 | 167 | foreach ($v as $kk => $vv) { |
168 | 168 | $new[strtoupper($kk)] = $vv; |
@@ -189,9 +189,9 @@ discard block |
||
189 | 189 | LEFT JOIN all_cons_columns cc ON cc.OWNER = ac.OWNER AND cc.CONSTRAINT_NAME = ac.CONSTRAINT_NAME |
190 | 190 | WHERE ac.OWNER = ? AND ac.R_OWNER = ? AND ac.R_CONSTRAINT_NAME = ? AND ac.CONSTRAINT_TYPE = ? |
191 | 191 | ORDER BY cc.POSITION", |
192 | - [ $owner, $owner, $pkname, 'R' ] |
|
192 | + [$owner, $owner, $pkname, 'R'] |
|
193 | 193 | )) |
194 | - ->map(function ($v) { |
|
194 | + ->map(function($v) { |
|
195 | 195 | $new = []; |
196 | 196 | foreach ($v as $kk => $vv) { |
197 | 197 | $new[strtoupper($kk)] = $vv; |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | as $relation |
202 | 202 | ) { |
203 | 203 | $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_NAME']; |
204 | - $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int)$relation['POSITION']-1]] = $relation['COLUMN_NAME']; |
|
204 | + $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int) $relation['POSITION'] - 1]] = $relation['COLUMN_NAME']; |
|
205 | 205 | } |
206 | 206 | foreach ($relations as $data) { |
207 | 207 | $rtable = $this->table($data['table'], true); |
@@ -225,9 +225,9 @@ discard block |
||
225 | 225 | ac.OWNER = ? AND ac.R_OWNER = ? AND ac.TABLE_NAME = ? AND ac.CONSTRAINT_TYPE = ? AND |
226 | 226 | cc.COLUMN_NAME IN (??) |
227 | 227 | ORDER BY POSITION", |
228 | - [ $owner, $owner, $data['table'], 'R', $columns ] |
|
228 | + [$owner, $owner, $data['table'], 'R', $columns] |
|
229 | 229 | )) |
230 | - ->map(function ($v) { |
|
230 | + ->map(function($v) { |
|
231 | 231 | $new = []; |
232 | 232 | foreach ($v as $kk => $vv) { |
233 | 233 | $new[strtoupper($kk)] = $vv; |
@@ -245,9 +245,9 @@ discard block |
||
245 | 245 | $rcolumns = Collection::from($this |
246 | 246 | ->query( |
247 | 247 | "SELECT COLUMN_NAME FROM all_cons_columns WHERE OWNER = ? AND CONSTRAINT_NAME = ? ORDER BY POSITION", |
248 | - [ $owner, current($foreign['keymap']) ] |
|
248 | + [$owner, current($foreign['keymap'])] |
|
249 | 249 | )) |
250 | - ->map(function ($v) { |
|
250 | + ->map(function($v) { |
|
251 | 251 | $new = []; |
252 | 252 | foreach ($v as $kk => $vv) { |
253 | 253 | $new[strtoupper($kk)] = $vv; |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | $relname = $foreign['table']; |
263 | 263 | $cntr = 1; |
264 | 264 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
265 | - $relname = $foreign['table'] . '_' . (++ $cntr); |
|
265 | + $relname = $foreign['table'].'_'.(++$cntr); |
|
266 | 266 | } |
267 | 267 | $definition->addRelation( |
268 | 268 | new TableRelation( |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | $relname = $data['table']; |
279 | 279 | $cntr = 1; |
280 | 280 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
281 | - $relname = $data['table'] . '_' . (++ $cntr); |
|
281 | + $relname = $data['table'].'_'.(++$cntr); |
|
282 | 282 | } |
283 | 283 | $definition->addRelation( |
284 | 284 | new TableRelation( |
@@ -302,9 +302,9 @@ discard block |
||
302 | 302 | LEFT JOIN all_cons_columns cc ON cc.OWNER = ac.OWNER AND cc.CONSTRAINT_NAME = ac.CONSTRAINT_NAME |
303 | 303 | WHERE ac.OWNER = ? AND ac.R_OWNER = ? AND ac.TABLE_NAME = ? AND ac.CONSTRAINT_TYPE = ? |
304 | 304 | ORDER BY cc.POSITION", |
305 | - [ $owner, $owner, strtoupper($table), 'R' ] |
|
305 | + [$owner, $owner, strtoupper($table), 'R'] |
|
306 | 306 | )) |
307 | - ->map(function ($v) { |
|
307 | + ->map(function($v) { |
|
308 | 308 | $new = []; |
309 | 309 | foreach ($v as $kk => $vv) { |
310 | 310 | $new[strtoupper($kk)] = $vv; |
@@ -320,9 +320,9 @@ discard block |
||
320 | 320 | $rcolumns = Collection::from($this |
321 | 321 | ->query( |
322 | 322 | "SELECT COLUMN_NAME FROM all_cons_columns WHERE OWNER = ? AND CONSTRAINT_NAME = ? ORDER BY POSITION", |
323 | - [ $owner, current($data['keymap']) ] |
|
323 | + [$owner, current($data['keymap'])] |
|
324 | 324 | )) |
325 | - ->map(function ($v) { |
|
325 | + ->map(function($v) { |
|
326 | 326 | $new = []; |
327 | 327 | foreach ($v as $kk => $vv) { |
328 | 328 | $new[strtoupper($kk)] = $vv; |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | $relname = $data['table']; |
338 | 338 | $cntr = 1; |
339 | 339 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
340 | - $relname = $data['table'] . '_' . (++ $cntr); |
|
340 | + $relname = $data['table'].'_'.(++$cntr); |
|
341 | 341 | } |
342 | 342 | $definition->addRelation( |
343 | 343 | new TableRelation( |
@@ -358,7 +358,7 @@ discard block |
||
358 | 358 | "SELECT TABLE_NAME FROM ALL_TABLES where OWNER = ?", |
359 | 359 | [$this->connection['name']] |
360 | 360 | )) |
361 | - ->map(function ($v) { |
|
361 | + ->map(function($v) { |
|
362 | 362 | $new = []; |
363 | 363 | foreach ($v as $kk => $vv) { |
364 | 364 | $new[strtoupper($kk)] = $vv; |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | return $new; |
367 | 367 | }) |
368 | 368 | ->pluck('TABLE_NAME') |
369 | - ->map(function ($v) { |
|
369 | + ->map(function($v) { |
|
370 | 370 | return $this->table($v); |
371 | 371 | }) |
372 | 372 | ->toArray(); |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | /** |
44 | 44 | * @var int[] |
45 | 45 | */ |
46 | - protected $li_of = [0,0]; |
|
46 | + protected $li_of = [0, 0]; |
|
47 | 47 | /** |
48 | 48 | * @var array |
49 | 49 | */ |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | public function __construct(DBInterface $db, $table) |
70 | 70 | { |
71 | 71 | $this->db = $db; |
72 | - $this->definition = $table instanceof Table ? $table : $this->db->definition((string)$table); |
|
72 | + $this->definition = $table instanceof Table ? $table : $this->db->definition((string) $table); |
|
73 | 73 | $primary = $this->definition->getPrimaryKey(); |
74 | 74 | $columns = $this->definition->getColumns(); |
75 | 75 | $this->pkey = count($primary) ? $primary : $columns; |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | { |
93 | 93 | $column = explode('.', $column); |
94 | 94 | if (count($column) === 1) { |
95 | - $column = [ $this->definition->getName(), $column[0] ]; |
|
95 | + $column = [$this->definition->getName(), $column[0]]; |
|
96 | 96 | $col = $this->definition->getColumn($column[1]); |
97 | 97 | } elseif (count($column) === 2) { |
98 | 98 | if ($column[0] === $this->definition->getName()) { |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | throw new DBException('Invalid column name in related table'); |
113 | 113 | } |
114 | 114 | } else { |
115 | - throw new DBException('Invalid foreign table name: ' . implode(',', $column)); |
|
115 | + throw new DBException('Invalid foreign table name: '.implode(',', $column)); |
|
116 | 116 | } |
117 | 117 | } |
118 | 118 | } else { |
@@ -121,15 +121,15 @@ discard block |
||
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 | - return [ 'name' => implode('.', $column), 'data' => $col ]; |
|
132 | + return ['name' => implode('.', $column), 'data' => $col]; |
|
133 | 133 | } |
134 | 134 | protected function normalizeValue(TableColumn $col, $value) |
135 | 135 | { |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | } |
177 | 177 | return $value; |
178 | 178 | case 'int': |
179 | - return (int)$value; |
|
179 | + return (int) $value; |
|
180 | 180 | default: |
181 | 181 | return $value; |
182 | 182 | } |
@@ -194,18 +194,16 @@ discard block |
||
194 | 194 | list($name, $column) = array_values($this->getColumn($column)); |
195 | 195 | if (is_null($value)) { |
196 | 196 | return $negate ? |
197 | - $this->where($name . ' IS NOT NULL') : |
|
198 | - $this->where($name . ' IS NULL'); |
|
197 | + $this->where($name.' IS NOT NULL') : $this->where($name.' IS NULL'); |
|
199 | 198 | } |
200 | 199 | if (!is_array($value)) { |
201 | 200 | return $negate ? |
202 | 201 | $this->where( |
203 | - $name . ' <> ?', |
|
204 | - [ $this->normalizeValue($column, $value) ] |
|
205 | - ) : |
|
206 | - $this->where( |
|
207 | - $name . ' = ?', |
|
208 | - [ $this->normalizeValue($column, $value) ] |
|
202 | + $name.' <> ?', |
|
203 | + [$this->normalizeValue($column, $value)] |
|
204 | + ) : $this->where( |
|
205 | + $name.' = ?', |
|
206 | + [$this->normalizeValue($column, $value)] |
|
209 | 207 | ); |
210 | 208 | } |
211 | 209 | if (isset($value['beg']) && isset($value['end'])) { |
@@ -216,8 +214,7 @@ discard block |
||
216 | 214 | $this->normalizeValue($column, $value['beg']), |
217 | 215 | $this->normalizeValue($column, $value['end']) |
218 | 216 | ] |
219 | - ) : |
|
220 | - $this->where( |
|
217 | + ) : $this->where( |
|
221 | 218 | $name.' BETWEEN ? AND ?', |
222 | 219 | [ |
223 | 220 | $this->normalizeValue($column, $value['beg']), |
@@ -227,12 +224,12 @@ discard block |
||
227 | 224 | } |
228 | 225 | return $negate ? |
229 | 226 | $this->where( |
230 | - $name . ' NOT IN (??)', |
|
231 | - [ array_map(function ($v) use ($column) { return $this->normalizeValue($column, $v); }, $value) ] |
|
227 | + $name.' NOT IN (??)', |
|
228 | + [array_map(function($v) use ($column) { return $this->normalizeValue($column, $v); }, $value)] |
|
232 | 229 | ) : |
233 | 230 | $this->where( |
234 | - $name . ' IN (??)', |
|
235 | - [ array_map(function ($v) use ($column) { return $this->normalizeValue($column, $v); }, $value) ] |
|
231 | + $name.' IN (??)', |
|
232 | + [array_map(function($v) use ($column) { return $this->normalizeValue($column, $v); }, $value)] |
|
236 | 233 | ); |
237 | 234 | } |
238 | 235 | /** |
@@ -243,7 +240,7 @@ discard block |
||
243 | 240 | */ |
244 | 241 | public function sort(string $column, bool $desc = false) : TableQuery |
245 | 242 | { |
246 | - return $this->order($this->getColumn($column)['name'] . ' ' . ($desc ? 'DESC' : 'ASC')); |
|
243 | + return $this->order($this->getColumn($column)['name'].' '.($desc ? 'DESC' : 'ASC')); |
|
247 | 244 | } |
248 | 245 | /** |
249 | 246 | * Group by a column (or columns) |
@@ -253,7 +250,7 @@ discard block |
||
253 | 250 | public function group($column) : TableQuery |
254 | 251 | { |
255 | 252 | if (!is_array($column)) { |
256 | - $column = [ $column ]; |
|
253 | + $column = [$column]; |
|
257 | 254 | } |
258 | 255 | foreach ($column as $k => $v) { |
259 | 256 | $column[$k] = $this->getColumn($v)['name']; |
@@ -294,7 +291,7 @@ discard block |
||
294 | 291 | $this->withr = []; |
295 | 292 | $this->order = []; |
296 | 293 | $this->having = []; |
297 | - $this->li_of = [0,0]; |
|
294 | + $this->li_of = [0, 0]; |
|
298 | 295 | $this->qiterator = null; |
299 | 296 | return $this; |
300 | 297 | } |
@@ -307,7 +304,7 @@ discard block |
||
307 | 304 | public function groupBy(string $sql, array $params = []) : TableQuery |
308 | 305 | { |
309 | 306 | $this->qiterator = null; |
310 | - $this->group = [ $sql, $params ]; |
|
307 | + $this->group = [$sql, $params]; |
|
311 | 308 | return $this; |
312 | 309 | } |
313 | 310 | /** |
@@ -320,7 +317,7 @@ discard block |
||
320 | 317 | */ |
321 | 318 | public function join($table, array $fields, string $name = null, bool $multiple = true) |
322 | 319 | { |
323 | - $table = $table instanceof Table ? $table : $this->db->definition((string)$table); |
|
320 | + $table = $table instanceof Table ? $table : $this->db->definition((string) $table); |
|
324 | 321 | $name = $name ?? $table->getName(); |
325 | 322 | if (isset($this->joins[$name]) || $this->definition->hasRelation($name)) { |
326 | 323 | throw new DBException('Alias / table name already in use'); |
@@ -329,7 +326,7 @@ discard block |
||
329 | 326 | foreach ($fields as $k => $v) { |
330 | 327 | $k = explode('.', $k, 2); |
331 | 328 | $k = count($k) == 2 ? $k[1] : $k[0]; |
332 | - $this->joins[$name]->keymap[$this->getColumn($name . '.' . $k)['name']] = $this->getColumn($v)['name']; |
|
329 | + $this->joins[$name]->keymap[$this->getColumn($name.'.'.$k)['name']] = $this->getColumn($v)['name']; |
|
333 | 330 | } |
334 | 331 | return $this; |
335 | 332 | } |
@@ -342,7 +339,7 @@ discard block |
||
342 | 339 | public function where(string $sql, array $params = []) : TableQuery |
343 | 340 | { |
344 | 341 | $this->qiterator = null; |
345 | - $this->where[] = [ $sql, $params ]; |
|
342 | + $this->where[] = [$sql, $params]; |
|
346 | 343 | return $this; |
347 | 344 | } |
348 | 345 | /** |
@@ -354,7 +351,7 @@ discard block |
||
354 | 351 | public function having(string $sql, array $params = []) : TableQuery |
355 | 352 | { |
356 | 353 | $this->qiterator = null; |
357 | - $this->having[] = [ $sql, $params ]; |
|
354 | + $this->having[] = [$sql, $params]; |
|
358 | 355 | return $this; |
359 | 356 | } |
360 | 357 | /** |
@@ -366,7 +363,7 @@ discard block |
||
366 | 363 | public function order(string $sql, array $params = []) : TableQuery |
367 | 364 | { |
368 | 365 | $this->qiterator = null; |
369 | - $this->order = [ $sql, $params ]; |
|
366 | + $this->order = [$sql, $params]; |
|
370 | 367 | return $this; |
371 | 368 | } |
372 | 369 | /** |
@@ -378,7 +375,7 @@ discard block |
||
378 | 375 | public function limit(int $limit, int $offset = 0) : TableQuery |
379 | 376 | { |
380 | 377 | $this->qiterator = null; |
381 | - $this->li_of = [ $limit, $offset ]; |
|
378 | + $this->li_of = [$limit, $offset]; |
|
382 | 379 | return $this; |
383 | 380 | } |
384 | 381 | /** |
@@ -394,22 +391,22 @@ discard block |
||
394 | 391 | $relations = $this->withr; |
395 | 392 | foreach ($this->definition->getRelations() as $k => $v) { |
396 | 393 | foreach ($this->where as $vv) { |
397 | - if (strpos($vv[0], $k . '.') !== false) { |
|
398 | - $relations[$k] = [ $v, $table ]; |
|
394 | + if (strpos($vv[0], $k.'.') !== false) { |
|
395 | + $relations[$k] = [$v, $table]; |
|
399 | 396 | } |
400 | 397 | } |
401 | - if (isset($this->order[0]) && strpos($this->order[0], $k . '.') !== false) { |
|
402 | - $relations[$k] = [ $v, $table ]; |
|
398 | + if (isset($this->order[0]) && strpos($this->order[0], $k.'.') !== false) { |
|
399 | + $relations[$k] = [$v, $table]; |
|
403 | 400 | } |
404 | 401 | } |
405 | 402 | |
406 | 403 | foreach ($this->joins as $k => $v) { |
407 | - $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON '; |
|
404 | + $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON '; |
|
408 | 405 | $tmp = []; |
409 | 406 | foreach ($v->keymap as $kk => $vv) { |
410 | 407 | $tmp[] = $kk.' = '.$vv; |
411 | 408 | } |
412 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
409 | + $sql .= implode(' AND ', $tmp).' '; |
|
413 | 410 | } |
414 | 411 | foreach ($relations as $k => $v) { |
415 | 412 | $table = $v[1]; |
@@ -420,13 +417,13 @@ discard block |
||
420 | 417 | foreach ($v->keymap as $kk => $vv) { |
421 | 418 | $tmp[] = $table.'.'.$kk.' = '.$k.'_pivot.'.$vv.' '; |
422 | 419 | } |
423 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
420 | + $sql .= implode(' AND ', $tmp).' '; |
|
424 | 421 | $sql .= 'LEFT JOIN '.$v->table->getName().' '.$k.' ON '; |
425 | 422 | $tmp = []; |
426 | 423 | foreach ($v->pivot_keymap as $kk => $vv) { |
427 | 424 | $tmp[] = $k.'.'.$vv.' = '.$k.'_pivot.'.$kk.' '; |
428 | 425 | } |
429 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
426 | + $sql .= implode(' AND ', $tmp).' '; |
|
430 | 427 | } else { |
431 | 428 | $sql .= 'LEFT JOIN '.$v->table->getName().' '.$k.' ON '; |
432 | 429 | $tmp = []; |
@@ -434,30 +431,30 @@ discard block |
||
434 | 431 | $tmp[] = $table.'.'.$kk.' = '.$k.'.'.$vv.' '; |
435 | 432 | } |
436 | 433 | if ($v->sql) { |
437 | - $tmp[] = $v->sql . ' '; |
|
434 | + $tmp[] = $v->sql.' '; |
|
438 | 435 | $par = array_merge($par, $v->par ?? []); |
439 | 436 | } |
440 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
437 | + $sql .= implode(' AND ', $tmp).' '; |
|
441 | 438 | } |
442 | 439 | } |
443 | 440 | if (count($this->where)) { |
444 | 441 | $sql .= 'WHERE '; |
445 | 442 | $tmp = []; |
446 | 443 | foreach ($this->where as $v) { |
447 | - $tmp[] = '(' . $v[0] . ')'; |
|
444 | + $tmp[] = '('.$v[0].')'; |
|
448 | 445 | $par = array_merge($par, $v[1]); |
449 | 446 | } |
450 | 447 | $sql .= implode(' AND ', $tmp).' '; |
451 | 448 | } |
452 | 449 | if (count($this->group)) { |
453 | - $sql .= 'GROUP BY ' . $this->group[0] . ' '; |
|
450 | + $sql .= 'GROUP BY '.$this->group[0].' '; |
|
454 | 451 | $par = array_merge($par, $this->group[1]); |
455 | 452 | } |
456 | 453 | if (count($this->having)) { |
457 | 454 | $sql .= 'HAVING '; |
458 | 455 | $tmp = []; |
459 | 456 | foreach ($this->having as $v) { |
460 | - $tmp[] = '(' . $v[0] . ')'; |
|
457 | + $tmp[] = '('.$v[0].')'; |
|
461 | 458 | $par = array_merge($par, $v[1]); |
462 | 459 | } |
463 | 460 | $sql .= implode(' AND ', $tmp).' '; |
@@ -491,7 +488,7 @@ discard block |
||
491 | 488 | $this->with(implode('.', $temp)); |
492 | 489 | $table = array_reduce( |
493 | 490 | $temp, |
494 | - function ($carry, $item) use (&$table) { |
|
491 | + function($carry, $item) use (&$table) { |
|
495 | 492 | return $table->getRelation($item)->table; |
496 | 493 | } |
497 | 494 | ); |
@@ -500,7 +497,7 @@ discard block |
||
500 | 497 | } |
501 | 498 | unset($fields[$k]); |
502 | 499 | foreach ($cols as $col) { |
503 | - $fields[] = $table . '.' . $col; |
|
500 | + $fields[] = $table.'.'.$col; |
|
504 | 501 | } |
505 | 502 | } |
506 | 503 | } |
@@ -538,37 +535,37 @@ discard block |
||
538 | 535 | $relations = $this->withr; |
539 | 536 | foreach ($this->definition->getRelations() as $k => $relation) { |
540 | 537 | foreach ($this->fields as $field) { |
541 | - if (strpos($field, $k . '.') === 0) { |
|
542 | - $relations[$k] = [ $relation, $table ]; |
|
538 | + if (strpos($field, $k.'.') === 0) { |
|
539 | + $relations[$k] = [$relation, $table]; |
|
543 | 540 | } |
544 | 541 | } |
545 | 542 | foreach ($this->where as $v) { |
546 | - if (strpos($v[0], $k . '.') !== false) { |
|
547 | - $relations[$k] = [ $relation, $table ]; |
|
543 | + if (strpos($v[0], $k.'.') !== false) { |
|
544 | + $relations[$k] = [$relation, $table]; |
|
548 | 545 | } |
549 | 546 | } |
550 | - if (isset($this->order[0]) && strpos($this->order[0], $k . '.') !== false) { |
|
551 | - $relations[$k] = [ $relation, $table ]; |
|
547 | + if (isset($this->order[0]) && strpos($this->order[0], $k.'.') !== false) { |
|
548 | + $relations[$k] = [$relation, $table]; |
|
552 | 549 | } |
553 | 550 | } |
554 | 551 | $select = []; |
555 | 552 | foreach ($this->fields as $k => $field) { |
556 | - $select[] = $field . (!is_numeric($k) ? ' ' . $k : ''); |
|
553 | + $select[] = $field.(!is_numeric($k) ? ' '.$k : ''); |
|
557 | 554 | } |
558 | 555 | foreach ($this->withr as $name => $relation) { |
559 | 556 | foreach ($relation[0]->table->getColumns() as $column) { |
560 | - $select[] = $name . '.' . $column . ' ' . $name . static::SEP . $column; |
|
557 | + $select[] = $name.'.'.$column.' '.$name.static::SEP.$column; |
|
561 | 558 | } |
562 | 559 | } |
563 | 560 | $sql = 'SELECT '.implode(', ', $select).' FROM '.$table.' '; |
564 | 561 | $par = []; |
565 | 562 | foreach ($this->joins as $k => $v) { |
566 | - $sql .= ($v->many ? 'LEFT ' : '' ) . 'JOIN '.$v->table->getName().' '.$k.' ON '; |
|
563 | + $sql .= ($v->many ? 'LEFT ' : '').'JOIN '.$v->table->getName().' '.$k.' ON '; |
|
567 | 564 | $tmp = []; |
568 | 565 | foreach ($v->keymap as $kk => $vv) { |
569 | 566 | $tmp[] = $kk.' = '.$vv; |
570 | 567 | } |
571 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
568 | + $sql .= implode(' AND ', $tmp).' '; |
|
572 | 569 | } |
573 | 570 | foreach ($relations as $relation => $v) { |
574 | 571 | $table = $v[1]; |
@@ -579,13 +576,13 @@ discard block |
||
579 | 576 | foreach ($v->keymap as $kk => $vv) { |
580 | 577 | $tmp[] = $table.'.'.$kk.' = '.$relation.'_pivot.'.$vv.' '; |
581 | 578 | } |
582 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
579 | + $sql .= implode(' AND ', $tmp).' '; |
|
583 | 580 | $sql .= 'LEFT JOIN '.$v->table->getName().' '.$relation.' ON '; |
584 | 581 | $tmp = []; |
585 | 582 | foreach ($v->pivot_keymap as $kk => $vv) { |
586 | 583 | $tmp[] = $relation.'.'.$vv.' = '.$relation.'_pivot.'.$kk.' '; |
587 | 584 | } |
588 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
585 | + $sql .= implode(' AND ', $tmp).' '; |
|
589 | 586 | } else { |
590 | 587 | $sql .= 'LEFT JOIN '.$v->table->getName().' '.$relation.' ON '; |
591 | 588 | $tmp = []; |
@@ -593,36 +590,36 @@ discard block |
||
593 | 590 | $tmp[] = $table.'.'.$kk.' = '.$relation.'.'.$vv.' '; |
594 | 591 | } |
595 | 592 | if ($v->sql) { |
596 | - $tmp[] = $v->sql . ' '; |
|
593 | + $tmp[] = $v->sql.' '; |
|
597 | 594 | $par = array_merge($par, $v->par ?? []); |
598 | 595 | } |
599 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
596 | + $sql .= implode(' AND ', $tmp).' '; |
|
600 | 597 | } |
601 | 598 | } |
602 | 599 | if (count($this->where)) { |
603 | 600 | $sql .= 'WHERE '; |
604 | 601 | $tmp = []; |
605 | 602 | foreach ($this->where as $v) { |
606 | - $tmp[] = '(' . $v[0] . ')'; |
|
603 | + $tmp[] = '('.$v[0].')'; |
|
607 | 604 | $par = array_merge($par, $v[1]); |
608 | 605 | } |
609 | 606 | $sql .= implode(' AND ', $tmp).' '; |
610 | 607 | } |
611 | 608 | if (count($this->group)) { |
612 | - $sql .= 'GROUP BY ' . $this->group[0] . ' '; |
|
609 | + $sql .= 'GROUP BY '.$this->group[0].' '; |
|
613 | 610 | $par = array_merge($par, $this->group[1]); |
614 | 611 | } |
615 | 612 | if (count($this->having)) { |
616 | 613 | $sql .= 'HAVING '; |
617 | 614 | $tmp = []; |
618 | 615 | foreach ($this->having as $v) { |
619 | - $tmp[] = '(' . $v[0] . ')'; |
|
616 | + $tmp[] = '('.$v[0].')'; |
|
620 | 617 | $par = array_merge($par, $v[1]); |
621 | 618 | } |
622 | 619 | $sql .= implode(' AND ', $tmp).' '; |
623 | 620 | } |
624 | 621 | if (count($this->order)) { |
625 | - $sql .= 'ORDER BY ' . $this->order[0] . ' '; |
|
622 | + $sql .= 'ORDER BY '.$this->order[0].' '; |
|
626 | 623 | $par = array_merge($par, $this->order[1]); |
627 | 624 | } |
628 | 625 | $porder = []; |
@@ -630,30 +627,30 @@ discard block |
||
630 | 627 | $porder[] = $this->getColumn($field)['name']; |
631 | 628 | } |
632 | 629 | if (count($porder)) { |
633 | - $sql .= (count($this->order) ? ', ' : 'ORDER BY ') . implode(', ', $porder) . ' '; |
|
630 | + $sql .= (count($this->order) ? ', ' : 'ORDER BY ').implode(', ', $porder).' '; |
|
634 | 631 | } |
635 | 632 | |
636 | 633 | if ($this->li_of[0]) { |
637 | 634 | if ($this->db->driverName() === 'oracle') { |
638 | - if ((int)$this->db->driverOption('version', 0) >= 12) { |
|
639 | - $sql .= 'OFFSET ' . $this->li_of[1] . ' ROWS FETCH NEXT ' . $this->li_of[0] . ' ROWS ONLY'; |
|
635 | + if ((int) $this->db->driverOption('version', 0) >= 12) { |
|
636 | + $sql .= 'OFFSET '.$this->li_of[1].' ROWS FETCH NEXT '.$this->li_of[0].' ROWS ONLY'; |
|
640 | 637 | } else { |
641 | - $f = array_map(function ($v) { |
|
638 | + $f = array_map(function($v) { |
|
642 | 639 | $v = explode(' ', trim($v), 2); |
643 | 640 | if (count($v) === 2) { return $v[1]; } |
644 | 641 | $v = explode('.', $v[0], 2); |
645 | 642 | return count($v) === 2 ? $v[1] : $v[0]; |
646 | 643 | }, $select); |
647 | - $sql = "SELECT " . implode(', ', $f) . " |
|
644 | + $sql = "SELECT ".implode(', ', $f)." |
|
648 | 645 | FROM ( |
649 | 646 | SELECT tbl__.*, rownum rnum__ FROM ( |
650 | - " . $sql . " |
|
647 | + " . $sql." |
|
651 | 648 | ) tbl__ |
652 | - WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1]) . " |
|
649 | + WHERE rownum <= " . ($this->li_of[0] + $this->li_of[1])." |
|
653 | 650 | ) WHERE rnum__ > " . $this->li_of[1]; |
654 | 651 | } |
655 | 652 | } else { |
656 | - $sql .= 'LIMIT ' . $this->li_of[0] . ' OFFSET ' . $this->li_of[1]; |
|
653 | + $sql .= 'LIMIT '.$this->li_of[0].' OFFSET '.$this->li_of[1]; |
|
657 | 654 | } |
658 | 655 | } |
659 | 656 | return $this->qiterator = new TableQueryIterator( |
@@ -702,7 +699,7 @@ discard block |
||
702 | 699 | $ret[$k] = str_repeat(' ', 255); |
703 | 700 | $par[] = &$ret[$k]; |
704 | 701 | } |
705 | - $sql .= ' RETURNING ' . implode(',', $primary) . ' INTO ' . implode(',', array_fill(0, count($primary), '?')); |
|
702 | + $sql .= ' RETURNING '.implode(',', $primary).' INTO '.implode(',', array_fill(0, count($primary), '?')); |
|
706 | 703 | $this->db->query($sql, $par); |
707 | 704 | return $ret; |
708 | 705 | } else { |
@@ -734,7 +731,7 @@ discard block |
||
734 | 731 | } |
735 | 732 | $sql = 'UPDATE '.$table.' SET '; |
736 | 733 | $par = []; |
737 | - $sql .= implode(', ', array_map(function ($v) { return $v . ' = ?'; }, array_keys($update))) . ' '; |
|
734 | + $sql .= implode(', ', array_map(function($v) { return $v.' = ?'; }, array_keys($update))).' '; |
|
738 | 735 | $par = array_merge($par, array_values($update)); |
739 | 736 | if (count($this->where)) { |
740 | 737 | $sql .= 'WHERE '; |
@@ -743,7 +740,7 @@ discard block |
||
743 | 740 | $tmp[] = $v[0]; |
744 | 741 | $par = array_merge($par, $v[1]); |
745 | 742 | } |
746 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
743 | + $sql .= implode(' AND ', $tmp).' '; |
|
747 | 744 | } |
748 | 745 | if (count($this->order)) { |
749 | 746 | $sql .= $this->order[0]; |
@@ -767,7 +764,7 @@ discard block |
||
767 | 764 | $tmp[] = $v[0]; |
768 | 765 | $par = array_merge($par, $v[1]); |
769 | 766 | } |
770 | - $sql .= implode(' AND ', $tmp) . ' '; |
|
767 | + $sql .= implode(' AND ', $tmp).' '; |
|
771 | 768 | } |
772 | 769 | if (count($this->order)) { |
773 | 770 | $sql .= $this->order[0]; |
@@ -787,13 +784,13 @@ discard block |
||
787 | 784 | $table = $this->definition; |
788 | 785 | array_reduce( |
789 | 786 | $parts, |
790 | - function ($carry, $item) use (&$table) { |
|
787 | + function($carry, $item) use (&$table) { |
|
791 | 788 | $relation = $table->getRelation($item); |
792 | 789 | if (!$relation) { |
793 | 790 | throw new DBException('Invalid relation name'); |
794 | 791 | } |
795 | - $name = $carry ? $carry . static::SEP . $item : $item; |
|
796 | - $this->withr[$name] = [ $relation, $carry ?? $table->getName() ]; |
|
792 | + $name = $carry ? $carry.static::SEP.$item : $item; |
|
793 | + $this->withr[$name] = [$relation, $carry ?? $table->getName()]; |
|
797 | 794 | $table = $relation->table; |
798 | 795 | return $name; |
799 | 796 | } |