Skip to content

Commit

Permalink
handle property type for custom doctrine type
Browse files Browse the repository at this point in the history
  • Loading branch information
IndraGunawan committed Jan 1, 2024
1 parent f63b0c0 commit 8f7fb20
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 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',
Types::ARRAY, Types::SIMPLE_ARRAY, Types::JSON => 'array',
Types::BOOLEAN => 'bool',
Expand All @@ -271,6 +272,19 @@ public static function getPropertyTypeForColumn(string $columnType): ?string
'ulid' => '\\'.Ulid::class,
default => null,
};

if (null === $propertyType && Type::getTypeRegistry()->has($columnType)) {
$reflection = new \ReflectionClass(get_class(Type::getTypeRegistry()->get($columnType)));
if ($reflection->hasMethod('convertToPHPValue') && $returnType = $reflection->getMethod('convertToPHPValue')->getReturnType()) {
if ($returnType->isBuiltin()) {
$propertyType = $returnType->getName();
} else {
$propertyType = '\\'.$returnType->getName();
}
}
}

return $propertyType;
}

/**
Expand Down

0 comments on commit 8f7fb20

Please sign in to comment.