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

api-platform / core / 14635100171

24 Apr 2025 06:39AM UTC coverage: 8.271% (+0.02%) from 8.252%
14635100171

Pull #6904

github

web-flow
Merge c9cefd82e into a3e5e53ea
Pull Request #6904: feat(graphql): added support for graphql subscriptions to work for actions

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

1999 existing lines in 144 files now uncovered.

13129 of 158728 relevant lines covered (8.27%)

13.6 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
    }
1,004✔
39

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

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

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

50
        if ($operation->getUriVariables()) {
968✔
51
            foreach ($operation->getUriVariables() as $key => $uriVariable) {
371✔
52
                if (!$uriVariable instanceof Link || !$uriVariable->getSecurity()) {
371✔
53
                    continue;
367✔
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;
968✔
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