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

api-platform / core / 14954769666

11 May 2025 10:14AM UTC coverage: 0.0% (-8.5%) from 8.457%
14954769666

Pull #7135

github

web-flow
Merge bf21e0bc7 into 4dd0cdfc4
Pull Request #7135: fix(symfony,laravel): InvalidUriVariableException status code (e400)

0 of 2 new or added lines in 2 files covered. (0.0%)

11040 existing lines in 370 files now uncovered.

0 of 48303 relevant lines covered (0.0%)

0.0 hits per line

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

0.0
/src/State/Provider/ParameterProvider.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\State\Provider;
15

16
use ApiPlatform\Metadata\HttpOperation;
17
use ApiPlatform\Metadata\Operation;
18
use ApiPlatform\State\Exception\ParameterNotSupportedException;
19
use ApiPlatform\State\Exception\ProviderNotFoundException;
20
use ApiPlatform\State\ParameterNotFound;
21
use ApiPlatform\State\ProviderInterface;
22
use ApiPlatform\State\Util\ParameterParserTrait;
23
use ApiPlatform\State\Util\RequestParser;
24
use Psr\Container\ContainerInterface;
25

26
/**
27
 * Loops over parameters to:
28
 *   - compute its values set as extra properties from the Parameter object (`_api_values`)
29
 *   - call the Parameter::provider if any and updates the Operation
30
 *
31
 * @experimental
32
 */
33
final class ParameterProvider implements ProviderInterface
34
{
35
    use ParameterParserTrait;
36

37
    public function __construct(private readonly ?ProviderInterface $decorated = null, private readonly ?ContainerInterface $locator = null)
38
    {
UNCOV
39
    }
×
40

41
    public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
42
    {
UNCOV
43
        $request = $context['request'] ?? null;
×
UNCOV
44
        if ($request && null === $request->attributes->get('_api_query_parameters')) {
×
UNCOV
45
            $queryString = RequestParser::getQueryString($request);
×
UNCOV
46
            $request->attributes->set('_api_query_parameters', $queryString ? RequestParser::parseRequestParams($queryString) : []);
×
47
        }
48

UNCOV
49
        if ($request && null === $request->attributes->get('_api_header_parameters')) {
×
UNCOV
50
            $request->attributes->set('_api_header_parameters', $request->headers->all());
×
51
        }
52

UNCOV
53
        $parameters = $operation->getParameters();
×
54

UNCOV
55
        if ($operation instanceof HttpOperation && true === $operation->getStrictQueryParameterValidation()) {
×
UNCOV
56
            $keys = [];
×
UNCOV
57
            foreach ($parameters as $parameter) {
×
UNCOV
58
                $keys[] = $parameter->getKey();
×
59
            }
60

UNCOV
61
            foreach (array_keys($request->attributes->get('_api_query_parameters')) as $key) {
×
UNCOV
62
                if (!\in_array($key, $keys, true)) {
×
UNCOV
63
                    throw new ParameterNotSupportedException($key);
×
64
                }
65
            }
66
        }
67

UNCOV
68
        foreach ($parameters ?? [] as $parameter) {
×
UNCOV
69
            $extraProperties = $parameter->getExtraProperties();
×
UNCOV
70
            unset($extraProperties['_api_values']);
×
UNCOV
71
            $parameters->add($parameter->getKey(), $parameter = $parameter->withExtraProperties($extraProperties));
×
72

UNCOV
73
            $context = ['operation' => $operation] + $context;
×
UNCOV
74
            $values = $this->getParameterValues($parameter, $request, $context);
×
UNCOV
75
            $value = $this->extractParameterValues($parameter, $values);
×
76

UNCOV
77
            if (($default = $parameter->getSchema()['default'] ?? false) && ($value instanceof ParameterNotFound || !$value)) {
×
UNCOV
78
                $value = $default;
×
79
            }
80

UNCOV
81
            if ($value instanceof ParameterNotFound) {
×
UNCOV
82
                continue;
×
83
            }
84

UNCOV
85
            $parameters->add($parameter->getKey(), $parameter = $parameter->withExtraProperties(
×
UNCOV
86
                $parameter->getExtraProperties() + ['_api_values' => $value]
×
UNCOV
87
            ));
×
88

UNCOV
89
            if (null === ($provider = $parameter->getProvider())) {
×
UNCOV
90
                continue;
×
91
            }
92

UNCOV
93
            if (\is_callable($provider)) {
×
UNCOV
94
                if (($op = $provider($parameter, $values, $context)) instanceof Operation) {
×
UNCOV
95
                    $operation = $op;
×
96
                }
97

UNCOV
98
                continue;
×
99
            }
100

UNCOV
101
            if (\is_string($provider)) {
×
UNCOV
102
                if (!$this->locator->has($provider)) {
×
103
                    throw new ProviderNotFoundException(\sprintf('Provider "%s" not found on operation "%s"', $provider, $operation->getName()));
×
104
                }
105

UNCOV
106
                $provider = $this->locator->get($provider);
×
107
            }
108

UNCOV
109
            if (($op = $provider->provide($parameter, $values, $context)) instanceof Operation) {
×
UNCOV
110
                $operation = $op;
×
111
            }
112
        }
113

UNCOV
114
        if ($parameters) {
×
UNCOV
115
            $operation = $operation->withParameters($parameters);
×
116
        }
UNCOV
117
        $request?->attributes->set('_api_operation', $operation);
×
UNCOV
118
        $context['operation'] = $operation;
×
119

UNCOV
120
        return $this->decorated?->provide($operation, $uriVariables, $context);
×
121
    }
122
}
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