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

api-platform / core / 16530614392

25 Jul 2025 08:04PM UTC coverage: 22.07%. Remained the same
16530614392

push

github

web-flow
fix(symfony): explicitly set the target class when mapping entities to resources (#7311)

3 of 3 new or added lines in 2 files covered. (100.0%)

125 existing lines in 11 files now uncovered.

11573 of 52437 relevant lines covered (22.07%)

23.54 hits per line

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

92.86
/src/Symfony/EventListener/RespondListener.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\ProcessorInterface;
18
use ApiPlatform\State\Util\OperationRequestInitiatorTrait;
19
use ApiPlatform\State\Util\RequestAttributesExtractor;
20
use Symfony\Component\HttpFoundation\Response;
21
use Symfony\Component\HttpKernel\Event\ViewEvent;
22

23
/**
24
 * Builds the response object.
25
 *
26
 * @author Kévin Dunglas <dunglas@gmail.com>
27
 */
28
final class RespondListener
29
{
30
    use OperationRequestInitiatorTrait;
31

32
    /**
33
     * @param ProcessorInterface<mixed,Response> $processor
34
     */
35
    public function __construct(private readonly ProcessorInterface $processor, ?ResourceMetadataCollectionFactoryInterface $resourceMetadataFactory = null)
36
    {
UNCOV
37
        $this->resourceMetadataCollectionFactory = $resourceMetadataFactory;
237✔
38
    }
39

40
    /**
41
     * Creates a Response to send to the client according to the requested format.
42
     */
43
    public function onKernelView(ViewEvent $event): void
44
    {
UNCOV
45
        $request = $event->getRequest();
237✔
UNCOV
46
        $operation = $this->initializeOperation($request);
237✔
47

UNCOV
48
        $attributes = RequestAttributesExtractor::extractAttributes($request);
237✔
UNCOV
49
        if (!($attributes['respond'] ?? $request->attributes->getBoolean('_api_respond')) || !$operation) {
237✔
50
            return;
×
51
        }
52

UNCOV
53
        $uriVariables = $request->attributes->get('_api_uri_variables') ?? [];
237✔
UNCOV
54
        $response = $this->processor->process($event->getControllerResult(), $operation, $uriVariables, [
237✔
UNCOV
55
            'request' => $request,
237✔
UNCOV
56
            'uri_variables' => $uriVariables,
237✔
UNCOV
57
            'resource_class' => $operation->getClass(),
237✔
UNCOV
58
            'original_data' => $request->attributes->get('original_data'),
237✔
UNCOV
59
        ]);
237✔
60

UNCOV
61
        $event->setResponse($response);
237✔
62
    }
63
}
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