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

api-platform / core / 20001323174

07 Dec 2025 08:10AM UTC coverage: 25.292% (+0.001%) from 25.291%
20001323174

push

github

soyuka
chore: bump metadata to 4.3.x-dev

14642 of 57891 relevant lines covered (25.29%)

28.94 hits per line

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

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

16
use ApiPlatform\Metadata\Exception\RuntimeException;
17
use ApiPlatform\Metadata\Operation;
18
use ApiPlatform\State\ParameterNotFound;
19
use ApiPlatform\State\ProviderInterface;
20
use Illuminate\Support\Facades\Validator;
21
use Illuminate\Validation\ValidationException;
22
use Symfony\Component\HttpFoundation\Request;
23

24
/**
25
 * Validates parameters using the Laravel validator.
26
 *
27
 * @implements ProviderInterface<object>
28
 *
29
 * @experimental
30
 */
31
final class ParameterValidatorProvider implements ProviderInterface
32
{
33
    use ValidationErrorTrait;
34

35
    /**
36
     * @param ProviderInterface<object> $decorated
37
     */
38
    public function __construct(
39
        private readonly ?ProviderInterface $decorated = null,
40
    ) {
41
    }
×
42

43
    public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
44
    {
45
        if (!($request = $context['request'] ?? null) instanceof Request) {
×
46
            return $this->decorated->provide($operation, $uriVariables, $context);
×
47
        }
48

49
        $operation = $request->attributes->get('_api_operation') ?? $operation;
×
50
        if (!($operation->getQueryParameterValidationEnabled() ?? true)) {
×
51
            return $this->decorated->provide($operation, $uriVariables, $context);
×
52
        }
53

54
        $allConstraints = [];
×
55

56
        foreach ($operation->getParameters() ?? [] as $parameter) {
×
57
            if (!$constraints = $parameter->getConstraints()) {
×
58
                continue;
×
59
            }
60

61
            $key = $parameter->getKey();
×
62
            if (null === $key) {
×
63
                throw new RuntimeException('A parameter must have a defined key.');
×
64
            }
65

66
            $value = $parameter->getValue();
×
67
            if ($value instanceof ParameterNotFound) {
×
68
                $value = null;
×
69
            }
70

71
            // Laravel Validator requires dot notation for nested rules (e.g., "sort.isActive"),
72
            // not nested arrays. We convert HTTP bracket syntax "sort[isActive]" to "sort.isActive".
73
            $ruleKey = str_replace(['[', ']'], ['.', ''], $key);
×
74

75
            $allConstraints[$ruleKey] = $constraints;
×
76
        }
77

78
        $validator = Validator::make($request->query->all(), $allConstraints);
×
79

80
        if ($validator->fails()) {
×
81
            throw $this->getValidationError($validator, new ValidationException($validator));
×
82
        }
83

84
        return $this->decorated->provide($operation, $uriVariables, $context);
×
85
    }
86
}
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