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

api-platform / core / 17792263445

17 Sep 2025 08:54AM UTC coverage: 21.693% (-0.2%) from 21.902%
17792263445

push

github

soyuka
feat(state): remove @internal from the CreateProvider

fixes https://github.com/api-platform/api-platform/issues/571

11753 of 54178 relevant lines covered (21.69%)

12.64 hits per line

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

0.0
/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
    ) {
48
        $this->resourceMetadataCollectionFactory = $resourceMetadataCollectionFactory;
×
49
        $this->uriVariablesConverter = $uriVariablesConverter;
×
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
    {
59
        $request = $event->getRequest();
×
60

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

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

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

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

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