@@ -1162,6 +1162,39 @@ private function getEntityTypeHint($doctrineType): ?string
1162
1162
}
1163
1163
}
1164
1164
1165
+ private function getTypeConstant (string $ type )
1166
+ {
1167
+ $ typesMapping = [
1168
+ 'array ' => 'Types::ARRAY ' ,
1169
+ 'ascii_string ' => 'Types::ASCII_STRING ' ,
1170
+ 'bigint ' => 'Types::BIGINT ' ,
1171
+ 'binary ' => 'Types::BINARY ' ,
1172
+ 'blob ' => 'Types::BLOB ' ,
1173
+ 'boolean ' => 'Types::BOOLEAN ' ,
1174
+ 'date ' => 'Types::DATE_MUTABLE ' ,
1175
+ 'date_immutable ' => 'Types::DATE_IMMUTABLE ' ,
1176
+ 'dateinterval ' => 'Types::DATEINTERVAL ' ,
1177
+ 'datetime ' => 'Types::DATETIME_MUTABLE ' ,
1178
+ 'datetime_immutable ' => 'Types::DATETIME_IMMUTABLE ' ,
1179
+ 'datetimetz ' => 'Types::DATETIMETZ_MUTABLE ' ,
1180
+ 'datetimetz_immutable ' => 'Types::DATETIMETZ_IMMUTABLE ' ,
1181
+ 'decimal ' => 'Types::DECIMAL ' ,
1182
+ 'float ' => 'Types::FLOAT ' ,
1183
+ 'guid ' => 'Types::GUID ' ,
1184
+ 'integer ' => 'Types::INTEGER ' ,
1185
+ 'json ' => 'Types::JSON ' ,
1186
+ 'object ' => 'Types::OBJECT ' ,
1187
+ 'simple_array ' => 'Types::SIMPLE_ARRAY ' ,
1188
+ 'smallint ' => 'Types::SMALLINT ' ,
1189
+ 'string ' => 'Types::STRING ' ,
1190
+ 'text ' => 'Types::TEXT ' ,
1191
+ 'time ' => 'Types::TIME_MUTABLE ' ,
1192
+ 'time_immutable ' => 'Types::TIME_IMMUTABLE ' ,
1193
+ ];
1194
+
1195
+ return $ typesMapping [$ type ] ?? $ type ;
1196
+ }
1197
+
1165
1198
private function isInSameNamespace ($ class ): bool
1166
1199
{
1167
1200
$ namespace = substr ($ class , 0 , strrpos ($ class , '\\' ));
@@ -1432,7 +1465,22 @@ private function buildAttributeNode(string $attributeClass, array $options): Nod
1432
1465
$ options = $ this ->sortOptionsByClassConstructorParameters ($ options , $ attributeClass );
1433
1466
1434
1467
$ context = $ this ;
1435
- $ nodeArguments = array_map (static function ($ option , $ value ) use ($ context ) {
1468
+ $ nodeArguments = array_map (static function ($ option , $ value ) use ($ context , $ attributeClass ) {
1469
+ // if we do are creating an ORM column attribute and this is the type option, we replace string with its constant
1470
+ if ('type ' === $ option && 'ORM \\Column ' === $ attributeClass ) {
1471
+ $ typeConstant = $ context ->getTypeConstant ($ value );
1472
+ // if given type is handled by doctrine, we generate the attribute using the constant
1473
+ if ($ typeConstant !== $ value ) {
1474
+ return new Node \Arg (
1475
+ new Node \Expr \ConstFetch (new Node \Name ($ typeConstant )),
1476
+ false ,
1477
+ false ,
1478
+ [],
1479
+ new Node \Identifier ($ option )
1480
+ );
1481
+ }
1482
+ }
1483
+
1436
1484
return new Node \Arg ($ context ->buildNodeExprByValue ($ value ), false , false , [], new Node \Identifier ($ option ));
1437
1485
}, array_keys ($ options ), array_values ($ options ));
1438
1486
0 commit comments