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

api-platform / core / 15681594877

16 Jun 2025 01:03PM UTC coverage: 21.908% (+0.03%) from 21.876%
15681594877

Pull #7213

github

web-flow
Merge 1b3ab0e56 into cff61eab8
Pull Request #7213: feat(metadata) Customize Resource & operations

39 of 101 new or added lines in 10 files covered. (38.61%)

123 existing lines in 11 files now uncovered.

11433 of 52186 relevant lines covered (21.91%)

20.97 hits per line

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

100.0
/src/Symfony/EventListener/AddFormatListener.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\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
17
use ApiPlatform\State\ProviderInterface;
18
use ApiPlatform\State\Util\OperationRequestInitiatorTrait;
19
use ApiPlatform\State\Util\RequestAttributesExtractor;
20
use Symfony\Component\HttpKernel\Event\RequestEvent;
21
use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException;
22
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
23

24
/**
25
 * Chooses the format to use according to the Accept header and supported formats.
26
 *
27
 * @author Kévin Dunglas <dunglas@gmail.com>
28
 */
29
final class AddFormatListener
30
{
31
    use OperationRequestInitiatorTrait;
32

33
    /**
34
     * @param ProviderInterface<object> $provider
35
     */
36
    public function __construct(
37
        private ProviderInterface $provider,
38
        ?ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory = null,
39
    ) {
UNCOV
40
        $this->resourceMetadataCollectionFactory = $resourceMetadataCollectionFactory;
241✔
41
    }
42

43
    /**
44
     * Sets the applicable format to the HttpFoundation Request.
45
     *
46
     * @throws NotFoundHttpException
47
     * @throws NotAcceptableHttpException
48
     */
49
    public function onKernelRequest(RequestEvent $event): void
50
    {
UNCOV
51
        $request = $event->getRequest();
241✔
UNCOV
52
        $operation = $this->initializeOperation($request);
241✔
UNCOV
53
        $attributes = RequestAttributesExtractor::extractAttributes($request);
241✔
UNCOV
54
        if (!($attributes['respond'] ?? $request->attributes->getBoolean('_api_respond')) || !$operation) {
241✔
UNCOV
55
            return;
30✔
56
        }
57

UNCOV
58
        $this->provider->provide($operation, $request->attributes->get('_api_uri_variables') ?? [], [
214✔
UNCOV
59
            'request' => $request,
214✔
UNCOV
60
            'uri_variables' => $request->attributes->get('_api_uri_variables') ?? [],
214✔
UNCOV
61
            'resource_class' => $operation->getClass(),
214✔
UNCOV
62
        ]);
214✔
63
    }
64
}
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