12
12
namespace Symfony \Bundle \MakerBundle \Doctrine ;
13
13
14
14
use Doctrine \DBAL \Connection ;
15
+ use Doctrine \DBAL \Types \Type ;
15
16
use Doctrine \DBAL \Types \Types ;
16
17
use Doctrine \ORM \EntityManagerInterface ;
17
18
use Doctrine \ORM \Mapping \Driver \AttributeDriver ;
@@ -257,7 +258,7 @@ public static function canColumnTypeBeInferredByPropertyType(string $columnType,
257
258
258
259
public static function getPropertyTypeForColumn (string $ columnType ): ?string
259
260
{
260
- return match ($ columnType ) {
261
+ $ propertyType = match ($ columnType ) {
261
262
Types::STRING , Types::TEXT , Types::GUID , Types::BIGINT , Types::DECIMAL => 'string ' ,
262
263
'array ' , Types::SIMPLE_ARRAY , Types::JSON => 'array ' ,
263
264
Types::BOOLEAN => 'bool ' ,
@@ -271,6 +272,23 @@ public static function getPropertyTypeForColumn(string $columnType): ?string
271
272
'ulid ' => '\\' .Ulid::class,
272
273
default => null ,
273
274
};
275
+
276
+ if (null !== $ propertyType || !($ registry = Type::getTypeRegistry ())->has ($ columnType )) {
277
+ return $ propertyType ;
278
+ }
279
+
280
+ $ reflection = new \ReflectionClass (($ registry ->get ($ columnType ))::class);
281
+
282
+ $ returnType = $ reflection ->getMethod ('convertToPHPValue ' )->getReturnType ();
283
+
284
+ /*
285
+ * we do not support union and intersection types
286
+ */
287
+ if (!$ returnType instanceof \ReflectionNamedType) {
288
+ return null ;
289
+ }
290
+
291
+ return $ returnType ->isBuiltin () ? $ returnType ->getName () : '\\' .$ returnType ->getName ();
274
292
}
275
293
276
294
/**
0 commit comments