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

api-platform / core / 14967095168

12 May 2025 08:08AM UTC coverage: 22.155% (+13.7%) from 8.457%
14967095168

Pull #7135

github

web-flow
Merge 574a2b863 into 4dd0cdfc4
Pull Request #7135: fix(symfony,laravel): InvalidUriVariableException status code (e400)

1 of 2 new or added lines in 2 files covered. (50.0%)

120 existing lines in 12 files now uncovered.

10846 of 48956 relevant lines covered (22.15%)

10.12 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\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
    ) {
UNCOV
48
        $this->resourceMetadataCollectionFactory = $resourceMetadataCollectionFactory;
×
UNCOV
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
    {
UNCOV
59
        $request = $event->getRequest();
×
60

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

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

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

UNCOV
74
        $uriVariables = [];
×
UNCOV
75
        if (!$request->attributes->has('exception') && $operation instanceof HttpOperation) {
×
76
            try {
UNCOV
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

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