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

api-platform / core / 7196499749

13 Dec 2023 02:17PM UTC coverage: 37.359% (+1.4%) from 36.003%
7196499749

push

github

web-flow
ci: conflict sebastian/comparator (#6032)

* ci: conflict sebastian/comparator

* for lowest

10295 of 27557 relevant lines covered (37.36%)

28.14 hits per line

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

80.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\Serializer\ResourceList;
18
use ApiPlatform\Serializer\SerializerContextBuilderInterface;
19
use ApiPlatform\State\ProcessorInterface;
20
use Symfony\Component\HttpFoundation\Response;
21
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
22
use Symfony\Component\Serializer\SerializerInterface;
23
use Symfony\Component\WebLink\GenericLinkProvider;
24
use Symfony\Component\WebLink\Link;
25

26
/**
27
 * Serializes data.
28
 *
29
 * @author Kévin Dunglas <dunglas@gmail.com>
30
 */
31
final class SerializeProcessor implements ProcessorInterface
32
{
33
    public function __construct(private readonly ProcessorInterface $processor, private readonly SerializerInterface $serializer, private readonly SerializerContextBuilderInterface $serializerContextBuilder)
34
    {
35
    }
85✔
36

37
    public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = [])
38
    {
39
        if ($data instanceof Response || !$operation->canSerialize() || !($request = $context['request'] ?? null)) {
82✔
40
            return $this->processor->process($data, $operation, $uriVariables, $context);
20✔
41
        }
42

43
        // @see ApiPlatform\State\Processor\RespondProcessor
44
        $context['original_data'] = $data;
62✔
45

46
        $serializerContext = $this->serializerContextBuilder->createFromRequest($request, true, [
62✔
47
            'resource_class' => $operation->getClass(),
62✔
48
            'operation' => $operation,
62✔
49
        ]);
62✔
50

51
        $serializerContext['uri_variables'] = $uriVariables;
62✔
52

53
        if (isset($serializerContext['output']) && \array_key_exists('class', $serializerContext['output']) && null === $serializerContext['output']['class']) {
62✔
54
            return $this->processor->process(null, $operation, $uriVariables, $context);
×
55
        }
56

57
        $resources = new ResourceList();
62✔
58
        $serializerContext['resources'] = &$resources;
62✔
59
        $serializerContext[AbstractObjectNormalizer::EXCLUDE_FROM_CACHE_KEY][] = 'resources';
62✔
60

61
        $resourcesToPush = new ResourceList();
62✔
62
        $serializerContext['resources_to_push'] = &$resourcesToPush;
62✔
63
        $serializerContext[AbstractObjectNormalizer::EXCLUDE_FROM_CACHE_KEY][] = 'resources_to_push';
62✔
64

65
        $serialized = $this->serializer->serialize($data, $request->getRequestFormat(), $serializerContext);
62✔
66
        $request->attributes->set('_resources', $request->attributes->get('_resources', []) + (array) $resources);
62✔
67
        if (\count($resourcesToPush)) {
62✔
68
            $linkProvider = $request->attributes->get('_api_platform_links', new GenericLinkProvider());
×
69
            foreach ($resourcesToPush as $resourceToPush) {
×
70
                $linkProvider = $linkProvider->withLink((new Link('preload', $resourceToPush))->withAttribute('as', 'fetch'));
×
71
            }
72
            $request->attributes->set('_api_platform_links', $linkProvider);
×
73
        }
74

75
        return $this->processor->process($serialized, $operation, $uriVariables, $context);
62✔
76
    }
77
}
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

© 2026 Coveralls, Inc