Skip to content

Commit 37d9cc0

Browse files
committed
Update to Doctrine ORM 3.2 #10257
1 parent 9c1dee3 commit 37d9cc0

13 files changed

+328
-579
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
},
3838
"require": {
3939
"php": "^8.2",
40-
"doctrine/orm": "^2.15",
40+
"doctrine/orm": "^3.2",
4141
"psr/container": "^1.1 || ^2.0",
4242
"webonyx/graphql-php": "^15.7"
4343
},

composer.lock

+177-452
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan-baseline.neon

+20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
parameters:
22
ignoreErrors:
3+
-
4+
message: "#^Cannot call method getMethods\\(\\) on ReflectionClass\\<object\\>\\|null\\.$#"
5+
count: 1
6+
path: src/Factory/AbstractFieldsConfigurationFactory.php
7+
8+
-
9+
message: "#^Parameter \\#1 \\$property of method GraphQL\\\\Doctrine\\\\Factory\\\\AbstractFactory\\:\\:isPropertyExcluded\\(\\) expects ReflectionProperty, ReflectionProperty\\|null given\\.$#"
10+
count: 1
11+
path: src/Factory/Type/FilterGroupConditionTypeFactory.php
12+
13+
-
14+
message: "#^Parameter \\#1 \\$property of method GraphQL\\\\Doctrine\\\\Factory\\\\Type\\\\FilterGroupConditionTypeFactory\\:\\:getLeafType\\(\\) expects ReflectionProperty, ReflectionProperty\\|null given\\.$#"
15+
count: 1
16+
path: src/Factory/Type/FilterGroupConditionTypeFactory.php
17+
18+
-
19+
message: "#^Parameter \\#1 \\$property of method GraphQL\\\\Doctrine\\\\Factory\\\\AbstractFactory\\:\\:isPropertyExcluded\\(\\) expects ReflectionProperty, ReflectionProperty\\|null given\\.$#"
20+
count: 1
21+
path: src/Factory/Type/SortingTypeFactory.php
22+
323
-
424
message: "#^Method GraphQL\\\\Doctrine\\\\Types\\:\\:getOperator\\(\\) should return GraphQL\\\\Doctrine\\\\Definition\\\\Operator\\\\AbstractOperator but returns GraphQL\\\\Type\\\\Definition\\\\NamedType&GraphQL\\\\Type\\\\Definition\\\\Type\\.$#"
525
count: 1

src/Definition/Operator/HaveOperatorType.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace GraphQL\Doctrine\Definition\Operator;
66

77
use Doctrine\ORM\Mapping\ClassMetadata;
8-
use Doctrine\ORM\Mapping\ClassMetadataInfo;
8+
use Doctrine\ORM\Mapping\OneToManyAssociationMapping;
99
use Doctrine\ORM\QueryBuilder;
1010
use GraphQL\Doctrine\Factory\UniqueNameFactory;
1111
use GraphQL\Type\Definition\LeafType;
@@ -48,12 +48,12 @@ protected function getCollectionValuedDqlCondition(UniqueNameFactory $uniqueName
4848
// use `=`, and not `IN()`). So we simulate an approximation of MEMBER OF that support multiple values. But it
4949
// does **not** support composite identifiers. And that is fine because it is an official limitation of this
5050
// library anyway.
51-
if ($association['type'] === ClassMetadataInfo::ONE_TO_MANY) {
51+
if ($association instanceof OneToManyAssociationMapping) {
5252
$id = $metadata->identifier[0];
5353

54-
$otherClassName = $association['targetEntity'];
54+
$otherClassName = $association->targetEntity;
5555
$otherAlias = $uniqueNameFactory->createAliasName($otherClassName);
56-
$otherField = $association['mappedBy'];
56+
$otherField = $association->mappedBy;
5757
$otherMetadata = $queryBuilder->getEntityManager()->getClassMetadata($otherClassName);
5858
$otherId = $otherMetadata->identifier[0];
5959

src/Factory/AbstractFieldsConfigurationFactory.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ private function findIdentityField(string $className): void
147147
{
148148
$this->metadata = $this->entityManager->getClassMetadata($className);
149149
foreach ($this->metadata->fieldMappings as $meta) {
150-
if ($meta['id'] ?? false) {
151-
$this->identityField = $meta['fieldName'];
150+
if ($meta->id ?? false) {
151+
$this->identityField = $meta->fieldName;
152152
}
153153
}
154154
}
@@ -184,7 +184,7 @@ final protected function isIdentityField(string $fieldName): bool
184184
*/
185185
private function getTargetEntity(string $fieldName): ?string
186186
{
187-
return $this->metadata->associationMappings[$fieldName]['targetEntity'] ?? null;
187+
return $this->metadata->associationMappings[$fieldName]->targetEntity ?? null;
188188
}
189189

190190
/**

src/Factory/FilteredQueryBuilderFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private function applyJoins(ClassMetadata $metadata, array $joins, string $alias
127127
$joinedAlias = $this->createJoin($alias, $field, $join['type']);
128128

129129
if (isset($join['joins']) || isset($join['conditions'])) {
130-
$targetClassName = $metadata->getAssociationMapping($field)['targetEntity'];
130+
$targetClassName = $metadata->getAssociationMapping($field)->targetEntity;
131131
$targetMetadata = $this->entityManager->getClassMetadata($targetClassName);
132132
$type = $this->types->getFilterGroupCondition($targetClassName);
133133
$this->applyJoinsAndFilters($targetMetadata, $joinedAlias, $type, $join['joins'] ?? [], $join['conditions'] ?? []);

src/Factory/Type/FilterGroupConditionTypeFactory.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace GraphQL\Doctrine\Factory\Type;
66

7+
use Doctrine\ORM\Mapping\FieldMapping;
78
use GraphQL\Doctrine\Attribute\Filter;
89
use GraphQL\Doctrine\Attribute\FilterGroupCondition;
910
use GraphQL\Doctrine\Definition\Operator\AbstractOperator;
@@ -60,7 +61,7 @@ public function create(string $className, string $typeName): InputObjectType
6061

6162
// Get all scalar fields
6263
foreach ($metadata->fieldMappings as $mapping) {
63-
$fieldName = $mapping['fieldName'];
64+
$fieldName = $mapping->fieldName;
6465
$property = $metadata->getReflectionProperty($fieldName);
6566

6667
// Skip exclusion specified by user
@@ -76,7 +77,7 @@ public function create(string $className, string $typeName): InputObjectType
7677

7778
// Get all collection fields
7879
foreach ($metadata->associationMappings as $mapping) {
79-
$fieldName = $mapping['fieldName'];
80+
$fieldName = $mapping->fieldName;
8081
$operators = $this->getOperators($fieldName, Type::id(), true, $metadata->isCollectionValuedAssociation($fieldName));
8182

8283
$filters[] = $this->getFieldConfiguration($typeName, $fieldName, $operators);
@@ -105,9 +106,9 @@ public function create(string $className, string $typeName): InputObjectType
105106
/**
106107
* Read the type of the filterGroupCondition, either from Doctrine mapping type, or the override via attribute.
107108
*/
108-
private function getLeafType(ReflectionProperty $property, array $mapping): LeafType
109+
private function getLeafType(ReflectionProperty $property, FieldMapping $mapping): LeafType
109110
{
110-
if ($mapping['id'] ?? false) {
111+
if ($mapping->id ?? false) {
111112
return Type::id();
112113
}
113114

@@ -127,7 +128,7 @@ private function getLeafType(ReflectionProperty $property, array $mapping): Leaf
127128
}
128129

129130
/** @var LeafType $leafType */
130-
$leafType = $this->types->get($mapping['type']);
131+
$leafType = $this->types->get($mapping->type);
131132

132133
return $leafType;
133134
}

src/Factory/Type/FilterGroupJoinTypeFactory.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ private function getJoinsFields(string $className): array
6060
$associations = $this->entityManager->getClassMetadata($className)->associationMappings;
6161
foreach ($associations as $association) {
6262
$field = [
63-
'name' => $association['fieldName'],
64-
'type' => $this->types->getJoinOn($association['targetEntity']),
63+
'name' => $association->fieldName,
64+
'type' => $this->types->getJoinOn($association->targetEntity),
6565
];
6666

6767
$fields[] = $field;

tests/Blog/Filtering/SearchOperatorType.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ private function getSearchableFields(ClassMetadata $metadata, string $alias): ar
6565
$fields = [];
6666
$textType = ['string', 'text'];
6767
foreach ($metadata->fieldMappings as $g) {
68-
if (in_array($g['type'], $textType, true)) {
69-
$fields[] = $alias . '.' . $g['fieldName'];
68+
if (in_array($g->type, $textType, true)) {
69+
$fields[] = $alias . '.' . $g->fieldName;
7070
}
7171
}
7272

tests/EntityManagerTrait.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ trait EntityManagerTrait
1818
private function setUpEntityManager(): void
1919
{
2020
$config = ORMSetup::createAttributeMetadataConfiguration([__DIR__ . '/Blog/Model'], true);
21-
$connection = DriverManager::getConnection(['url' => 'sqlite:///:memory:']);
21+
$connection = DriverManager::getConnection([
22+
'driver' => 'sqlite3',
23+
'memory' => true,
24+
]);
2225

2326
$this->entityManager = new EntityManager($connection, $config);
2427
}

0 commit comments

Comments
 (0)