Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 69d10fe

Browse files
committed
bug #54694 [PropertyInfo] Update DoctrineExtractor for new DBAL 4 BIGINT type (llupa)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [PropertyInfo] Update DoctrineExtractor for new DBAL 4 BIGINT type | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | not sure | Deprecations? | no | Issues | Fix #54418 | License | MIT ## Additional Considerations This issue looks pretty straight forward, but it has had me running in circles not being sure how to exactly interpret it. The new return type to make it work with DBAL 4 is _fine_, but it is neither an intersection nor a union type, which **will** cause trouble for other libs if they do not explicitly check each. There is not easy way to get which DBAL version is the extractor is running against, so trying to optimize the flow is _tricky_. I am opening this PR to have a starting point in the hopes that maintainers of this package have more historical context than me. I have tried to document as much as possible about this in the issue linked above. 🍻 Commits ------- 92e54ac [PropertyInfo] Update DoctrineExtractor for new DBAL 4 BIGINT type
2 parents a03ad0e + 92e54ac commit 69d10fe

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bridge\Doctrine\PropertyInfo;
1313

1414
use Doctrine\Common\Collections\Collection;
15+
use Doctrine\DBAL\Types\BigIntType;
1516
use Doctrine\DBAL\Types\Types;
1617
use Doctrine\ORM\EntityManagerInterface;
1718
use Doctrine\ORM\Mapping\AssociationMapping;
@@ -142,6 +143,15 @@ public function getTypes(string $class, string $property, array $context = [])
142143
}
143144

144145
$nullable = $metadata instanceof ClassMetadata && $metadata->isNullable($property);
146+
147+
// DBAL 4 has a special fallback strategy for BINGINT (int -> string)
148+
if (Types::BIGINT === $typeOfField && !method_exists(BigIntType::class, 'getName')) {
149+
return [
150+
new Type(Type::BUILTIN_TYPE_INT, $nullable),
151+
new Type(Type::BUILTIN_TYPE_STRING, $nullable),
152+
];
153+
}
154+
145155
$enumType = null;
146156
if (null !== $enumClass = self::getMappingValue($metadata->getFieldMapping($property), 'enumType') ?? null) {
147157
$enumType = new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, $enumClass);

src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Doctrine\Common\EventManager;
1717
use Doctrine\DBAL\DriverManager;
1818
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
19+
use Doctrine\DBAL\Types\BigIntType;
1920
use Doctrine\DBAL\Types\Type as DBALType;
2021
use Doctrine\ORM\EntityManager;
2122
use Doctrine\ORM\Mapping\Column;
@@ -162,10 +163,17 @@ public function testExtractEnum()
162163

163164
public static function typesProvider(): array
164165
{
166+
// DBAL 4 has a special fallback strategy for BINGINT (int -> string)
167+
if (!method_exists(BigIntType::class, 'getName')) {
168+
$expectedBingIntType = [new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING)];
169+
} else {
170+
$expectedBingIntType = [new Type(Type::BUILTIN_TYPE_STRING)];
171+
}
172+
165173
return [
166174
['id', [new Type(Type::BUILTIN_TYPE_INT)]],
167175
['guid', [new Type(Type::BUILTIN_TYPE_STRING)]],
168-
['bigint', [new Type(Type::BUILTIN_TYPE_STRING)]],
176+
['bigint', $expectedBingIntType],
169177
['time', [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'DateTime')]],
170178
['timeImmutable', [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'DateTimeImmutable')]],
171179
['dateInterval', [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'DateInterval')]],

0 commit comments

Comments
 (0)