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

api-platform / core / 14955007251

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

Pull #7135

github

web-flow
Merge 8a231af70 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/Symfony/Security/State/LinkedReadProvider.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\Security\State;
15

16
use ApiPlatform\Metadata\Exception\InvalidIdentifierException;
17
use ApiPlatform\Metadata\Exception\InvalidUriVariableException;
18
use ApiPlatform\Metadata\HttpOperation;
19
use ApiPlatform\Metadata\Link;
20
use ApiPlatform\Metadata\Operation;
21
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
22
use ApiPlatform\State\Exception\ProviderNotFoundException;
23
use ApiPlatform\State\ProviderInterface;
24
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
25

26
/**
27
 * Checks if the linked resources have security attributes and prepares them for access checking.
28
 *
29
 * @experimental
30
 */
31
final class LinkedReadProvider implements ProviderInterface
32
{
33
    public function __construct(
34
        private readonly ProviderInterface $decorated,
35
        private readonly ProviderInterface $locator,
36
        private readonly ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory,
37
    ) {
UNCOV
38
    }
×
39

40
    public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
41
    {
UNCOV
42
        $data = $this->decorated->provide($operation, $uriVariables, $context);
×
43

UNCOV
44
        if (!$operation instanceof HttpOperation) {
×
45
            return $data;
×
46
        }
47

UNCOV
48
        $request = ($context['request'] ?? null);
×
49

UNCOV
50
        if ($operation->getUriVariables()) {
×
UNCOV
51
            foreach ($operation->getUriVariables() as $key => $uriVariable) {
×
UNCOV
52
                if (!$uriVariable instanceof Link || !$uriVariable->getSecurity()) {
×
UNCOV
53
                    continue;
×
54
                }
55

56
                $relationClass = $uriVariable->getFromClass() ?? $uriVariable->getToClass();
×
57

58
                if (!$relationClass) {
×
59
                    continue;
×
60
                }
61

62
                $parentOperation = $this->resourceMetadataCollectionFactory
×
63
                    ->create($relationClass)
×
64
                    ->getOperation($operation->getExtraProperties()['parent_uri_template'] ?? null);
×
65
                try {
66
                    $relation = $this->locator->provide($parentOperation, [$uriVariable->getIdentifiers()[0] => $request?->attributes->all()[$key]], $context);
×
67
                } catch (ProviderNotFoundException) {
×
68
                    $relation = null;
×
69
                }
70

71
                if (!$relation) {
×
72
                    throw new NotFoundHttpException('Relation for link security not found.');
×
73
                }
74

75
                try {
76
                    $securityObjectName = $uriVariable->getSecurityObjectName();
×
77

78
                    if (!$securityObjectName) {
×
79
                        $securityObjectName = $uriVariable->getToProperty() ?? $uriVariable->getFromProperty();
×
80
                    }
81

82
                    $request?->attributes->set($securityObjectName, $relation);
×
83
                } catch (InvalidIdentifierException|InvalidUriVariableException $e) {
×
84
                    throw new NotFoundHttpException('Invalid identifier value or configuration.', $e);
×
85
                }
86
            }
87
        }
88

UNCOV
89
        return $data;
×
90
    }
91
}
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