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

api-platform / core / 12691826531

09 Jan 2025 02:22PM UTC coverage: 61.963% (-0.2%) from 62.121%
12691826531

push

github

web-flow
 chore: add missing deprecation notices to ParameterValidator  (#6655)

Co-authored-by: soyuka <soyuka@users.noreply.github.com>

2 of 11 new or added lines in 11 files covered. (18.18%)

25 existing lines in 4 files now uncovered.

11475 of 18519 relevant lines covered (61.96%)

68.04 hits per line

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

0.0
/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
 * @deprecated
33
 */
34
final class QueryParameterValidateListener
35
{
36
    use OperationRequestInitiatorTrait;
37

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

42
    public function __construct($queryParameterValidator, ?ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory = null)
43
    {
UNCOV
44
        if ($queryParameterValidator instanceof ProviderInterface) {
×
45
            $this->provider = $queryParameterValidator;
×
46
        } else {
UNCOV
47
            $this->queryParameterValidator = $queryParameterValidator;
×
48
        }
49

UNCOV
50
        $this->resourceMetadataCollectionFactory = $resourceMetadataCollectionFactory;
×
51
    }
52

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

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

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

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

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

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

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

90
            return;
×
91
        }
92

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

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

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

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

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