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

api-platform / core / 18283705710

06 Oct 2025 02:10PM UTC coverage: 0.0% (-22.0%) from 21.956%
18283705710

Pull #7397

github

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

0 of 4 new or added lines in 1 file covered. (0.0%)

12313 existing lines in 405 files now uncovered.

0 of 56347 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/Provider/ReadProvider.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\Provider;
15

16
use ApiPlatform\Metadata\HttpOperation;
17
use ApiPlatform\Metadata\Operation;
18
use ApiPlatform\Metadata\Put;
19
use ApiPlatform\Metadata\Util\CloneTrait;
20
use ApiPlatform\State\Exception\ProviderNotFoundException;
21
use ApiPlatform\State\ProviderInterface;
22
use ApiPlatform\State\SerializerContextBuilderInterface;
23
use ApiPlatform\State\StopwatchAwareInterface;
24
use ApiPlatform\State\StopwatchAwareTrait;
25
use ApiPlatform\State\UriVariablesResolverTrait;
26
use ApiPlatform\State\Util\OperationRequestInitiatorTrait;
27
use ApiPlatform\State\Util\RequestParser;
28
use Psr\Log\LoggerInterface;
29
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
30

31
/**
32
 * Retrieves data from the applicable data provider, based on the current IRI, and sets it as a request parameter called data.
33
 *
34
 * @author Kévin Dunglas <dunglas@gmail.com>
35
 */
36
final class ReadProvider implements ProviderInterface, StopwatchAwareInterface
37
{
38
    use CloneTrait;
39
    use OperationRequestInitiatorTrait;
40
    use StopwatchAwareTrait;
41
    use UriVariablesResolverTrait;
42

43
    public function __construct(
44
        private readonly ProviderInterface $provider,
45
        private readonly ?SerializerContextBuilderInterface $serializerContextBuilder = null,
46
        private readonly ?LoggerInterface $logger = null,
47
    ) {
UNCOV
48
    }
×
49

50
    public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
51
    {
UNCOV
52
        if (!$operation instanceof HttpOperation) {
×
53
            return null;
×
54
        }
55

UNCOV
56
        $request = ($context['request'] ?? null);
×
UNCOV
57
        if (!$operation->canRead()) {
×
UNCOV
58
            return null;
×
59
        }
60

UNCOV
61
        $this->stopwatch?->start('api_platform.provider.read');
×
62

UNCOV
63
        if (null === ($filters = $request?->attributes->get('_api_filters')) && $request) {
×
UNCOV
64
            $queryString = RequestParser::getQueryString($request);
×
UNCOV
65
            $filters = $queryString ? RequestParser::parseRequestParams($queryString) : null;
×
66
        }
67

UNCOV
68
        if ($filters) {
×
UNCOV
69
            $context['filters'] = $filters;
×
70
        }
71

UNCOV
72
        $resourceClass = $operation->getClass();
×
73

UNCOV
74
        if ($this->serializerContextBuilder && $request) {
×
75
            // Builtin data providers are able to use the serialization context to automatically add join clauses
UNCOV
76
            $context += $normalizationContext = $this->serializerContextBuilder->createFromRequest($request, true, [
×
UNCOV
77
                'resource_class' => $resourceClass,
×
UNCOV
78
                'operation' => $operation,
×
UNCOV
79
            ]);
×
UNCOV
80
            $request->attributes->set('_api_normalization_context', $normalizationContext);
×
81
        }
82

83
        try {
UNCOV
84
            $data = $this->provider->provide($operation, $uriVariables, $context);
×
UNCOV
85
        } catch (ProviderNotFoundException $e) {
×
86
            // In case the dev just forgot to implement it
87
            $this->logger?->debug('No provider registered for {resource_class}', ['resource_class' => $resourceClass]);
×
88
            $data = null;
×
89
        }
90

91
        if (
UNCOV
92
            null === $data
×
UNCOV
93
            && 'POST' !== $operation->getMethod()
×
UNCOV
94
            && ('PUT' !== $operation->getMethod()
×
UNCOV
95
                || ($operation instanceof Put && !($operation->getAllowCreate() ?? false))
×
96
            )
97
        ) {
UNCOV
98
            throw new NotFoundHttpException('Not Found', $e ?? null);
×
99
        }
100

UNCOV
101
        $request?->attributes->set('data', $data);
×
UNCOV
102
        $request?->attributes->set('previous_data', $this->clone($data));
×
103

UNCOV
104
        $this->stopwatch?->stop('api_platform.provider.read');
×
105

UNCOV
106
        return $data;
×
107
    }
108
}
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