Skip to content

Commit 7bb92a5

Browse files
authored
fix(doctrine): use stateOptions only within doctrine context (#5726)
1 parent 78a4966 commit 7bb92a5

File tree

5 files changed

+27
-29
lines changed

5 files changed

+27
-29
lines changed

features/doctrine/separated_resource.feature

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Feature: Use state options to use an entity that is not a resource
55

66
@!mongodb
77
@createSchema
8-
Scenario: Get collection
8+
Scenario: Get collection
99
Given there are 5 separated entities
1010
When I send a "GET" request to "/separated_entities"
1111
Then the response status code should be 200
@@ -35,7 +35,7 @@ Feature: Use state options to use an entity that is not a resource
3535

3636
@!mongodb
3737
@createSchema
38-
Scenario: Get ordered collection
38+
Scenario: Get ordered collection
3939
Given there are 5 separated entities
4040
When I send a "GET" request to "/separated_entities?order[value]=desc"
4141
Then the response status code should be 200
@@ -45,10 +45,32 @@ Feature: Use state options to use an entity that is not a resource
4545

4646
@!mongodb
4747
@createSchema
48-
Scenario: Get item
48+
Scenario: Get item
4949
Given there are 5 separated entities
5050
When I send a "GET" request to "/separated_entities/1"
51-
Then print last JSON response
5251
Then the response status code should be 200
5352
And the response should be in JSON
5453
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
54+
55+
@!mongodb
56+
@createSchema
57+
Scenario: Get item
58+
Given there are 5 separated entities
59+
When I send a "GET" request to "/separated_entities/1"
60+
Then the response status code should be 200
61+
And the response should be in JSON
62+
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
63+
64+
@!mongodb
65+
@createSchema
66+
Scenario: Get all EntityClassAndCustomProviderResources
67+
Given there are 1 separated entities
68+
When I send a "GET" request to "/entityClassAndCustomProviderResources"
69+
Then the response status code should be 200
70+
71+
@!mongodb
72+
@createSchema
73+
Scenario: Get one EntityClassAndCustomProviderResource
74+
Given there are 1 separated entities
75+
When I send a "GET" request to "/entityClassAndCustomProviderResources/1"
76+
Then the response status code should be 200

features/main/crud_uri_variables.feature

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,3 @@ Feature: Uri Variables
200200
When I add "Content-Type" header equal to "application/ld+json"
201201
And I send a "GET" request to "/companies/1/employees/2"
202202
Then the response status code should be 404
203-
204-
@!mongodb
205-
Scenario: Get all EntityClassAndCustomProviderResources
206-
Given there are 1 separated entities
207-
When I send a "GET" request to "/entityClassAndCustomProviderResources"
208-
Then the response status code should be 200
209-
210-
@!mongodb
211-
Scenario: Get one EntityClassAndCustomProviderResource
212-
Given there are 1 separated entities
213-
When I send a "GET" request to "/entityClassAndCustomProviderResources/1"
214-
Then the response status code should be 200

src/Metadata/Resource/Factory/LinkFactory.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
namespace ApiPlatform\Metadata\Resource\Factory;
1515

16-
use ApiPlatform\Doctrine\Orm\State\Options;
1716
use ApiPlatform\Metadata\ApiResource;
1817
use ApiPlatform\Metadata\Exception\RuntimeException;
1918
use ApiPlatform\Metadata\Link;
@@ -59,12 +58,7 @@ public function createLinksFromIdentifiers(ApiResource|Operation $operation): ar
5958
return [];
6059
}
6160

62-
$entityClass = $resourceClass;
63-
if (($options = $operation->getStateOptions()) && $options instanceof Options && $options->getEntityClass()) {
64-
$entityClass = $options->getEntityClass();
65-
}
66-
67-
$link = (new Link())->withFromClass($entityClass)->withIdentifiers($identifiers);
61+
$link = (new Link())->withFromClass($resourceClass)->withIdentifiers($identifiers);
6862
$parameterName = $identifiers[0];
6963

7064
if (1 < \count($identifiers)) {

tests/Fixtures/TestBundle/ApiResource/EntityClassAndCustomProviderResource.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
namespace ApiPlatform\Tests\Fixtures\TestBundle\ApiResource;
1515

1616
use ApiPlatform\Doctrine\Orm\State\Options;
17-
use ApiPlatform\Metadata\ApiProperty;
1817
use ApiPlatform\Metadata\ApiResource;
1918
use ApiPlatform\Metadata\Get;
2019
use ApiPlatform\Metadata\GetCollection;
@@ -25,7 +24,6 @@
2524
operations: [
2625
new Get(
2726
uriTemplate: '/entityClassAndCustomProviderResources/{id}',
28-
uriVariables: ['id']
2927
),
3028
new GetCollection(
3129
uriTemplate: '/entityClassAndCustomProviderResources'
@@ -36,8 +34,6 @@
3634
)]
3735
class EntityClassAndCustomProviderResource
3836
{
39-
#[ApiProperty(identifier: true)]
4037
public ?int $id;
41-
4238
public ?string $value;
4339
}

tests/Fixtures/TestBundle/State/EntityClassAndCustomProviderResourceProvider.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
use ApiPlatform\Doctrine\Orm\State\CollectionProvider;
1717
use ApiPlatform\Doctrine\Orm\State\ItemProvider;
18-
use ApiPlatform\Doctrine\Orm\State\Options;
1918
use ApiPlatform\Exception\ItemNotFoundException;
2019
use ApiPlatform\Metadata\CollectionOperationInterface;
2120
use ApiPlatform\Metadata\Operation;
@@ -39,7 +38,6 @@ public function __construct(
3938
*/
4039
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
4140
{
42-
$operation = ($stateOptions = $operation->getStateOptions()) instanceof Options ? $operation->withClass($stateOptions->getEntityClass()) : $operation;
4341
if ($operation instanceof CollectionOperationInterface) {
4442
$data = $this->collectionProvider->provide(
4543
$operation,

0 commit comments

Comments
 (0)