Skip to content

Commit 6f1e210

Browse files
authored
feature #1413 [DoctrineHelper] handle property type for custom doctrine type
1 parent cbf2646 commit 6f1e210

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/Doctrine/DoctrineHelper.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\MakerBundle\Doctrine;
1313

1414
use Doctrine\DBAL\Connection;
15+
use Doctrine\DBAL\Types\Type;
1516
use Doctrine\DBAL\Types\Types;
1617
use Doctrine\ORM\EntityManagerInterface;
1718
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
@@ -257,7 +258,7 @@ public static function canColumnTypeBeInferredByPropertyType(string $columnType,
257258

258259
public static function getPropertyTypeForColumn(string $columnType): ?string
259260
{
260-
return match ($columnType) {
261+
$propertyType = match ($columnType) {
261262
Types::STRING, Types::TEXT, Types::GUID, Types::BIGINT, Types::DECIMAL => 'string',
262263
'array', Types::SIMPLE_ARRAY, Types::JSON => 'array',
263264
Types::BOOLEAN => 'bool',
@@ -271,6 +272,23 @@ public static function getPropertyTypeForColumn(string $columnType): ?string
271272
'ulid' => '\\'.Ulid::class,
272273
default => null,
273274
};
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();
274292
}
275293

276294
/**

0 commit comments

Comments
 (0)