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

api-platform / core / 17581213192

09 Sep 2025 11:31AM UTC coverage: 0.0% (-22.6%) from 22.604%
17581213192

Pull #7374

github

web-flow
Merge 0f1360e1a into 6db55be8c
Pull Request #7374: fix(jsonld): various json streamer fixes

0 of 34 new or added lines in 2 files covered. (0.0%)

12081 existing lines in 401 files now uncovered.

0 of 52792 relevant lines covered (0.0%)

0.0 hits per line

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

0.0
/src/State/Processor/SerializeProcessor.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\State\Processor;
15

16
use ApiPlatform\Metadata\Operation;
17
use ApiPlatform\State\ProcessorInterface;
18
use ApiPlatform\State\ResourceList;
19
use ApiPlatform\State\SerializerContextBuilderInterface;
20
use ApiPlatform\State\StopwatchAwareInterface;
21
use ApiPlatform\State\StopwatchAwareTrait;
22
use Symfony\Component\HttpFoundation\Response;
23
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
24
use Symfony\Component\Serializer\SerializerInterface;
25
use Symfony\Component\WebLink\GenericLinkProvider;
26
use Symfony\Component\WebLink\Link;
27

28
/**
29
 * Serializes data.
30
 *
31
 * @template T1
32
 * @template T2
33
 *
34
 * @implements ProcessorInterface<T1, T2>
35
 *
36
 * @author Kévin Dunglas <dunglas@gmail.com>
37
 */
38
final class SerializeProcessor implements ProcessorInterface, StopwatchAwareInterface
39
{
40
    use StopwatchAwareTrait;
41

42
    /**
43
     * @param ProcessorInterface<mixed, mixed>|null $processor
44
     */
45
    public function __construct(
46
        private readonly ?ProcessorInterface $processor,
47
        private readonly SerializerInterface $serializer,
48
        private readonly SerializerContextBuilderInterface $serializerContextBuilder,
49
    ) {
UNCOV
50
    }
×
51

52
    public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = [])
53
    {
UNCOV
54
        if ($data instanceof Response || !$operation->canSerialize() || !($request = $context['request'] ?? null)) {
×
UNCOV
55
            return $this->processor ? $this->processor->process($data, $operation, $uriVariables, $context) : $data;
×
56
        }
57

UNCOV
58
        $this->stopwatch?->start('api_platform.processor.serialize');
×
59

60
        // @see ApiPlatform\State\Processor\RespondProcessor
UNCOV
61
        $context['original_data'] = $data;
×
62

UNCOV
63
        $class = $operation->getClass();
×
UNCOV
64
        $serializerContext = $this->serializerContextBuilder->createFromRequest($request, true, [
×
UNCOV
65
            'resource_class' => $class,
×
UNCOV
66
            'operation' => $operation,
×
UNCOV
67
        ]);
×
68

UNCOV
69
        $serializerContext['uri_variables'] = $uriVariables;
×
70

UNCOV
71
        if (isset($serializerContext['output']) && \array_key_exists('class', $serializerContext['output']) && null === $serializerContext['output']['class']) {
×
72
            $this->stopwatch?->stop('api_platform.processor.serialize');
×
73

74
            return $this->processor ? $this->processor->process(null, $operation, $uriVariables, $context) : null;
×
75
        }
76

UNCOV
77
        $resources = new ResourceList();
×
UNCOV
78
        $serializerContext['resources'] = &$resources;
×
UNCOV
79
        $serializerContext[AbstractObjectNormalizer::EXCLUDE_FROM_CACHE_KEY][] = 'resources';
×
80

UNCOV
81
        $resourcesToPush = new ResourceList();
×
UNCOV
82
        $serializerContext['resources_to_push'] = &$resourcesToPush;
×
UNCOV
83
        $serializerContext[AbstractObjectNormalizer::EXCLUDE_FROM_CACHE_KEY][] = 'resources_to_push';
×
84

UNCOV
85
        $serialized = $this->serializer->serialize($data, $request->getRequestFormat(), $serializerContext);
×
UNCOV
86
        $request->attributes->set('_resources', $request->attributes->get('_resources', []) + (array) $resources);
×
UNCOV
87
        if (\count($resourcesToPush)) {
×
88
            $linkProvider = $request->attributes->get('_api_platform_links', new GenericLinkProvider());
×
89
            foreach ($resourcesToPush as $resourceToPush) {
×
90
                $linkProvider = $linkProvider->withLink((new Link('preload', $resourceToPush))->withAttribute('as', 'fetch'));
×
91
            }
92
            $request->attributes->set('_api_platform_links', $linkProvider);
×
93
        }
94

UNCOV
95
        $this->stopwatch?->stop('api_platform.processor.serialize');
×
96

UNCOV
97
        return $this->processor ? $this->processor->process($serialized, $operation, $uriVariables, $context) : $serialized;
×
98
    }
99
}
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