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