Skip to content

Commit 2e20446

Browse files
authored
fix: parameter provider in a long running http worker (#6683)
1 parent f932699 commit 2e20446

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/State/Provider/ParameterProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
5252
$context = ['operation' => $operation] + $context;
5353
$parameters = $operation->getParameters();
5454
foreach ($parameters ?? [] as $parameter) {
55+
$extraProperties = $parameter->getExtraProperties();
56+
unset($extraProperties['_api_values']);
57+
$parameters->add($parameter->getKey(), $parameter = $parameter->withExtraProperties($extraProperties));
58+
5559
$values = $this->getParameterValues($parameter, $request, $context);
5660
$value = $this->extractParameterValues($parameter, $values);
5761

src/State/Tests/ParameterProviderTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use ApiPlatform\Metadata\Parameter;
1919
use ApiPlatform\Metadata\Parameters;
2020
use ApiPlatform\Metadata\QueryParameter;
21+
use ApiPlatform\State\ParameterNotFound;
2122
use ApiPlatform\State\ParameterProviderInterface;
2223
use ApiPlatform\State\Provider\ParameterProvider;
2324
use PHPUnit\Framework\TestCase;
@@ -51,16 +52,20 @@ public function has(string $id): bool
5152
'order' => new QueryParameter(key: 'order', provider: 'test'),
5253
'search[:property]' => new QueryParameter(key: 'search[:property]', provider: [self::class, 'provide']),
5354
'foo' => new QueryParameter(key: 'foo', provider: [self::class, 'shouldNotBeCalled']),
55+
'baz' => (new QueryParameter(key: 'baz'))->withExtraProperties(['_api_values' => 'test1']),
56+
'fas' => (new QueryParameter(key: 'fas'))->withExtraProperties(['_api_values' => '42']),
5457
]));
5558
$parameterProvider = new ParameterProvider(null, $locator);
56-
$request = new Request(server: ['QUERY_STRING' => 'order[foo]=asc&search[a]=bar']);
59+
$request = new Request(server: ['QUERY_STRING' => 'order[foo]=asc&search[a]=bar&baz=t42']);
5760
$context = ['request' => $request, 'operation' => $operation];
5861
$parameterProvider->provide($operation, [], $context);
5962
$operation = $request->attributes->get('_api_operation');
6063

6164
$this->assertEquals('ok', $operation->getName());
6265
$this->assertEquals(['foo' => 'asc'], $operation->getParameters()->get('order', QueryParameter::class)->getValue());
6366
$this->assertEquals(['a' => 'bar'], $operation->getParameters()->get('search[:property]', QueryParameter::class)->getValue());
67+
$this->assertEquals('t42', $operation->getParameters()->get('baz', QueryParameter::class)->getValue());
68+
$this->assertEquals(new ParameterNotFound(), $operation->getParameters()->get('fas', QueryParameter::class)->getValue());
6469
}
6570

6671
public static function provide(): void

0 commit comments

Comments
 (0)