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

api-platform / core / 18338852783

08 Oct 2025 08:37AM UTC coverage: 24.561% (+0.001%) from 24.56%
18338852783

push

github

web-flow
fix(symfony): ensure the kernel is booted before using `KernelBrowser::loginUser()` (#7446)

1 of 1 new or added line in 1 file covered. (100.0%)

329 existing lines in 15 files now uncovered.

14003 of 57012 relevant lines covered (24.56%)

26.03 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\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
19
use ApiPlatform\Metadata\UriVariablesConverterInterface;
20
use ApiPlatform\Metadata\Util\CloneTrait;
21
use ApiPlatform\State\ProviderInterface;
22
use ApiPlatform\State\UriVariablesResolverTrait;
23
use ApiPlatform\State\Util\OperationRequestInitiatorTrait;
24
use ApiPlatform\State\Util\RequestAttributesExtractor;
25
use Symfony\Component\HttpKernel\Event\RequestEvent;
26
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
27

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

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

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

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

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

UNCOV
70
        if (null === $operation->canRead()) {
301✔
UNCOV
71
            $operation = $operation->withRead($operation->getUriVariables() || $request->isMethodSafe());
300✔
72
        }
73

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

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