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

api-platform / core / 16531587208

25 Jul 2025 09:05PM UTC coverage: 0.0% (-22.1%) from 22.07%
16531587208

Pull #7225

github

web-flow
Merge 23f449a58 into 02a764950
Pull Request #7225: feat: json streamer

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

11514 existing lines in 375 files now uncovered.

0 of 51976 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/ParameterProvider/ReadLinkParameterProvider.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\ParameterProvider;
15

16
use ApiPlatform\Metadata\GraphQl\Operation as GraphQlOperation;
17
use ApiPlatform\Metadata\HttpOperation;
18
use ApiPlatform\Metadata\Link;
19
use ApiPlatform\Metadata\Operation;
20
use ApiPlatform\Metadata\Parameter;
21
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
22
use ApiPlatform\State\Exception\ProviderNotFoundException;
23
use ApiPlatform\State\ParameterProviderInterface;
24
use ApiPlatform\State\ProviderInterface;
25
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
26

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

43
    public function provide(Parameter $parameter, array $parameters = [], array $context = []): ?Operation
44
    {
UNCOV
45
        $operation = $context['operation'];
×
UNCOV
46
        $extraProperties = $parameter->getExtraProperties();
×
47

UNCOV
48
        if ($parameter instanceof Link) {
×
UNCOV
49
            $linkClass = $parameter->getFromClass() ?? $parameter->getToClass();
×
UNCOV
50
            $securityObjectName = $parameter->getSecurityObjectName() ?? $parameter->getToProperty() ?? $parameter->getFromProperty();
×
51
        }
52

UNCOV
53
        $securityObjectName ??= $parameter->getKey();
×
54

UNCOV
55
        $linkClass ??= $extraProperties['resource_class'] ?? $operation->getClass();
×
56

UNCOV
57
        if (!$linkClass) {
×
58
            return $operation;
×
59
        }
60

UNCOV
61
        $linkOperation = $this->resourceMetadataCollectionFactory
×
UNCOV
62
            ->create($linkClass)
×
UNCOV
63
            ->getOperation($operation->getExtraProperties()['parent_uri_template'] ?? $extraProperties['uri_template'] ?? null);
×
64

UNCOV
65
        $value = $parameter->getValue();
×
66

UNCOV
67
        if (\is_array($value) && array_is_list($value)) {
×
UNCOV
68
            $relation = [];
×
69

UNCOV
70
            foreach ($value as $v) {
×
71
                try {
UNCOV
72
                    $relation[] = $this->locator->provide($linkOperation, $this->getUriVariables($v, $parameter, $linkOperation), $context);
×
73
                } catch (ProviderNotFoundException) {
×
74
                }
75
            }
76
        } else {
77
            try {
UNCOV
78
                $relation = $this->locator->provide($linkOperation, $this->getUriVariables($value, $parameter, $linkOperation), $context);
×
79
            } catch (ProviderNotFoundException) {
×
80
                $relation = null;
×
81
            }
82
        }
83

UNCOV
84
        $parameter->setValue($relation);
×
85

UNCOV
86
        if (null === $relation && true === ($extraProperties['throw_not_found'] ?? true)) {
×
UNCOV
87
            throw new NotFoundHttpException('Relation for link security not found.');
×
88
        }
89

UNCOV
90
        $context['request']?->attributes->set($securityObjectName, $relation);
×
91

UNCOV
92
        return $operation;
×
93
    }
94

95
    /**
96
     * @return array<string, string>
97
     */
98
    private function getUriVariables(mixed $value, Parameter $parameter, Operation $operation): array
99
    {
UNCOV
100
        $extraProperties = $parameter->getExtraProperties();
×
101

UNCOV
102
        if ($operation instanceof HttpOperation) {
×
UNCOV
103
            $links = $operation->getUriVariables();
×
104
        } elseif ($operation instanceof GraphQlOperation) {
×
105
            $links = $operation->getLinks();
×
106
        } else {
107
            $links = [];
×
108
        }
109

UNCOV
110
        if (!\is_array($value)) {
×
UNCOV
111
            $uriVariables = [];
×
112

UNCOV
113
            foreach ($links as $key => $link) {
×
UNCOV
114
                if (!\is_string($key)) {
×
115
                    $key = $link->getParameterName() ?? $extraProperties['uri_variable'] ?? $link->getFromProperty();
×
116
                }
117

UNCOV
118
                if (!$key || !\is_string($key)) {
×
119
                    continue;
×
120
                }
121

UNCOV
122
                $uriVariables[$key] = $value;
×
123
            }
124

UNCOV
125
            return $uriVariables;
×
126
        }
127

UNCOV
128
        return $value;
×
129
    }
130
}
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