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

api-platform / core / 17496868802

05 Sep 2025 03:02PM UTC coverage: 22.604% (+0.05%) from 22.559%
17496868802

push

github

soyuka
fix(symfony): remove deprecation about jsonopenapi

12072 of 53406 relevant lines covered (22.6%)

26.38 hits per line

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

100.0
/src/Symfony/EventListener/JsonStreamerSerializeListener.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
 * Serializes data using JSON Streamer.
25
 *
26
 * @author Kévin Dunglas <dunglas@gmail.com>
27
 */
28
final class JsonStreamerSerializeListener
29
{
30
    use OperationRequestInitiatorTrait;
31

32
    /**
33
     * @param ProcessorInterface<mixed,Response> $jsonStreamerProcessor
34
     */
35
    public function __construct(private readonly ProcessorInterface $jsonStreamerProcessor, private readonly string $format, ?ResourceMetadataCollectionFactoryInterface $resourceMetadataFactory = null)
36
    {
37
        $this->resourceMetadataCollectionFactory = $resourceMetadataFactory;
268✔
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
    {
45
        $request = $event->getRequest();
268✔
46
        $operation = $this->initializeOperation($request);
268✔
47

48
        $attributes = RequestAttributesExtractor::extractAttributes($request);
268✔
49
        if (!($attributes['respond'] ?? $request->attributes->getBoolean('_api_respond')) || !$operation || !$operation->getJsonStream() || $this->format !== $request->getRequestFormat()) {
268✔
50
            return;
265✔
51
        }
52

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

61
        $event->setResponse($response);
6✔
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