Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f05b043

Browse files
committedMay 17, 2024
fix bigint handling with DBAL 4
1 parent 5ba4d33 commit f05b043

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed
 

‎PropertyInfo/DoctrineExtractor.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ public function getType(string $class, string $property, array $context = []): ?
130130
}
131131

132132
$nullable = $metadata instanceof ClassMetadata && $metadata->isNullable($property);
133+
134+
// DBAL 4 has a special fallback strategy for BINGINT (int -> string)
135+
if (Types::BIGINT === $typeOfField && !method_exists(BigIntType::class, 'getName')) {
136+
return Type::collection(Type::int(), Type::string());
137+
}
138+
133139
$enumType = null;
134140

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

‎Tests/PropertyInfo/DoctrineExtractorTest.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public static function legacyTypesProvider(): array
156156
{
157157
// DBAL 4 has a special fallback strategy for BINGINT (int -> string)
158158
if (!method_exists(BigIntType::class, 'getName')) {
159-
$expectedBingIntType = [new LegacyType(LegacyType::BUILTIN_TYPE_INT), new Type(LegacyType::BUILTIN_TYPE_STRING)];
159+
$expectedBingIntType = [new LegacyType(LegacyType::BUILTIN_TYPE_INT), new LegacyType(LegacyType::BUILTIN_TYPE_STRING)];
160160
} else {
161161
$expectedBingIntType = [new LegacyType(LegacyType::BUILTIN_TYPE_STRING)];
162162
}
@@ -298,9 +298,16 @@ public function testExtract(string $property, ?Type $type)
298298
*/
299299
public static function typeProvider(): iterable
300300
{
301+
// DBAL 4 has a special fallback strategy for BINGINT (int -> string)
302+
if (!method_exists(BigIntType::class, 'getName')) {
303+
$expectedBigIntType = Type::collection(Type::int(), Type::string());
304+
} else {
305+
$expectedBigIntType = Type::string();
306+
}
307+
301308
yield ['id', Type::int()];
302309
yield ['guid', Type::string()];
303-
yield ['bigint', Type::string()];
310+
yield ['bigint', $expectedBigIntType];
304311
yield ['time', Type::object(\DateTime::class)];
305312
yield ['timeImmutable', Type::object(\DateTimeImmutable::class)];
306313
yield ['dateInterval', Type::object(\DateInterval::class)];

0 commit comments

Comments
 (0)
Please sign in to comment.