Skip to content

Commit 10c64a8

Browse files
committed
fixup! Add payload controller value resolver
1 parent 9b895cb commit 10c64a8

File tree

5 files changed

+3
-42
lines changed

5 files changed

+3
-42
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* DataProvider: Add `TraversablePaginator` (#3783)
1313
* JSON:API: Support inclusion of resources from path (#3288)
1414
* Swagger UI: Add `swagger_ui_extra_configuration` to Swagger / OpenAPI configuration (#3731)
15-
* Allow controller argument with a name different from `$data` thanks to an argument resolver
15+
* Allow controller argument with a name different from `$data` thanks to an argument resolver (#3263)
1616

1717
## 2.6.3
1818

src/Bridge/Symfony/Bundle/ArgumentResolver/PayloadArgumentResolver.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ public function supports(Request $request, ArgumentMetadata $argument): bool
6262

6363
public function resolve(Request $request, ArgumentMetadata $argument): \Generator
6464
{
65-
if (!$this->supports($request, $argument)) {
66-
throw new \InvalidArgumentException('Given request and argument not supported.');
67-
}
68-
6965
yield $request->attributes->get('data');
7066
}
7167

src/Bridge/Symfony/Bundle/Resources/config/argument_resolver.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
66

77
<services>
8-
<service id="api_platform.payload_argument_resolver" class="ApiPlatform\Core\Bridge\Symfony\Bundle\ArgumentResolver\PayloadArgumentResolver" public="false">
8+
<service id="api_platform.argument_resolver.payload" class="ApiPlatform\Core\Bridge\Symfony\Bundle\ArgumentResolver\PayloadArgumentResolver" public="false">
99
<argument type="service" id="api_platform.metadata.resource.metadata_factory" />
1010
<argument type="service" id="api_platform.serializer.context_builder" />
1111

tests/Bridge/Symfony/Bundle/ArgumentResolver/PayloadArgumentResolverTest.php

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
use Symfony\Component\HttpFoundation\Request;
2323
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
2424

25-
/**
26-
* @covers \ApiPlatform\Core\Bridge\Symfony\Bundle\ArgumentResolver\PayloadArgumentResolver
27-
*/
2825
class PayloadArgumentResolverTest extends KernelTestCase
2926
{
3027
public function testItSupportsRequestWithPayloadOfExpectedType(): void
@@ -136,38 +133,6 @@ public function testItResolvesArgumentFromRequestWithDataOfChildType(): void
136133
);
137134
}
138135

139-
/**
140-
* @dataProvider provideUnsupportedArguments
141-
*/
142-
public function testItDoesNotResolveForUnsupportedArgument(ArgumentMetadata $argument): void
143-
{
144-
$resolver = $this->createArgumentResolver();
145-
146-
$request = $this->createRequest('PUT', [
147-
'_api_resource_class' => ResourceImplementation::class,
148-
'_api_receive' => true,
149-
'_api_item_operation_name' => 'update',
150-
'data' => new ResourceImplementation(),
151-
]);
152-
153-
$this->expectException(\InvalidArgumentException::class);
154-
155-
iterator_to_array($resolver->resolve($request, $argument));
156-
}
157-
158-
/**
159-
* @dataProvider provideUnsupportedRequests
160-
*/
161-
public function testItDoesNotResolveForUnsupportedRequest(Request $request): void
162-
{
163-
$resolver = $this->createArgumentResolver();
164-
$argument = $this->createArgumentMetadata(ResourceInterface::class);
165-
166-
$this->expectException(\InvalidArgumentException::class);
167-
168-
iterator_to_array($resolver->resolve($request, $argument));
169-
}
170-
171136
public function provideUnsupportedRequests(): iterable
172137
{
173138
yield 'GET request' => [$this->createRequest('GET', [

tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,7 @@ private function getBaseContainerBuilderProphecy(array $doctrineIntegrationsToLo
12871287
'api_platform.metadata.resource.name_collection_factory.annotation',
12881288
'api_platform.metadata.resource.name_collection_factory.yaml',
12891289
'api_platform.metadata.subresource.metadata_factory.annotation',
1290-
'api_platform.payload_argument_resolver',
1290+
'api_platform.argument_resolver.payload',
12911291
'api_platform.problem.encoder',
12921292
'api_platform.problem.normalizer.constraint_violation_list',
12931293
'api_platform.problem.normalizer.error',

0 commit comments

Comments
 (0)