-
-
Notifications
You must be signed in to change notification settings - Fork 849
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
2,133 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the API Platform project. | ||
* | ||
* (c) Kévin Dunglas <dunglas@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ApiPlatform\Core\EventListener; | ||
|
||
use ApiPlatform\Core\Filter\QueryParameterValidator; | ||
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface; | ||
use ApiPlatform\Core\Util\RequestAttributesExtractor; | ||
use ApiPlatform\Core\Util\RequestParser; | ||
use Symfony\Component\HttpKernel\Event\GetResponseEvent; | ||
|
||
/** | ||
* Validates query parameters depending on filter description. | ||
* | ||
* @author Julien Deniau <julien.deniau@mapado.com> | ||
*/ | ||
final class QueryParameterValidateListener | ||
{ | ||
private $resourceMetadataFactory; | ||
|
||
private $queryParameterValidator; | ||
|
||
public function __construct(ResourceMetadataFactoryInterface $resourceMetadataFactory, QueryParameterValidator $queryParameterValidator) | ||
{ | ||
$this->resourceMetadataFactory = $resourceMetadataFactory; | ||
$this->queryParameterValidator = $queryParameterValidator; | ||
} | ||
|
||
public function onKernelRequest(GetResponseEvent $event) | ||
{ | ||
$request = $event->getRequest(); | ||
if ( | ||
!$request->isMethodSafe(false) | ||
|| !($attributes = RequestAttributesExtractor::extractAttributes($request)) | ||
|| !isset($attributes['collection_operation_name']) | ||
|| 'get' !== ($operationName = $attributes['collection_operation_name']) | ||
) { | ||
return; | ||
} | ||
$queryString = RequestParser::getQueryString($request); | ||
$queryParameters = $queryString ? RequestParser::parseRequestParams($queryString) : []; | ||
|
||
$resourceMetadata = $this->resourceMetadataFactory->create($attributes['resource_class']); | ||
$resourceFilters = $resourceMetadata->getCollectionOperationAttribute($operationName, 'filters', [], true); | ||
|
||
$this->queryParameterValidator->validateFilters($attributes['resource_class'], $resourceFilters, $queryParameters); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.