8000 handle property type for custom doctrine type · symfony/maker-bundle@8f7fb20 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8f7fb20

Browse files
committed
handle property type for custom doctrine type
1 parent f63b0c0 commit 8f7fb20

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/Doctrine/DoctrineHelper.php

Lines changed: 15 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
Types::ARRAY, Types::SIMPLE_ARRAY, Types::JSON => 'array',
263264
Types::BOOLEAN => 'bool',
@@ -271,6 +272,19 @@ public static function getPropertyTypeForColumn(string $columnType): ?string
271272
'ulid' => '\\'.Ulid::class,
272273
default => null,
273274
};
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;
274288
}
275289

276290
/**

0 commit comments

Comments
 (0)
0