Skip to content

Commit c739df3

Browse files
committed
Merge 3.3
2 parents 0b985ae + c473b2e commit c739df3

27 files changed

+290
-115
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Doctrine\Common;
15+
16+
trait ParameterValueExtractorTrait
17+
{
18+
/**
19+
* @param array<string, mixed> $values
20+
*
21+
* @return array<string, mixed>
22+
*/
23+
private function extractParameterValue(array $values): array
24+
{
25+
if (!$values) {
26+
return $values;
27+
}
28+
29+
$key = key($values);
30+
if (!str_contains($key, ':property')) {
31+
return $values;
32+
}
33+
34+
return [str_replace('[:property]', '', $key) => $values[$key]];
35+
}
36+
}

src/Doctrine/Odm/Extension/ParameterExtension.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace ApiPlatform\Doctrine\Odm\Extension;
1515

16+
use ApiPlatform\Doctrine\Common\ParameterValueExtractorTrait;
1617
use ApiPlatform\Doctrine\Odm\Filter\FilterInterface;
1718
use ApiPlatform\Metadata\Operation;
1819
use Doctrine\ODM\MongoDB\Aggregation\Builder;
@@ -25,14 +26,16 @@
2526
*/
2627
final class ParameterExtension implements AggregationCollectionExtensionInterface, AggregationItemExtensionInterface
2728
{
29+
use ParameterValueExtractorTrait;
30+
2831
public function __construct(private readonly ContainerInterface $filterLocator)
2932
{
3033
}
3134

3235
private function applyFilter(Builder $aggregationBuilder, ?string $resourceClass = null, ?Operation $operation = null, array &$context = []): void
3336
{
3437
foreach ($operation->getParameters() ?? [] as $parameter) {
35-
$values = $parameter->getExtraProperties()['_api_values'] ?? [];
38+
$values = $this->extractParameterValue($parameter->getValue() ?? []);
3639
if (!$values) {
3740
continue;
3841
}

src/Doctrine/Orm/Extension/ParameterExtension.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace ApiPlatform\Doctrine\Orm\Extension;
1515

16+
use ApiPlatform\Doctrine\Common\ParameterValueExtractorTrait;
1617
use ApiPlatform\Doctrine\Orm\Filter\FilterInterface;
1718
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
1819
use ApiPlatform\Metadata\Operation;
@@ -26,6 +27,8 @@
2627
*/
2728
final class ParameterExtension implements QueryCollectionExtensionInterface, QueryItemExtensionInterface
2829
{
30+
use ParameterValueExtractorTrait;
31+
2932
public function __construct(private readonly ContainerInterface $filterLocator)
3033
{
3134
}
@@ -36,7 +39,7 @@ public function __construct(private readonly ContainerInterface $filterLocator)
3639
private function applyFilter(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, ?Operation $operation = null, array $context = []): void
3740
{
3841
foreach ($operation?->getParameters() ?? [] as $parameter) {
39-
$values = $parameter->getExtraProperties()['_api_values'] ?? [];
42+
$values = $this->extractParameterValue($parameter->getValue() ?? []);
4043
if (!$values) {
4144
continue;
4245
}

src/Metadata/ApiResource.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ public function __construct(
960960
$provider = null,
961961
$processor = null,
962962
protected ?OptionsInterface $stateOptions = null,
963-
protected array|Parameters|null $parameters = null,
963+
array|Parameters|null $parameters = null,
964964
protected array $extraProperties = [],
965965
) {
966966
parent::__construct(
@@ -1389,19 +1389,6 @@ public function withExceptionToStatus(array $exceptionToStatus): self
13891389
return $self;
13901390
}
13911391

1392-
public function getQueryParameterValidationEnabled(): ?bool
1393-
{
1394-
return $this->queryParameterValidationEnabled;
1395-
}
1396-
1397-
public function withQueryParameterValidationEnabled(bool $queryParameterValidationEnabled): self
1398-
{
1399-
$self = clone $this;
1400-
$self->queryParameterValidationEnabled = $queryParameterValidationEnabled;
1401-
1402-
return $self;
1403-
}
1404-
14051392
/**
14061393
* @return GraphQlOperation[]
14071394
*/

src/Metadata/Extractor/schema/resources.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
<xsd:attributeGroup ref="base"/>
6767
<xsd:attribute type="xsd:string" name="resolver"/>
6868
<xsd:attribute type="xsd:string" name="class" use="required"/>
69+
<xsd:attribute type="xsd:boolean" name="queryParameterValidationEnabled"/>
6970
<xsd:attribute type="xsd:boolean" name="read"/>
7071
<xsd:attribute type="xsd:boolean" name="deserialize"/>
7172
<xsd:attribute type="xsd:boolean" name="validate"/>

src/Metadata/GraphQl/Operation.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public function __construct(
8989
$processor = null,
9090
?OptionsInterface $stateOptions = null,
9191
array|Parameters|null $parameters = null,
92+
?bool $queryParameterValidationEnabled = null,
9293
array $extraProperties = []
9394
) {
9495
parent::__construct(
@@ -137,6 +138,7 @@ class: $class,
137138
processor: $processor,
138139
stateOptions: $stateOptions,
139140
parameters: $parameters,
141+
queryParameterValidationEnabled: $queryParameterValidationEnabled,
140142
extraProperties: $extraProperties
141143
);
142144
}

src/Metadata/GraphQl/Query.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public function __construct(
7272
$processor = null,
7373
?OptionsInterface $stateOptions = null,
7474
array|Parameters|null $parameters = null,
75+
?bool $queryParameterValidationEnabled = null,
7576
array $extraProperties = [],
7677

7778
protected ?bool $nested = null,
@@ -128,6 +129,7 @@ class: $class,
128129
processor: $processor,
129130
stateOptions: $stateOptions,
130131
parameters: $parameters,
132+
queryParameterValidationEnabled: $queryParameterValidationEnabled,
131133
extraProperties: $extraProperties
132134
);
133135
}

src/Metadata/GraphQl/QueryCollection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public function __construct(
7373
$processor = null,
7474
protected ?OptionsInterface $stateOptions = null,
7575
array|Parameters|null $parameters = null,
76+
?bool $queryParameterValidationEnabled = null,
7677
array $extraProperties = [],
7778

7879
?bool $nested = null,
@@ -128,6 +129,7 @@ class: $class,
128129
provider: $provider,
129130
processor: $processor,
130131
parameters: $parameters,
132+
queryParameterValidationEnabled: $queryParameterValidationEnabled,
131133
extraProperties: $extraProperties,
132134
nested: $nested,
133135
);

src/Metadata/GraphQl/Subscription.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public function __construct(
7272
$processor = null,
7373
?OptionsInterface $stateOptions = null,
7474
array|Parameters|null $parameters = null,
75+
?bool $queryParameterValidationEnabled = null,
7576
array $extraProperties = [],
7677
) {
7778
parent::__construct(
@@ -126,6 +127,7 @@ class: $class,
126127
processor: $processor,
127128
stateOptions: $stateOptions,
128129
parameters: $parameters,
130+
queryParameterValidationEnabled: $queryParameterValidationEnabled,
129131
extraProperties: $extraProperties,
130132
);
131133
}

src/Metadata/HttpOperation.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ public function __construct(
153153
protected ?array $openapiContext = null, // TODO Remove in 4.0
154154
protected bool|OpenApiOperation|Webhook|null $openapi = null,
155155
protected ?array $exceptionToStatus = null,
156-
protected ?bool $queryParameterValidationEnabled = null,
157156
protected ?array $links = null,
158157

159158
?string $shortName = null,
@@ -201,6 +200,7 @@ public function __construct(
201200
$processor = null,
202201
?OptionsInterface $stateOptions = null,
203202
array|Parameters|null $parameters = null,
203+
?bool $queryParameterValidationEnabled = null,
204204
array $extraProperties = [],
205205
) {
206206
parent::__construct(
@@ -249,6 +249,7 @@ class: $class,
249249
processor: $processor,
250250
stateOptions: $stateOptions,
251251
parameters: $parameters,
252+
queryParameterValidationEnabled: $queryParameterValidationEnabled,
252253
extraProperties: $extraProperties
253254
);
254255
}
@@ -607,19 +608,6 @@ public function withExceptionToStatus(array $exceptionToStatus): self
607608
return $self;
608609
}
609610

610-
public function getQueryParameterValidationEnabled(): ?bool
611-
{
612-
return $this->queryParameterValidationEnabled;
613-
}
614-
615-
public function withQueryParameterValidationEnabled(bool $queryParameterValidationEnabled): self
616-
{
617-
$self = clone $this;
618-
$self->queryParameterValidationEnabled = $queryParameterValidationEnabled;
619-
620-
return $self;
621-
}
622-
623611
public function getLinks(): ?array
624612
{
625613
return $this->links;

0 commit comments

Comments
 (0)