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

api-platform / core / 13724522058

07 Mar 2025 04:04PM UTC coverage: 8.175% (-0.3%) from 8.518%
13724522058

Pull #7005

github

web-flow
Merge 322407532 into 1e0bc9dc8
Pull Request #7005: fix(validation): deprecate string message for ValidationException con…

4 of 6 new or added lines in 1 file covered. (66.67%)

159 existing lines in 24 files now uncovered.

12839 of 157045 relevant lines covered (8.18%)

13.55 hits per line

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

77.78
/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
    ) {
38
    }
996✔
39

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

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

48
        $request = ($context['request'] ?? null);
964✔
49

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

UNCOV
56
                $relationClass = $uriVariable->getFromClass() ?? $uriVariable->getToClass();
9✔
57

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

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

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

75
                try {
UNCOV
76
                    $securityObjectName = $uriVariable->getSecurityObjectName();
8✔
77

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

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

89
        return $data;
964✔
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