Skip to content

Commit 578e15e

Browse files
committed
Merge 4.0
2 parents fcbd804 + 1aa5017 commit 578e15e

File tree

5 files changed

+33
-19
lines changed

5 files changed

+33
-19
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@ On write operations, we added the [expectsHeader](https://www.hydra-cg.com/spec/
100100
* [d0a442786](https://github.com/api-platform/core/commit/d0a44278630d201b91cbba0774a09f4eeaac88f7) feat(doctrine): enhance getLinksHandler with method validation and typo suggestions (#6874)
101101
* [f67f6f1ac](https://github.com/api-platform/core/commit/f67f6f1acb6476182c18a3503f2a8bc80ae89a0b) feat(doctrine): doctrine filters like laravel eloquent filters (#6775)
102102

103+
## v4.0.20
104+
105+
### Bug fixes
106+
107+
* [284937039](https://github.com/api-platform/core/commit/284937039c61d4516687c648f4a7581ec1686f3d) fix(doctrine): mapping ArrayAccess deprecation (#6982)
108+
* [a434173b8](https://github.com/api-platform/core/commit/a434173b82f735041a79cb5f469ee0e731ca5956) fix(doctrine): Add a proper exception when a doctrine manager could not be found for a resource class (#6995)
109+
110+
111+
### Features
112+
103113
## v4.0.19
104114

105115
### Bug fixes

src/Doctrine/Orm/Extension/EagerLoadingExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ private function joinRelations(QueryBuilder $queryBuilder, QueryNameGeneratorInt
181181
$associationAlias = $existingJoin->getAlias();
182182
$isLeftJoin = Join::LEFT_JOIN === $existingJoin->getJoinType();
183183
} else {
184-
$isNullable = $mapping['joinColumns'][0]['nullable'] ?? true;
184+
$isNullable = $mapping['joinColumns'][0]?->nullable ?? true;
185185
$isLeftJoin = false !== $wasLeftJoin || true === $isNullable;
186186
$method = $isLeftJoin ? 'leftJoin' : 'innerJoin';
187187

src/Doctrine/Orm/State/ItemProvider.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
5353
$entityClass = $options->getEntityClass();
5454
}
5555

56-
/** @var EntityManagerInterface $manager */
56+
/** @var EntityManagerInterface|null $manager */
5757
$manager = $this->managerRegistry->getManagerForClass($entityClass);
58+
if (null === $manager) {
59+
throw new RuntimeException(\sprintf('No manager found for class "%s". Are you sure it\'s an entity?', $entityClass));
60+
}
5861

5962
$fetchData = $context['fetch_data'] ?? true;
6063
if (!$fetchData && \array_key_exists('id', $uriVariables)) {

src/Doctrine/Orm/Tests/Extension/EagerLoadingExtensionTest.php

+17-16
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
use ApiPlatform\Metadata\Property\PropertyNameCollection;
3636
use Doctrine\ORM\EntityManager;
3737
use Doctrine\ORM\Mapping\ClassMetadata;
38+
use Doctrine\ORM\Mapping\JoinColumn;
3839
use Doctrine\ORM\Query\Expr\Join;
3940
use Doctrine\ORM\QueryBuilder;
4041
use PHPUnit\Framework\TestCase;
@@ -94,8 +95,8 @@ public function testApplyToCollection(): void
9495

9596
$classMetadataProphecy = $this->prophesize(ClassMetadata::class);
9697
$classMetadataProphecy->associationMappings = [
97-
'relatedDummy' => ['fetch' => ClassMetadata::FETCH_EAGER, 'joinColumns' => [['nullable' => true]], 'targetEntity' => RelatedDummy::class],
98-
'relatedDummy2' => ['fetch' => ClassMetadata::FETCH_EAGER, 'joinColumns' => [['nullable' => false]], 'targetEntity' => RelatedDummy::class],
98+
'relatedDummy' => ['fetch' => ClassMetadata::FETCH_EAGER, 'joinColumns' => [new JoinColumn(nullable: true)], 'targetEntity' => RelatedDummy::class],
99+
'relatedDummy2' => ['fetch' => ClassMetadata::FETCH_EAGER, 'joinColumns' => [new JoinColumn(nullable: false)], 'targetEntity' => RelatedDummy::class],
99100
];
100101

101102
$relatedClassMetadataProphecy = $this->prophesize(ClassMetadata::class);
@@ -181,9 +182,9 @@ public function testApplyToItem(): void
181182

182183
$classMetadataProphecy = $this->prophesize(ClassMetadata::class);
183184
$classMetadataProphecy->associationMappings = [
184-
'relatedDummy' => ['fetch' => ClassMetadata::FETCH_EAGER, 'joinColumns' => [['nullable' => true]], 'targetEntity' => RelatedDummy::class],
185-
'relatedDummy2' => ['fetch' => ClassMetadata::FETCH_EAGER, 'joinColumns' => [['nullable' => false]], 'targetEntity' => UnknownDummy::class],
186-
'relatedDummy3' => ['fetch' => ClassMetadata::FETCH_EAGER, 'joinTable' => ['joinColumns' => [['nullable' => false]]], 'targetEntity' => UnknownDummy::class],
185+
'relatedDummy' => ['fetch' => ClassMetadata::FETCH_EAGER, 'joinColumns' => [new JoinColumn(nullable: true)], 'targetEntity' => RelatedDummy::class],
186+
'relatedDummy2' => ['fetch' => ClassMetadata::FETCH_EAGER, 'joinColumns' => [new JoinColumn(nullable: false)], 'targetEntity' => UnknownDummy::class],
187+
'relatedDummy3' => ['fetch' => ClassMetadata::FETCH_EAGER, 'joinTable' => ['joinColumns' => [new JoinColumn(nullable: false)]], 'targetEntity' => UnknownDummy::class],
187188
'relatedDummy4' => ['fetch' => ClassMetadata::FETCH_EAGER, 'targetEntity' => UnknownDummy::class],
188189
'relatedDummy5' => ['fetch' => ClassMetadata::FETCH_LAZY, 'targetEntity' => UnknownDummy::class],
189190
'singleInheritanceRelation' => ['fetch' => ClassMetadata::FETCH_EAGER, 'targetEntity' => AbstractDummy::class],
@@ -200,7 +201,7 @@ public function testApplyToItem(): void
200201
$relatedClassMetadataProphecy->hasField('embeddedDummy.name')->willReturn(true)->shouldBeCalled();
201202

202203
$relatedClassMetadataProphecy->associationMappings = [
203-
'relation' => ['fetch' => ClassMetadata::FETCH_EAGER, 'joinColumns' => [['nullable' => false]], 'targetEntity' => UnknownDummy::class],
204+
'relation' => ['fetch' => ClassMetadata::FETCH_EAGER, 'joinColumns' => [new JoinColumn(nullable: false)], 'targetEntity' => UnknownDummy::class],
204205
'thirdLevel' => ['fetch' => ClassMetadata::FETCH_EAGER, 'targetEntity' => ThirdLevel::class, 'sourceEntity' => RelatedDummy::class, 'inversedBy' => 'relatedDummies', 'type' => ClassMetadata::TO_ONE],
205206
];
206207

@@ -361,13 +362,13 @@ public function testMaxJoinsReached(): void
361362

362363
$classMetadataProphecy = $this->prophesize(ClassMetadata::class);
363364
$classMetadataProphecy->associationMappings = [
364-
'relatedDummy' => ['fetch' => ClassMetadata::FETCH_EAGER, 'joinColumns' => [['nullable' => false]], 'targetEntity' => RelatedDummy::class],
365+
'relatedDummy' => ['fetch' => ClassMetadata::FETCH_EAGER, 'joinColumns' => [new JoinColumn(nullable: false)], 'targetEntity' => RelatedDummy::class],
365366
];
366367
$classMetadataProphecy->hasField('relatedDummy')->willReturn(true);
367368

368369
$relatedClassMetadataProphecy = $this->prophesize(ClassMetadata::class);
369370
$relatedClassMetadataProphecy->associationMappings = [
370-
'dummy' => ['fetch' => ClassMetadata::FETCH_EAGER, 'joinColumns' => [['nullable' => false]], 'targetEntity' => Dummy::class],
371+
'dummy' => ['fetch' => ClassMetadata::FETCH_EAGER, 'joinColumns' => [new JoinColumn(nullable: false)], 'targetEntity' => Dummy::class],
371372
];
372373
$relatedClassMetadataProphecy->hasField('dummy')->willReturn(true);
373374

@@ -410,13 +411,13 @@ public function testMaxDepth(): void
410411

411412
$classMetadataProphecy = $this->prophesize(ClassMetadata::class);
412413
$classMetadataProphecy->associationMappings = [
413-
'relatedDummy' => ['fetch' => ClassMetadata::FETCH_EAGER, 'joinColumns' => [['nullable' => false]], 'targetEntity' => RelatedDummy::class],
414+
'relatedDummy' => ['fetch' => ClassMetadata::FETCH_EAGER, 'joinColumns' => [new JoinColumn(nullable: false)], 'targetEntity' => RelatedDummy::class],
414415
];
415416
$classMetadataProphecy->hasField('relatedDummy')->willReturn(true);
416417

417418
$relatedClassMetadataProphecy = $this->prophesize(ClassMetadata::class);
418419
$relatedClassMetadataProphecy->associationMappings = [
419-
'dummy' => ['fetch' => ClassMetadata::FETCH_EAGER, 'joinColumns' => [['nullable' => false]], 'targetEntity' => Dummy::class],
420+
'dummy' => ['fetch' => ClassMetadata::FETCH_EAGER, 'joinColumns' => [new JoinColumn(nullable: false)], 'targetEntity' => Dummy::class],
420421
];
421422
$relatedClassMetadataProphecy->hasField('dummy')->willReturn(true);
422423

@@ -471,7 +472,7 @@ public function testForceEager(): void
471472

472473
$classMetadataProphecy = $this->prophesize(ClassMetadata::class);
473474
$classMetadataProphecy->associationMappings = [
474-
'relation' => ['fetch' => ClassMetadata::FETCH_LAZY, 'targetEntity' => UnknownDummy::class, 'joinColumns' => [['nullable' => false]]],
475+
'relation' => ['fetch' => ClassMetadata::FETCH_LAZY, 'targetEntity' => UnknownDummy::class, 'joinColumns' => [new JoinColumn(nullable: false)]],
475476
];
476477

477478
$unknownClassMetadataProphecy = $this->prophesize(ClassMetadata::class);
@@ -577,7 +578,7 @@ public function testResourceClassNotFoundExceptionPropertyNameCollection(): void
577578

578579
$classMetadataProphecy = $this->prophesize(ClassMetadata::class);
579580
$classMetadataProphecy->associationMappings = [
580-
'relation' => ['fetch' => ClassMetadata::FETCH_LAZY, 'targetEntity' => UnknownDummy::class, 'joinColumns' => [['nullable' => false]]],
581+
'relation' => ['fetch' => ClassMetadata::FETCH_LAZY, 'targetEntity' => UnknownDummy::class, 'joinColumns' => [new JoinColumn(nullable: false)]],
581582
];
582583
$emProphecy = $this->prophesize(EntityManager::class);
583584
$emProphecy->getClassMetadata(Dummy::class)->shouldBeCalled()->willReturn($classMetadataProphecy->reveal());
@@ -751,8 +752,8 @@ public function testApplyToCollectionNoPartial(): void
751752

752753
$classMetadataProphecy = $this->prophesize(ClassMetadata::class);
753754
$classMetadataProphecy->associationMappings = [
754-
'relatedDummy' => ['fetch' => ClassMetadata::FETCH_EAGER, 'joinColumns' => [['nullable' => true]], 'targetEntity' => RelatedDummy::class],
755-
'relatedDummy2' => ['fetch' => ClassMetadata::FETCH_EAGER, 'joinColumns' => [['nullable' => false]], 'targetEntity' => RelatedDummy::class],
755+
'relatedDummy' => ['fetch' => ClassMetadata::FETCH_EAGER, 'joinColumns' => [new JoinColumn(nullable: true)], 'targetEntity' => RelatedDummy::class],
756+
'relatedDummy2' => ['fetch' => ClassMetadata::FETCH_EAGER, 'joinColumns' => [new JoinColumn(nullable: false)], 'targetEntity' => RelatedDummy::class],
756757
];
757758

758759
$emProphecy = $this->prophesize(EntityManager::class);
@@ -796,8 +797,8 @@ public function testApplyToCollectionWithANonReadableButFetchEagerProperty(): vo
796797

797798
$classMetadataProphecy = $this->prophesize(ClassMetadata::class);
798799
$classMetadataProphecy->associationMappings = [
799-
'relatedDummy' => ['fetch' => ClassMetadata::FETCH_EAGER, 'joinColumns' => [['nullable' => true]], 'targetEntity' => RelatedDummy::class],
800-
'relatedDummy2' => ['fetch' => ClassMetadata::FETCH_EAGER, 'joinColumns' => [['nullable' => false]], 'targetEntity' => RelatedDummy::class],
800+
'relatedDummy' => ['fetch' => ClassMetadata::FETCH_EAGER, 'joinColumns' => [new JoinColumn(nullable: true)], 'targetEntity' => RelatedDummy::class],
801+
'relatedDummy2' => ['fetch' => ClassMetadata::FETCH_EAGER, 'joinColumns' => [new JoinColumn(nullable: false)], 'targetEntity' => RelatedDummy::class],
801802
];
802803

803804
$emProphecy = $this->prophesize(EntityManager::class);

src/Metadata/ApiResource.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function __construct(
142142
* #[ApiResource(
143143
* uriTemplate: '/companies/{companyId}/employees/{id}',
144144
* uriVariables: [
145-
* 'companyId' => new Link(fromClass: Company::class, toProperty: 'company']),
145+
* 'companyId' => new Link(fromClass: Company::class, toProperty: 'company'),
146146
* 'id' => new Link(fromClass: Employee::class)
147147
* ],
148148
* operations: [new Get()]

0 commit comments

Comments
 (0)