Skip to content

Commit

Permalink
fix bigint handling with DBAL 4
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed May 17, 2024
1 parent 232d6d0 commit a289973
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ public function getType(string $class, string $property, array $context = []): ?
}

$nullable = $metadata instanceof ClassMetadata && $metadata->isNullable($property);

// DBAL 4 has a special fallback strategy for BINGINT (int -> string)
if (Types::BIGINT === $typeOfField && !method_exists(BigIntType::class, 'getName')) {
return Type::collection(Type::int(), Type::string());
}

$enumType = null;

if (null !== $enumClass = self::getMappingValue($metadata->getFieldMapping($property), 'enumType') ?? null) {
Expand Down Expand Up @@ -241,8 +247,8 @@ public function getTypes(string $class, string $property, array $context = []):
// DBAL 4 has a special fallback strategy for BINGINT (int -> string)
if (Types::BIGINT === $typeOfField && !method_exists(BigIntType::class, 'getName')) {
return [
new Type(Type::BUILTIN_TYPE_INT, $nullable),
new Type(Type::BUILTIN_TYPE_STRING, $nullable),
new LegacyType(LegacyType::BUILTIN_TYPE_INT, $nullable),
new LegacyType(LegacyType::BUILTIN_TYPE_STRING, $nullable),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public static function legacyTypesProvider(): array
{
// DBAL 4 has a special fallback strategy for BINGINT (int -> string)
if (!method_exists(BigIntType::class, 'getName')) {
$expectedBingIntType = [new LegacyType(LegacyType::BUILTIN_TYPE_INT), new Type(LegacyType::BUILTIN_TYPE_STRING)];
$expectedBingIntType = [new LegacyType(LegacyType::BUILTIN_TYPE_INT), new LegacyType(LegacyType::BUILTIN_TYPE_STRING)];
} else {
$expectedBingIntType = [new LegacyType(LegacyType::BUILTIN_TYPE_STRING)];
}
Expand Down Expand Up @@ -298,9 +298,16 @@ public function testExtract(string $property, ?Type $type)
*/
public static function typeProvider(): iterable
{
// DBAL 4 has a special fallback strategy for BINGINT (int -> string)
if (!method_exists(BigIntType::class, 'getName')) {
$expectedBigIntType = Type::collection(Type::int(), Type::string());
} else {
$expectedBigIntType = Type::string();
}

yield ['id', Type::int()];
yield ['guid', Type::string()];
yield ['bigint', Type::string()];
yield ['bigint', $expectedBigIntType];
yield ['time', Type::object(\DateTime::class)];
yield ['timeImmutable', Type::object(\DateTimeImmutable::class)];
yield ['dateInterval', Type::object(\DateInterval::class)];
Expand Down

0 comments on commit a289973

Please sign in to comment.