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

api-platform / core / 9881030386

10 Jul 2024 08:30PM UTC coverage: 64.71% (-0.03%) from 64.738%
9881030386

push

github

web-flow
feat(symfony): skip error handler (#6463)

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

187 existing lines in 30 files now uncovered.

11475 of 17733 relevant lines covered (64.71%)

68.98 hits per line

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

36.11
/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\Doctrine\Odm\State\Options as ODMOptions;
17
use ApiPlatform\Doctrine\Orm\State\Options;
18
use ApiPlatform\Metadata\HttpOperation;
19
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
20
use ApiPlatform\ParameterValidator\ParameterValidator;
21
use ApiPlatform\State\ProviderInterface;
22
use ApiPlatform\State\Util\OperationRequestInitiatorTrait;
23
use ApiPlatform\State\Util\RequestParser;
24
use ApiPlatform\Symfony\Util\RequestAttributesExtractor;
25
use Symfony\Component\HttpKernel\Event\RequestEvent;
26

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

36
    public const OPERATION_ATTRIBUTE_KEY = 'query_parameter_validate';
37
    private ?ParameterValidator $queryParameterValidator = null;
38
    private ?ProviderInterface $provider = null;
39

40
    public function __construct($queryParameterValidator, ?ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory = null)
41
    {
UNCOV
42
        if ($queryParameterValidator instanceof ProviderInterface) {
113✔
43
            $this->provider = $queryParameterValidator;
×
44
        } else {
UNCOV
45
            trigger_deprecation('api-platform/core', '3.3', 'Use a "%s" as first argument in "%s" instead of "%s".', ProviderInterface::class, self::class, ParameterValidator::class);
113✔
UNCOV
46
            $this->queryParameterValidator = $queryParameterValidator;
113✔
47
        }
48

UNCOV
49
        $this->resourceMetadataCollectionFactory = $resourceMetadataCollectionFactory;
113✔
50
    }
51

52
    public function onKernelRequest(RequestEvent $event): void
53
    {
UNCOV
54
        $request = $event->getRequest();
113✔
UNCOV
55
        $operation = $this->initializeOperation($request);
113✔
56

57
        if (
UNCOV
58
            !$request->isMethodSafe()
113✔
UNCOV
59
            || !($attributes = RequestAttributesExtractor::extractAttributes($request))
113✔
UNCOV
60
            || 'GET' !== $request->getMethod()
113✔
UNCOV
61
            || $request->attributes->get('_api_platform_disable_listeners')
113✔
62
        ) {
UNCOV
63
            return;
40✔
64
        }
65

UNCOV
66
        if ('api_platform.symfony.main_controller' === $operation?->getController()) {
91✔
UNCOV
67
            return;
91✔
68
        }
69

70
        if (!($operation->getExtraProperties()['use_legacy_parameter_validator'] ?? true)) {
×
71
            return;
×
72
        }
73

74
        if (!($operation?->getQueryParameterValidationEnabled() ?? true) || !$operation instanceof HttpOperation) {
×
75
            return;
×
76
        }
77

78
        if ($this->provider instanceof ProviderInterface) {
×
79
            if (null === $operation->getQueryParameterValidationEnabled()) {
×
80
                $operation = $operation->withQueryParameterValidationEnabled('GET' === $request->getMethod());
×
81
            }
82

83
            $this->provider->provide($operation, $request->attributes->get('_api_uri_variables') ?? [], [
×
84
                'request' => $request,
×
85
                'uri_variables' => $request->attributes->get('_api_uri_variables') ?? [],
×
86
                'resource_class' => $operation->getClass(),
×
87
            ]);
×
88

89
            return;
×
90
        }
91

92
        $queryString = RequestParser::getQueryString($request);
×
93
        $queryParameters = $queryString ? RequestParser::parseRequestParams($queryString) : [];
×
94

95
        $class = $attributes['resource_class'];
×
96

97
        if ($options = $operation->getStateOptions()) {
×
98
            if ($options instanceof Options && $options->getEntityClass()) {
×
99
                $class = $options->getEntityClass();
×
100
            }
101

102
            if ($options instanceof ODMOptions && $options->getDocumentClass()) {
×
103
                $class = $options->getDocumentClass();
×
104
            }
105
        }
106

107
        $this->queryParameterValidator->validateFilters($class, $operation->getFilters() ?? [], $queryParameters);
×
108
    }
109
}
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

© 2025 Coveralls, Inc