@@ -136,93 +136,93 @@ discard block |
||
| 136 | 136 | // Columns Statement |
| 137 | 137 | $columnStatements = []; |
| 138 | 138 | foreach ($columns as $columnName => $columnAttributes) { |
| 139 | - if (isset($columnAttributes[ 'type' ])) { |
|
| 140 | - if (isset($columnAttributes[ 'foreign_key' ])) { |
|
| 141 | - $foreignKeys[ $columnName ] = $columnAttributes[ 'foreign_key' ]; |
|
| 139 | + if (isset($columnAttributes['type'])) { |
|
| 140 | + if (isset($columnAttributes['foreign_key'])) { |
|
| 141 | + $foreignKeys[$columnName] = $columnAttributes['foreign_key']; |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | $columnStatementLine = []; |
| 145 | 145 | $columnName = $this->conn->escapeIdentifiers($columnName); |
| 146 | - $columnAttributes[ 'type' ] = strtoupper($columnAttributes[ 'type' ]); |
|
| 146 | + $columnAttributes['type'] = strtoupper($columnAttributes['type']); |
|
| 147 | 147 | |
| 148 | - if (isset($columnAttributes[ 'primary_key' ])) { |
|
| 149 | - if ($columnAttributes[ 'primary_key' ] === true) { |
|
| 148 | + if (isset($columnAttributes['primary_key'])) { |
|
| 149 | + if ($columnAttributes['primary_key'] === true) { |
|
| 150 | 150 | $primaryKeys[] = $columnName; |
| 151 | 151 | } |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - if (isset($columnAttributes[ 'unique' ])) { |
|
| 155 | - if ($columnAttributes[ 'unique' ] === true) { |
|
| 154 | + if (isset($columnAttributes['unique'])) { |
|
| 155 | + if ($columnAttributes['unique'] === true) { |
|
| 156 | 156 | $uniqueKeys[] = $columnName; |
| 157 | 157 | } |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - if ($columnAttributes[ 'type' ] === 'ENUM') { |
|
| 161 | - if (empty($columnAttributes[ 'value' ])) { |
|
| 160 | + if ($columnAttributes['type'] === 'ENUM') { |
|
| 161 | + if (empty($columnAttributes['value'])) { |
|
| 162 | 162 | continue; |
| 163 | 163 | } else { |
| 164 | - if (is_string($columnAttributes[ 'value' ])) { |
|
| 165 | - $columnAttributes[ 'value' ] = explode(',', $columnAttributes[ 'value' ]); |
|
| 164 | + if (is_string($columnAttributes['value'])) { |
|
| 165 | + $columnAttributes['value'] = explode(',', $columnAttributes['value']); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - $columnAttributes[ 'value' ] = array_map(function ($value) { |
|
| 168 | + $columnAttributes['value'] = array_map(function($value) { |
|
| 169 | 169 | return $this->conn->escape(str_replace('\'', '', trim($value))); |
| 170 | - }, $columnAttributes[ 'value' ]); |
|
| 170 | + }, $columnAttributes['value']); |
|
| 171 | 171 | |
| 172 | 172 | $columnStatementLine[] = $columnName . |
| 173 | - ' ' . $columnAttributes[ 'type' ] . '(' . |
|
| 174 | - implode(',', $columnAttributes[ 'value' ]) |
|
| 173 | + ' ' . $columnAttributes['type'] . '(' . |
|
| 174 | + implode(',', $columnAttributes['value']) |
|
| 175 | 175 | . ')'; |
| 176 | 176 | } |
| 177 | - } elseif (isset($columnAttributes[ 'length' ])) { |
|
| 178 | - $columnStatementLine[] = $columnName . ' ' . $columnAttributes[ 'type' ] . '(' . $columnAttributes[ 'length' ] . ')'; |
|
| 177 | + } elseif (isset($columnAttributes['length'])) { |
|
| 178 | + $columnStatementLine[] = $columnName . ' ' . $columnAttributes['type'] . '(' . $columnAttributes['length'] . ')'; |
|
| 179 | 179 | } else { |
| 180 | - $columnStatementLine[] = $columnName . ' ' . $columnAttributes[ 'type' ]; |
|
| 180 | + $columnStatementLine[] = $columnName . ' ' . $columnAttributes['type']; |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | - if (isset($columnAttributes[ 'unsigned' ])) { |
|
| 184 | - if ($columnAttributes[ 'unsigned' ] === true) { |
|
| 185 | - if (in_array($columnAttributes[ 'type' ], $this->unsignedSupportColumnTypes)) { |
|
| 183 | + if (isset($columnAttributes['unsigned'])) { |
|
| 184 | + if ($columnAttributes['unsigned'] === true) { |
|
| 185 | + if (in_array($columnAttributes['type'], $this->unsignedSupportColumnTypes)) { |
|
| 186 | 186 | $columnStatementLine[] = 'UNSIGNED'; |
| 187 | 187 | } |
| 188 | 188 | } |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - if (isset($columnAttributes[ 'collate' ])) { |
|
| 192 | - $columnStatementLine[] = 'COLLATE ' . $columnAttributes[ 'collate' ]; |
|
| 193 | - } elseif (in_array($columnAttributes[ 'type' ], |
|
| 191 | + if (isset($columnAttributes['collate'])) { |
|
| 192 | + $columnStatementLine[] = 'COLLATE ' . $columnAttributes['collate']; |
|
| 193 | + } elseif (in_array($columnAttributes['type'], |
|
| 194 | 194 | ['CHAR', 'VARCHAR', 'TEXT', 'LONGTEXT', 'TINYTEXT', 'ENUM'])) { |
| 195 | 195 | $columnStatementLine[] = 'COLLATE ' . $this->conn->getConfig('collate'); |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | - if (isset($columnAttributes[ 'not_null' ])) { |
|
| 199 | - if ($columnAttributes[ 'not_null' ] === true) { |
|
| 198 | + if (isset($columnAttributes['not_null'])) { |
|
| 199 | + if ($columnAttributes['not_null'] === true) { |
|
| 200 | 200 | $columnStatementLine[] = 'NOT NULL'; |
| 201 | 201 | } |
| 202 | - } elseif (isset($columnAttributes[ 'null' ])) { |
|
| 203 | - if ($columnAttributes[ 'null' ] === false) { |
|
| 202 | + } elseif (isset($columnAttributes['null'])) { |
|
| 203 | + if ($columnAttributes['null'] === false) { |
|
| 204 | 204 | $columnStatementLine[] = 'NOT NULL'; |
| 205 | 205 | } |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | - if (isset($columnAttributes[ 'timestamp' ])) { |
|
| 209 | - if ($columnAttributes[ 'timestamp' ] === true) { |
|
| 208 | + if (isset($columnAttributes['timestamp'])) { |
|
| 209 | + if ($columnAttributes['timestamp'] === true) { |
|
| 210 | 210 | $columnStatementLine[] = 'ON UPDATE CURRENT_TIMESTAMP'; |
| 211 | 211 | } |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - if (isset($columnAttributes[ 'default' ])) { |
|
| 215 | - $columnStatementLine[] = 'DEFAULT ' . $this->conn->escape($columnAttributes[ 'default' ]); |
|
| 214 | + if (isset($columnAttributes['default'])) { |
|
| 215 | + $columnStatementLine[] = 'DEFAULT ' . $this->conn->escape($columnAttributes['default']); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | - if (isset($columnAttributes[ 'auto_increment' ])) { |
|
| 219 | - if ($columnAttributes[ 'auto_increment' ] === true) { |
|
| 218 | + if (isset($columnAttributes['auto_increment'])) { |
|
| 219 | + if ($columnAttributes['auto_increment'] === true) { |
|
| 220 | 220 | $columnStatementLine[] = 'AUTO_INCREMENT'; |
| 221 | 221 | } |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - if (isset($columnAttributes[ 'comment' ])) { |
|
| 225 | - $columnStatementLine[] = 'COMMENT ' . $columnAttributes[ 'comment' ]; |
|
| 224 | + if (isset($columnAttributes['comment'])) { |
|
| 225 | + $columnStatementLine[] = 'COMMENT ' . $columnAttributes['comment']; |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | $columnStatements[] = "\t" . implode(' ', $columnStatementLine); |
@@ -252,16 +252,16 @@ discard block |
||
| 252 | 252 | // Foreign Keys Statement |
| 253 | 253 | if (count($foreignKeys)) { |
| 254 | 254 | foreach ($foreignKeys as $foreignKeyColumnName => $foreignKeyAttributes) { |
| 255 | - if (empty($foreignKeyAttributes[ 'name' ])) { |
|
| 256 | - $foreignKeyAttributes[ 'name' ] = 'fk_' . $foreignKeyColumnName; |
|
| 255 | + if (empty($foreignKeyAttributes['name'])) { |
|
| 256 | + $foreignKeyAttributes['name'] = 'fk_' . $foreignKeyColumnName; |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - if (isset($foreignKeyAttributes[ 'references' ])) { |
|
| 259 | + if (isset($foreignKeyAttributes['references'])) { |
|
| 260 | 260 | $keyStatements[] = 'KEY ' . |
| 261 | - $this->conn->escapeIdentifiers($foreignKeyAttributes[ 'name' ]) . |
|
| 261 | + $this->conn->escapeIdentifiers($foreignKeyAttributes['name']) . |
|
| 262 | 262 | ' (' . $this->conn->escapeIdentifiers($foreignKeyColumnName) . ')'; |
| 263 | 263 | |
| 264 | - $referenceParts = array_map('trim', explode('.', $foreignKeyAttributes[ 'references' ])); |
|
| 264 | + $referenceParts = array_map('trim', explode('.', $foreignKeyAttributes['references'])); |
|
| 265 | 265 | list($referenceTable, $referenceColumn) = $referenceParts; |
| 266 | 266 | |
| 267 | 267 | $referenceOnDelete = 'NO ACTION'; |
@@ -274,20 +274,20 @@ discard block |
||
| 274 | 274 | 'SET NULL', |
| 275 | 275 | ]; |
| 276 | 276 | |
| 277 | - if (isset($foreignKeyAttributes[ 'on_delete' ])) { |
|
| 278 | - if (in_array($foreignKeyAttributes[ 'on_delete' ], $validReferenceActions)) { |
|
| 279 | - $referenceOnDelete = $foreignKeyAttributes[ 'on_delete' ]; |
|
| 277 | + if (isset($foreignKeyAttributes['on_delete'])) { |
|
| 278 | + if (in_array($foreignKeyAttributes['on_delete'], $validReferenceActions)) { |
|
| 279 | + $referenceOnDelete = $foreignKeyAttributes['on_delete']; |
|
| 280 | 280 | } |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - if (isset($foreignKeyAttributes[ 'on_update' ])) { |
|
| 284 | - if (in_array($foreignKeyAttributes[ 'on_update' ], $validReferenceActions)) { |
|
| 285 | - $referenceOnUpdate = $foreignKeyAttributes[ 'on_update' ]; |
|
| 283 | + if (isset($foreignKeyAttributes['on_update'])) { |
|
| 284 | + if (in_array($foreignKeyAttributes['on_update'], $validReferenceActions)) { |
|
| 285 | + $referenceOnUpdate = $foreignKeyAttributes['on_update']; |
|
| 286 | 286 | } |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | $constraintStatements[] = 'CONSTRAINT ' . |
| 290 | - $this->conn->escapeIdentifiers($foreignKeyAttributes[ 'name' ]) . |
|
| 290 | + $this->conn->escapeIdentifiers($foreignKeyAttributes['name']) . |
|
| 291 | 291 | ' FOREIGN KEY (' . $this->conn->escapeIdentifiers($foreignKeyColumnName) . ') REFERENCES ' . |
| 292 | 292 | $this->conn->escapeIdentifiers($referenceTable) . ' (' . $this->conn->escapeIdentifiers($referenceColumn) . |
| 293 | 293 | ') ON DELETE ' . $referenceOnDelete . ' ON UPDATE ' . $referenceOnUpdate; |
@@ -299,25 +299,25 @@ discard block |
||
| 299 | 299 | array_merge($columnStatements, $keyStatements, $constraintStatements)); |
| 300 | 300 | |
| 301 | 301 | if (empty($attributes)) { |
| 302 | - $attributes[ 'engine' ] = 'InnoDB'; |
|
| 302 | + $attributes['engine'] = 'InnoDB'; |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | - if( ! array_key_exists('charset', $attributes) ) { |
|
| 306 | - $attributes[ 'charset' ] = $this->conn->getConfig('charset'); |
|
| 305 | + if ( ! array_key_exists('charset', $attributes)) { |
|
| 306 | + $attributes['charset'] = $this->conn->getConfig('charset'); |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | - if( ! array_key_exists('collate', $attributes) ) { |
|
| 310 | - $attributes[ 'collate' ] = $this->conn->getConfig('collate'); |
|
| 309 | + if ( ! array_key_exists('collate', $attributes)) { |
|
| 310 | + $attributes['collate'] = $this->conn->getConfig('collate'); |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | $attributeStatements = []; |
| 314 | 314 | foreach ($attributes as $key => $value) { |
| 315 | - if(is_string($key)) { |
|
| 315 | + if (is_string($key)) { |
|
| 316 | 316 | $key = strtoupper(dash($key)); |
| 317 | 317 | |
| 318 | 318 | if ($key === 'CHARSET') { |
| 319 | - $attributeStatements[] = 'DEFAULT CHARSET=' . $value; |
|
| 320 | - } elseif(in_array($key, $this->quotedTableOptions)) { |
|
| 319 | + $attributeStatements[] = 'DEFAULT CHARSET=' . $value; |
|
| 320 | + } elseif (in_array($key, $this->quotedTableOptions)) { |
|
| 321 | 321 | $attributeStatements[] = $this->conn->escape($key) . '=' . $value; |
| 322 | 322 | } else { |
| 323 | 323 | $attributeStatements[] = $this->conn->escapeString($key) . '=' . $value; |
@@ -377,63 +377,63 @@ discard block |
||
| 377 | 377 | $alterTableStatementStrings[] = strtoupper($action); |
| 378 | 378 | $alterTableStatementStrings[] = $this->conn->escapeIdentifiers($column); |
| 379 | 379 | |
| 380 | - if (isset($attributes[ 'type' ])) { |
|
| 381 | - if ($attributes[ 'type' ] === 'ENUM') { |
|
| 382 | - if (empty($attributes[ 'value' ])) { |
|
| 380 | + if (isset($attributes['type'])) { |
|
| 381 | + if ($attributes['type'] === 'ENUM') { |
|
| 382 | + if (empty($attributes['value'])) { |
|
| 383 | 383 | return false; |
| 384 | 384 | } else { |
| 385 | - if (is_string($attributes[ 'value' ])) { |
|
| 386 | - $attributes[ 'value' ] = explode(',', $attributes[ 'value' ]); |
|
| 385 | + if (is_string($attributes['value'])) { |
|
| 386 | + $attributes['value'] = explode(',', $attributes['value']); |
|
| 387 | 387 | } |
| 388 | 388 | |
| 389 | - $attributes[ 'value' ] = array_map(function ($value) { |
|
| 389 | + $attributes['value'] = array_map(function($value) { |
|
| 390 | 390 | return $this->conn->escape(str_replace('\'', '', trim($value))); |
| 391 | - }, $attributes[ 'value' ]); |
|
| 391 | + }, $attributes['value']); |
|
| 392 | 392 | |
| 393 | - $alterTableStatementStrings[] = $attributes[ 'type' ] . '(' . |
|
| 394 | - implode(',', $attributes[ 'value' ]) |
|
| 393 | + $alterTableStatementStrings[] = $attributes['type'] . '(' . |
|
| 394 | + implode(',', $attributes['value']) |
|
| 395 | 395 | . ')'; |
| 396 | 396 | } |
| 397 | - } elseif (isset($attributes[ 'length' ])) { |
|
| 398 | - $alterTableStatementStrings[] = $attributes[ 'type' ] . '(' . $attributes[ 'length' ] . ')'; |
|
| 397 | + } elseif (isset($attributes['length'])) { |
|
| 398 | + $alterTableStatementStrings[] = $attributes['type'] . '(' . $attributes['length'] . ')'; |
|
| 399 | 399 | } else { |
| 400 | - $alterTableStatementStrings[] = $attributes[ 'type' ]; |
|
| 400 | + $alterTableStatementStrings[] = $attributes['type']; |
|
| 401 | 401 | } |
| 402 | 402 | |
| 403 | - if (isset($attributes[ 'unsigned' ])) { |
|
| 404 | - if ($attributes[ 'unsigned' ] === true) { |
|
| 405 | - if (in_array($attributes[ 'type' ], |
|
| 403 | + if (isset($attributes['unsigned'])) { |
|
| 404 | + if ($attributes['unsigned'] === true) { |
|
| 405 | + if (in_array($attributes['type'], |
|
| 406 | 406 | ['INT', 'BIGINT', 'SMALLINT', 'TINYINT', 'FLOAT', 'DECIMAL', 'REAL'])) { |
| 407 | 407 | $alterTableStatementStrings[] = 'UNSIGNED'; |
| 408 | 408 | } |
| 409 | 409 | } |
| 410 | 410 | } |
| 411 | 411 | |
| 412 | - if (isset($attributes[ 'collate' ])) { |
|
| 413 | - $alterTableStatementStrings[] = 'COLLATE ' . $attributes[ 'collate' ]; |
|
| 414 | - } elseif (in_array($attributes[ 'type' ], |
|
| 412 | + if (isset($attributes['collate'])) { |
|
| 413 | + $alterTableStatementStrings[] = 'COLLATE ' . $attributes['collate']; |
|
| 414 | + } elseif (in_array($attributes['type'], |
|
| 415 | 415 | ['CHAR', 'VARCHAR', 'TEXT', 'LONGTEXT', 'TINYTEXT', 'ENUM'])) { |
| 416 | 416 | $alterTableStatementStrings[] = 'COLLATE ' . $this->conn->getConfig('collate'); |
| 417 | 417 | } |
| 418 | 418 | |
| 419 | - if (isset($attributes[ 'not_null' ])) { |
|
| 420 | - if ($attributes[ 'not_null' ] === true) { |
|
| 419 | + if (isset($attributes['not_null'])) { |
|
| 420 | + if ($attributes['not_null'] === true) { |
|
| 421 | 421 | $alterTableStatementStrings[] = 'NOT NULL'; |
| 422 | 422 | } |
| 423 | 423 | } |
| 424 | 424 | |
| 425 | - if (isset($attributes[ 'default' ])) { |
|
| 426 | - $alterTableStatementStrings[] = 'DEFAULT ' . $this->conn->escape($attributes[ 'default' ]); |
|
| 425 | + if (isset($attributes['default'])) { |
|
| 426 | + $alterTableStatementStrings[] = 'DEFAULT ' . $this->conn->escape($attributes['default']); |
|
| 427 | 427 | } |
| 428 | 428 | |
| 429 | - if (isset($attributes[ 'auto_increment' ])) { |
|
| 430 | - if ($attributes[ 'auto_increment' ] === true) { |
|
| 429 | + if (isset($attributes['auto_increment'])) { |
|
| 430 | + if ($attributes['auto_increment'] === true) { |
|
| 431 | 431 | $alterTableStatementStrings[] = 'AUTO_INCREMENT '; |
| 432 | 432 | } |
| 433 | 433 | } |
| 434 | 434 | |
| 435 | - if (isset($attributes[ 'comment' ])) { |
|
| 436 | - $alterTableStatementStrings[] = 'COMMENT ' . $attributes[ 'comment' ]; |
|
| 435 | + if (isset($attributes['comment'])) { |
|
| 436 | + $alterTableStatementStrings[] = 'COMMENT ' . $attributes['comment']; |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | $statementLines[] = implode(' ', $alterTableStatementStrings) . ';'; |
@@ -474,7 +474,7 @@ discard block |
||
| 474 | 474 | { |
| 475 | 475 | $statementLines[] = 'ALTER TABLE ' . $this->conn->escapeIdentifiers($table); |
| 476 | 476 | |
| 477 | - $keys = array_map(function ($column) { |
|
| 477 | + $keys = array_map(function($column) { |
|
| 478 | 478 | return $this->conn->escapeIdentifiers($column); |
| 479 | 479 | }, $columns); |
| 480 | 480 | |
@@ -547,7 +547,7 @@ discard block |
||
| 547 | 547 | { |
| 548 | 548 | $statementLines[] = 'ALTER TABLE ' . $this->conn->escapeIdentifiers($table); |
| 549 | 549 | |
| 550 | - $keys = array_map(function ($column) { |
|
| 550 | + $keys = array_map(function($column) { |
|
| 551 | 551 | return $this->conn->escapeIdentifiers($column); |
| 552 | 552 | }, $columns); |
| 553 | 553 | |
@@ -575,7 +575,7 @@ discard block |
||
| 575 | 575 | */ |
| 576 | 576 | protected function platformCreateTableIndexesStatement($table, array $columns, $unique = false) |
| 577 | 577 | { |
| 578 | - $keys = array_map(function ($column) { |
|
| 578 | + $keys = array_map(function($column) { |
|
| 579 | 579 | return $this->conn->escapeIdentifiers($column); |
| 580 | 580 | }, $columns); |
| 581 | 581 | |
@@ -658,13 +658,13 @@ discard block |
||
| 658 | 658 | $columns = array_keys($conditions); |
| 659 | 659 | |
| 660 | 660 | if (count($conditions) == 1) { |
| 661 | - $statementLines[] = 'ADD CHECK (' . $this->conn->escapeIdentifiers($columns[ 0 ]) . ')'; |
|
| 661 | + $statementLines[] = 'ADD CHECK (' . $this->conn->escapeIdentifiers($columns[0]) . ')'; |
|
| 662 | 662 | } else { |
| 663 | 663 | $conditionStatementStrings = []; |
| 664 | 664 | |
| 665 | 665 | foreach ($conditions as $column => $condition) { |
| 666 | 666 | if (preg_match('/\s*(?:<|>|!)?=\s*|\s*<>?\s*|\s*>\s*/i', $column, $match, PREG_OFFSET_CAPTURE)) { |
| 667 | - $operator = trim($match[ 0 ]); |
|
| 667 | + $operator = trim($match[0]); |
|
| 668 | 668 | $column = trim(str_replace($operator, '', $column)); |
| 669 | 669 | |
| 670 | 670 | $conditionStatementStrings[] = $this->conn->escapeIdentifiers($column) . $operator . $this->conn->escape($condition); |