• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 7142557150

08 Dec 2023 02:28PM UTC coverage: 36.003% (-1.4%) from 37.36%
7142557150

push

github

web-flow
fix(jsonld): remove link to ApiDocumentation when doc is disabled (#6029)

0 of 1 new or added line in 1 file covered. (0.0%)

2297 existing lines in 182 files now uncovered.

9992 of 27753 relevant lines covered (36.0%)

147.09 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

57.14
/src/Symfony/EventListener/QueryParameterValidateListener.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
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\Symfony\EventListener;
15

16
use ApiPlatform\Api\QueryParameterValidator\QueryParameterValidator;
17
use ApiPlatform\Doctrine\Odm\State\Options as ODMOptions;
18
use ApiPlatform\Doctrine\Orm\State\Options;
19
use ApiPlatform\Metadata\CollectionOperationInterface;
20
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
21
use ApiPlatform\State\Util\OperationRequestInitiatorTrait;
22
use ApiPlatform\State\Util\RequestParser;
23
use ApiPlatform\Symfony\Util\RequestAttributesExtractor;
24
use Symfony\Component\HttpKernel\Event\RequestEvent;
25

26
/**
27
 * Validates query parameters depending on filter description.
28
 *
29
 * @author Julien Deniau <julien.deniau@mapado.com>
30
 */
31
final class QueryParameterValidateListener
32
{
33
    use OperationRequestInitiatorTrait;
34

35
    public const OPERATION_ATTRIBUTE_KEY = 'query_parameter_validate';
36

37
    public function __construct(private readonly QueryParameterValidator $queryParameterValidator, ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory = null)
38
    {
39
        $this->resourceMetadataCollectionFactory = $resourceMetadataCollectionFactory;
2,496✔
40
    }
41

42
    public function onKernelRequest(RequestEvent $event): void
43
    {
44
        $request = $event->getRequest();
2,496✔
45

46
        if (
47
            !$request->isMethodSafe()
2,496✔
48
            || !($attributes = RequestAttributesExtractor::extractAttributes($request))
2,496✔
49
            || 'GET' !== $request->getMethod()
2,496✔
50
            || $request->attributes->get('_api_platform_disable_listeners')
2,496✔
51
        ) {
52
            return;
1,398✔
53
        }
54

55
        $operation = $this->initializeOperation($request);
1,251✔
56
        if ('api_platform.symfony.main_controller' === $operation?->getController()) {
1,251✔
57
            return;
1,236✔
58
        }
59

60
        if (!($operation?->getQueryParameterValidationEnabled() ?? true) || !$operation instanceof CollectionOperationInterface) {
15✔
61
            return;
15✔
62
        }
63

UNCOV
64
        $queryString = RequestParser::getQueryString($request);
×
UNCOV
65
        $queryParameters = $queryString ? RequestParser::parseRequestParams($queryString) : [];
×
66

UNCOV
67
        $class = $attributes['resource_class'];
×
68

UNCOV
69
        if ($options = $operation->getStateOptions()) {
×
70
            if ($options instanceof Options && $options->getEntityClass()) {
×
71
                $class = $options->getEntityClass();
×
72
            }
73

74
            if ($options instanceof ODMOptions && $options->getDocumentClass()) {
×
75
                $class = $options->getDocumentClass();
×
76
            }
77
        }
78

UNCOV
79
        $this->queryParameterValidator->validateFilters($class, $operation->getFilters() ?? [], $queryParameters);
×
80
    }
81
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc