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

api-platform / core / 15778454820

20 Jun 2025 12:00PM UTC coverage: 22.065%. Remained the same
15778454820

Pull #7237

github

web-flow
Merge 48863f2d5 into 42f0ce79f
Pull Request #7237: ci: bump lowest dependencies

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

125 existing lines in 11 files now uncovered.

11487 of 52060 relevant lines covered (22.06%)

21.72 hits per line

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

95.83
/src/Symfony/EventListener/ReadListener.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\EventListener;
15

16
use ApiPlatform\Metadata\Exception\InvalidIdentifierException;
17
use ApiPlatform\Metadata\Exception\InvalidUriVariableException;
18
use ApiPlatform\Metadata\HttpOperation;
19
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
20
use ApiPlatform\Metadata\UriVariablesConverterInterface;
21
use ApiPlatform\Metadata\Util\CloneTrait;
22
use ApiPlatform\State\ProviderInterface;
23
use ApiPlatform\State\UriVariablesResolverTrait;
24
use ApiPlatform\State\Util\OperationRequestInitiatorTrait;
25
use ApiPlatform\State\Util\RequestAttributesExtractor;
26
use Symfony\Component\HttpKernel\Event\RequestEvent;
27
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
28

29
/**
30
 * Retrieves data from the applicable data provider and sets it as a request parameter called data.
31
 *
32
 * @author Kévin Dunglas <dunglas@gmail.com>
33
 */
34
final class ReadListener
35
{
36
    use CloneTrait;
37
    use OperationRequestInitiatorTrait;
38
    use UriVariablesResolverTrait;
39

40
    /**
41
     * @param ProviderInterface<object> $provider
42
     */
43
    public function __construct(
44
        private readonly ProviderInterface $provider,
45
        ?ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory = null,
46
        ?UriVariablesConverterInterface $uriVariablesConverter = null,
47
        private readonly ?ProviderInterface $parameterProvider = null,
48
    ) {
UNCOV
49
        $this->resourceMetadataCollectionFactory = $resourceMetadataCollectionFactory;
251✔
UNCOV
50
        $this->uriVariablesConverter = $uriVariablesConverter;
251✔
51
    }
52

53
    /**
54
     * Calls the data provider and sets the data attribute.
55
     *
56
     * @throws NotFoundHttpException
57
     */
58
    public function onKernelRequest(RequestEvent $event): void
59
    {
UNCOV
60
        $request = $event->getRequest();
251✔
61

UNCOV
62
        if (!($attributes = RequestAttributesExtractor::extractAttributes($request)) || !$attributes['receive']) {
251✔
UNCOV
63
            return;
31✔
64
        }
65

UNCOV
66
        $operation = $this->initializeOperation($request);
223✔
UNCOV
67
        if (!$operation) {
223✔
68
            return;
×
69
        }
70

UNCOV
71
        if (null === $operation->canRead()) {
223✔
UNCOV
72
            $operation = $operation->withRead($operation->getUriVariables() || $request->isMethodSafe());
222✔
73
        }
74

UNCOV
75
        $uriVariables = [];
223✔
UNCOV
76
        if (!$request->attributes->has('exception') && $operation instanceof HttpOperation) {
223✔
77
            try {
UNCOV
78
                $uriVariables = $this->getOperationUriVariables($operation, $request->attributes->all(), $operation->getClass());
221✔
UNCOV
79
            } catch (InvalidIdentifierException|InvalidUriVariableException $e) {
1✔
UNCOV
80
                if ($operation->canRead()) {
1✔
UNCOV
81
                    throw new NotFoundHttpException('Invalid identifier value or configuration.', $e);
1✔
82
                }
83
            }
84
        }
85

UNCOV
86
        $request->attributes->set('_api_uri_variables', $uriVariables);
223✔
UNCOV
87
        $context = [
223✔
UNCOV
88
            'request' => $request,
223✔
UNCOV
89
            'uri_variables' => $uriVariables,
223✔
UNCOV
90
            'resource_class' => $operation->getClass(),
223✔
UNCOV
91
        ];
223✔
UNCOV
92
        $this->parameterProvider?->provide($operation, $uriVariables, $context);
223✔
UNCOV
93
        $this->provider->provide($operation, $uriVariables, $context);
223✔
94
    }
95
}
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