Skip to content

Commit

Permalink
feature #1413 [DoctrineHelper] handle property type for custom doctri…
Browse files Browse the repository at this point in the history
…ne type
  • Loading branch information
IndraGunawan authored Mar 4, 2024
1 parent cbf2646 commit 6f1e210
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/Doctrine/DoctrineHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Bundle\MakerBundle\Doctrine;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
Expand Down Expand Up @@ -257,7 +258,7 @@ public static function canColumnTypeBeInferredByPropertyType(string $columnType,

public static function getPropertyTypeForColumn(string $columnType): ?string
{
return match ($columnType) {
$propertyType = match ($columnType) {
Types::STRING, Types::TEXT, Types::GUID, Types::BIGINT, Types::DECIMAL => 'string',
'array', Types::SIMPLE_ARRAY, Types::JSON => 'array',
Types::BOOLEAN => 'bool',
Expand All @@ -271,6 +272,23 @@ public static function getPropertyTypeForColumn(string $columnType): ?string
'ulid' => '\\'.Ulid::class,
default => null,
};

if (null !== $propertyType || !($registry = Type::getTypeRegistry())->has($columnType)) {
return $propertyType;
}

$reflection = new \ReflectionClass(($registry->get($columnType))::class);

$returnType = $reflection->getMethod('convertToPHPValue')->getReturnType();

/*
* we do not support union and intersection types
*/
if (!$returnType instanceof \ReflectionNamedType) {
return null;
}

return $returnType->isBuiltin() ? $returnType->getName() : '\\'.$returnType->getName();
}

/**
Expand Down

0 comments on commit 6f1e210

Please sign in to comment.