Skip to content

Commit 4f59677

Browse files
aegypiussoyuka
andcommitted
feat(parametervalidator): create api-platform/parameter-validator component
Co-authored-by: Antoine Bluchet <[email protected]>
1 parent bbc99cf commit 4f59677

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+885
-114
lines changed

.commitlintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"jsonapi",
1717
"graphql",
1818
"openapi",
19+
"parametervalidator",
1920
"serializer",
2021
"jsonschema",
2122
"validation",

.github/workflows/ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
with:
2323
fetch-depth: 0
2424
- name: Run commitlint
25-
run: |
25+
run: |
2626
commit=$(gh api \
2727
/repos/${{ github.repository }}/pulls/${{github.event.number}}/commits \
2828
| jq -r '.[0].commit.message' \
@@ -197,11 +197,13 @@ jobs:
197197
- JsonSchema
198198
- OpenApi
199199
- Metadata
200+
- ParameterValidator
200201
- Elasticsearch
201202
- HttpCache
202203
- RamseyUuid
203204
- GraphQl
204205
- Serializer
206+
- Symfony
205207
fail-fast: false
206208
steps:
207209
- name: Checkout
@@ -1139,4 +1141,3 @@ jobs:
11391141
name: openapi-docs-php${{ matrix.php }}
11401142
path: build/out/openapi
11411143
continue-on-error: true
1142-

src/Api/QueryParameterValidator/QueryParameterValidator.php

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -13,63 +13,13 @@
1313

1414
namespace ApiPlatform\Api\QueryParameterValidator;
1515

16-
use ApiPlatform\Api\FilterLocatorTrait;
17-
use ApiPlatform\Api\QueryParameterValidator\Validator\ArrayItems;
18-
use ApiPlatform\Api\QueryParameterValidator\Validator\Bounds;
19-
use ApiPlatform\Api\QueryParameterValidator\Validator\Enum;
20-
use ApiPlatform\Api\QueryParameterValidator\Validator\Length;
21-
use ApiPlatform\Api\QueryParameterValidator\Validator\MultipleOf;
22-
use ApiPlatform\Api\QueryParameterValidator\Validator\Pattern;
23-
use ApiPlatform\Api\QueryParameterValidator\Validator\Required;
24-
use ApiPlatform\Exception\FilterValidationException;
25-
use Psr\Container\ContainerInterface;
16+
use ApiPlatform\ParameterValidator\ParameterValidator as NewQueryParameterValidator;
2617

2718
/**
2819
* Validates query parameters depending on filter description.
2920
*
30-
* @author Julien Deniau <[email protected]>
21+
* @deprecated use ApiPlatform\QueryParameterValidator\QueryParameterValidator instead
3122
*/
32-
class QueryParameterValidator
23+
class QueryParameterValidator extends NewQueryParameterValidator
3324
{
34-
use FilterLocatorTrait;
35-
36-
private array $validators;
37-
38-
public function __construct(ContainerInterface $filterLocator)
39-
{
40-
$this->setFilterLocator($filterLocator);
41-
42-
$this->validators = [
43-
new ArrayItems(),
44-
new Bounds(),
45-
new Enum(),
46-
new Length(),
47-
new MultipleOf(),
48-
new Pattern(),
49-
new Required(),
50-
];
51-
}
52-
53-
public function validateFilters(string $resourceClass, array $resourceFilters, array $queryParameters): void
54-
{
55-
$errorList = [];
56-
57-
foreach ($resourceFilters as $filterId) {
58-
if (!$filter = $this->getFilter($filterId)) {
59-
continue;
60-
}
61-
62-
foreach ($filter->getDescription($resourceClass) as $name => $data) {
63-
foreach ($this->validators as $validator) {
64-
if ($errors = $validator->validate($name, $data, $queryParameters)) {
65-
$errorList[] = $errors;
66-
}
67-
}
68-
}
69-
}
70-
71-
if ($errorList) {
72-
throw new FilterValidationException(array_merge(...$errorList));
73-
}
74-
}
7525
}

src/Api/QueryParameterValidator/Validator/ArrayItems.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313

1414
namespace ApiPlatform\Api\QueryParameterValidator\Validator;
1515

16+
use ApiPlatform\ParameterValidator\Validator\CheckFilterDeprecationsTrait;
17+
use ApiPlatform\ParameterValidator\Validator\ValidatorInterface;
18+
19+
/**
20+
* @deprecated use \ApiPlatform\ParameterValidator\Validator\ArrayItems instead
21+
*/
1622
final class ArrayItems implements ValidatorInterface
1723
{
1824
use CheckFilterDeprecationsTrait;

src/Api/QueryParameterValidator/Validator/Bounds.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313

1414
namespace ApiPlatform\Api\QueryParameterValidator\Validator;
1515

16+
use ApiPlatform\ParameterValidator\Validator\CheckFilterDeprecationsTrait;
17+
use ApiPlatform\ParameterValidator\Validator\ValidatorInterface;
18+
19+
/**
20+
* @deprecated use \ApiPlatform\ParameterValidator\Validator\Bounds instead
21+
*/
1622
final class Bounds implements ValidatorInterface
1723
{
1824
use CheckFilterDeprecationsTrait;

src/Api/QueryParameterValidator/Validator/Enum.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313

1414
namespace ApiPlatform\Api\QueryParameterValidator\Validator;
1515

16+
use ApiPlatform\ParameterValidator\Validator\CheckFilterDeprecationsTrait;
17+
use ApiPlatform\ParameterValidator\Validator\ValidatorInterface;
18+
19+
/**
20+
* @deprecated use \ApiPlatform\ParameterValidator\Validator\Enum instead
21+
*/
1622
final class Enum implements ValidatorInterface
1723
{
1824
use CheckFilterDeprecationsTrait;

src/Api/QueryParameterValidator/Validator/Length.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313

1414
namespace ApiPlatform\Api\QueryParameterValidator\Validator;
1515

16+
use ApiPlatform\ParameterValidator\Validator\CheckFilterDeprecationsTrait;
17+
use ApiPlatform\ParameterValidator\Validator\ValidatorInterface;
18+
19+
/**
20+
* @deprecated use \ApiPlatform\ParameterValidator\Validator\Length instead
21+
*/
1622
final class Length implements ValidatorInterface
1723
{
1824
use CheckFilterDeprecationsTrait;

src/Api/QueryParameterValidator/Validator/MultipleOf.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313

1414
namespace ApiPlatform\Api\QueryParameterValidator\Validator;
1515

16+
use ApiPlatform\ParameterValidator\Validator\CheckFilterDeprecationsTrait;
17+
use ApiPlatform\ParameterValidator\Validator\ValidatorInterface;
18+
19+
/**
20+
* @deprecated use \ApiPlatform\ParameterValidator\Validator\MultipleOf instead
21+
*/
1622
final class MultipleOf implements ValidatorInterface
1723
{
1824
use CheckFilterDeprecationsTrait;

src/Api/QueryParameterValidator/Validator/Pattern.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313

1414
namespace ApiPlatform\Api\QueryParameterValidator\Validator;
1515

16+
use ApiPlatform\ParameterValidator\Validator\CheckFilterDeprecationsTrait;
17+
use ApiPlatform\ParameterValidator\Validator\ValidatorInterface;
18+
19+
/**
20+
* @deprecated use \ApiPlatform\ParameterValidator\Validator\Pattern instead
21+
*/
1622
final class Pattern implements ValidatorInterface
1723
{
1824
use CheckFilterDeprecationsTrait;

src/Api/QueryParameterValidator/Validator/Required.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@
1313

1414
namespace ApiPlatform\Api\QueryParameterValidator\Validator;
1515

16+
use ApiPlatform\ParameterValidator\Validator\CheckFilterDeprecationsTrait;
17+
use ApiPlatform\ParameterValidator\Validator\ValidatorInterface;
1618
use ApiPlatform\State\Util\RequestParser;
1719

20+
/**
21+
* @deprecated use \ApiPlatform\ParameterValidator\Validator\Required instead
22+
*/
1823
final class Required implements ValidatorInterface
1924
{
2025
use CheckFilterDeprecationsTrait;

0 commit comments

Comments
 (0)