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

api-platform / core / 18223414080

03 Oct 2025 01:18PM UTC coverage: 0.0% (-22.0%) from 21.956%
18223414080

Pull #7397

github

web-flow
Merge 69d085182 into 0b8237918
Pull Request #7397: fix(jsonschema/jsonld): make `@id` and `@type` properties required only in the JSON-LD schema for output

0 of 18 new or added lines in 2 files covered. (0.0%)

12304 existing lines in 405 files now uncovered.

0 of 53965 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
        if ($parameter instanceof Link) {
×
UNCOV
93
            $uriVariables = $operation->getUriVariables();
×
UNCOV
94
            $uriVariables[$parameter->getKey()] = $parameter;
×
UNCOV
95
            $operation = $operation->withUriVariables($uriVariables);
×
96
        }
97

UNCOV
98
        return $operation;
×
99
    }
100

101
    /**
102
     * @return array<string, string>
103
     */
104
    private function getUriVariables(mixed $value, Parameter $parameter, Operation $operation): array
105
    {
UNCOV
106
        $extraProperties = $parameter->getExtraProperties();
×
107

UNCOV
108
        if ($operation instanceof HttpOperation) {
×
UNCOV
109
            $links = $operation->getUriVariables();
×
110
        } elseif ($operation instanceof GraphQlOperation) {
×
111
            $links = $operation->getLinks();
×
112
        } else {
113
            $links = [];
×
114
        }
115

UNCOV
116
        if (!\is_array($value)) {
×
UNCOV
117
            $uriVariables = [];
×
118

UNCOV
119
            foreach ($links as $key => $link) {
×
UNCOV
120
                if (!\is_string($key)) {
×
121
                    $key = $link->getParameterName() ?? $extraProperties['uri_variable'] ?? $link->getFromProperty();
×
122
                }
123

UNCOV
124
                if (!$key || !\is_string($key)) {
×
125
                    continue;
×
126
                }
127

UNCOV
128
                $uriVariables[$key] = $value;
×
129
            }
130

UNCOV
131
            return $uriVariables;
×
132
        }
133

UNCOV
134
        return $value;
×
135
    }
136
}
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