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
Types::ARRAY , Types::SIMPLE_ARRAY , Types::JSON => 'array ' ,
263
264
Types::BOOLEAN => 'bool ' ,
@@ -271,6 +272,19 @@ public static function getPropertyTypeForColumn(string $columnType): ?string
271
272
'ulid ' => '\\' .Ulid::class,
272
273
default => null ,
273
274
};
275
+
276
+ if (null === $ propertyType && Type::getTypeRegistry ()->has ($ columnType )) {
277
+ $ reflection = new \ReflectionClass (get_class (Type::getTypeRegistry ()->get ($ columnType )));
278
+ if ($ reflection ->hasMethod ('convertToPHPValue ' ) && $ returnType = $ reflection ->getMethod ('convertToPHPValue ' )->getReturnType ()) {
279
+ if ($ returnType ->isBuiltin ()) {
280
+ $ propertyType = $ returnType ->getName ();
281
+ } else {
282
+ $ propertyType = '\\' .$ returnType ->getName ();
283
+ }
284
+ }
285
+ }
286
+
287
+ return $ propertyType ;
274
288
}
275
289
276
290
/**
0 commit comments