@@ -169,7 +169,7 @@ public function getCode(bool $quoted = false):string
169
169
$ default = '' ;
170
170
} elseif (ApiGenerator::isPostgres () && $ this ->isEnum ()) {
171
171
$ default =
172
- $ this ->rawParts ['default ' ] !== null ? ' DEFAULT ' . self :: escapeQuotes ( trim ($ this ->rawParts ['default ' ]) ) : '' ;
172
+ $ this ->rawParts ['default ' ] !== null ? ' DEFAULT ' . trim ($ this ->rawParts ['default ' ]) : '' ;
173
173
} else {
174
174
$ default = $ this ->rawParts ['default ' ] !== null ? ' DEFAULT ' . trim ($ this ->rawParts ['default ' ]) : '' ;
175
175
}
@@ -178,13 +178,10 @@ public function getCode(bool $quoted = false):string
178
178
if ((ApiGenerator::isMysql () || ApiGenerator::isMariaDb ()) && $ this ->rawParts ['position ' ]) {
179
179
$ code .= ' ' . $ this ->rawParts ['position ' ];
180
180
}
181
- if ((ApiGenerator::isMysql () || ApiGenerator::isMariaDb ()) && $ this ->isEnum ()) {
182
- return $ quoted ? "' " . $ code . "' " : $ code ;
183
- }
184
181
if (ApiGenerator::isPostgres () && $ this ->alterByXDbType ) {
185
- return $ quoted ? " ' " . $ this ->rawParts ['type ' ] . " ' " : $ this ->rawParts ['type ' ];
182
+ return $ quoted ? VarDumper:: export ( $ this ->rawParts ['type ' ]) : $ this ->rawParts ['type ' ];
186
183
}
187
- return $ quoted ? " ' " . $ code . " ' " : $ code ;
184
+ return $ quoted ? VarDumper:: export ( $ code) : $ code ;
188
185
}
189
186
190
187
public function getAlterExpression (bool $ addUsingExpression = false ):string
@@ -226,7 +223,7 @@ public function isJson():bool
226
223
227
224
public function isEnum ():bool
228
225
{
229
- return ! empty ($ this ->column -> enumValues );
226
+ return BaseMigrationBuilder:: isEnum ($ this ->column );
230
227
}
231
228
232
229
public function isDecimal ()
@@ -313,14 +310,14 @@ public static function mysqlEnumToString(array $enum):string
313
310
private function defaultValueJson (array $ value ):string
314
311
{
315
312
if ($ this ->alter === true ) {
316
- return "' " . str_replace ('" ' , '\" ' , Json::encode ($ value)) . "' " ;
313
+ return "' " . str_replace ('" ' , '\" ' , Json::encode ($ value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT )) . "' " ;
317
314
}
318
- return "\\ ' " . new Expression ( Json::encode ($ value)) . "\\ ' " ;
315
+ return "' " . Json::encode ($ value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT ) . "' " ;
319
316
}
320
317
321
318
private function defaultValueArray (array $ value ):string
322
319
{
323
- return "'{ " . str_replace ( ' " ' , "\"" , trim (Json::encode ($ value ), '[] ' ) ) . "}' " ;
320
+ return "'{ " . trim (Json::encode ($ value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT ), '[] ' ) . "}' " ;
324
321
}
325
322
326
323
private function resolve ():void
@@ -442,10 +439,10 @@ private function resolveDefaultValue():void
442
439
break ;
443
440
case 'object ' :
444
441
if ($ value instanceof JsonExpression) {
445
- $ this ->fluentParts ['default ' ] = "defaultValue(' " . Json::encode ($ value ->getValue ()) . "') " ;
442
+ $ this ->fluentParts ['default ' ] = "defaultValue(' " . Json::encode ($ value ->getValue (), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT ) . "') " ;
446
443
$ this ->rawParts ['default ' ] = $ this ->defaultValueJson ($ value ->getValue ());
447
444
} elseif ($ value instanceof ArrayExpression) {
448
- $ this ->fluentParts ['default ' ] = "defaultValue(' " . Json::encode ($ value ->getValue ()) . "') " ;
445
+ $ this ->fluentParts ['default ' ] = "defaultValue(' " . Json::encode ($ value ->getValue (), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT ) . "') " ;
449
446
$ this ->rawParts ['default ' ] = $ this ->defaultValueArray ($ value ->getValue ());
450
447
} else {
451
448
// $value instanceof \yii\db\Expression
@@ -454,19 +451,15 @@ private function resolveDefaultValue():void
454
451
}
455
452
break ;
456
453
case 'array ' :
457
- $ this ->fluentParts ['default ' ] = "defaultValue(' " . Json::encode ($ value ) . "') " ;
454
+ $ this ->fluentParts ['default ' ] = "defaultValue(' " . Json::encode ($ value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_QUOT ) . "') " ;
458
455
$ this ->rawParts ['default ' ] = $ this ->isJson ()
459
456
? $ this ->defaultValueJson ($ value )
460
457
: $ this ->defaultValueArray ($ value );
461
458
break ;
462
459
default :
463
460
$ this ->fluentParts ['default ' ] = $ expectInteger
464
- ? 'defaultValue( ' . $ value . ') ' : 'defaultValue(" ' . self ::escapeQuotes ((string )$ value ) . '") ' ;
465
- $ this ->rawParts ['default ' ] = $ expectInteger ? $ value : self ::wrapQuotes ($ value );
466
-
467
- if ((ApiGenerator::isMysql () || ApiGenerator::isMariaDb ()) && $ this ->isEnum ()) {
468
- $ this ->rawParts ['default ' ] = self ::escapeQuotes ($ this ->rawParts ['default ' ]);
469
- }
461
+ ? 'defaultValue( ' . $ value . ') ' : 'defaultValue( ' . VarDumper::export ((string )$ value ) . ') ' ;
462
+ $ this ->rawParts ['default ' ] = $ expectInteger ? $ value : VarDumper::export ((string )$ value );
470
463
}
471
464
}
472
465
0 commit comments