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

api-platform / core / 14635100171

24 Apr 2025 06:39AM UTC coverage: 8.271% (+0.02%) from 8.252%
14635100171

Pull #6904

github

web-flow
Merge c9cefd82e into a3e5e53ea
Pull Request #6904: feat(graphql): added support for graphql subscriptions to work for actions

0 of 73 new or added lines in 3 files covered. (0.0%)

1999 existing lines in 144 files now uncovered.

13129 of 158728 relevant lines covered (8.27%)

13.6 hits per line

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

84.62
/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 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
 * @template T1
30
 * @template T2
31
 *
32
 * @implements ProcessorInterface<T1, T2>
33
 *
34
 * @author Kévin Dunglas <dunglas@gmail.com>
35
 */
36
final class SerializeProcessor implements ProcessorInterface
37
{
38
    /**
39
     * @param ProcessorInterface<mixed, mixed>|null $processor
40
     */
41
    public function __construct(private readonly ?ProcessorInterface $processor, private readonly SerializerInterface $serializer, private readonly SerializerContextBuilderInterface $serializerContextBuilder)
42
    {
43
    }
985✔
44

45
    public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = [])
46
    {
47
        if ($data instanceof Response || !$operation->canSerialize() || !($request = $context['request'] ?? null)) {
978✔
48
            return $this->processor ? $this->processor->process($data, $operation, $uriVariables, $context) : $data;
25✔
49
        }
50

51
        // @see ApiPlatform\State\Processor\RespondProcessor
52
        $context['original_data'] = $data;
955✔
53

54
        $class = $operation->getClass();
955✔
55
        $serializerContext = $this->serializerContextBuilder->createFromRequest($request, true, [
955✔
56
            'resource_class' => $class,
955✔
57
            'operation' => $operation,
955✔
58
        ]);
955✔
59

60
        $serializerContext['uri_variables'] = $uriVariables;
955✔
61

62
        if (isset($serializerContext['output']) && \array_key_exists('class', $serializerContext['output']) && null === $serializerContext['output']['class']) {
955✔
UNCOV
63
            return $this->processor ? $this->processor->process(null, $operation, $uriVariables, $context) : null;
3✔
64
        }
65

66
        $resources = new ResourceList();
952✔
67
        $serializerContext['resources'] = &$resources;
952✔
68
        $serializerContext[AbstractObjectNormalizer::EXCLUDE_FROM_CACHE_KEY][] = 'resources';
952✔
69

70
        $resourcesToPush = new ResourceList();
952✔
71
        $serializerContext['resources_to_push'] = &$resourcesToPush;
952✔
72
        $serializerContext[AbstractObjectNormalizer::EXCLUDE_FROM_CACHE_KEY][] = 'resources_to_push';
952✔
73

74
        $serialized = $this->serializer->serialize($data, $request->getRequestFormat(), $serializerContext);
952✔
75
        $request->attributes->set('_resources', $request->attributes->get('_resources', []) + (array) $resources);
952✔
76
        if (\count($resourcesToPush)) {
952✔
77
            $linkProvider = $request->attributes->get('_api_platform_links', new GenericLinkProvider());
×
78
            foreach ($resourcesToPush as $resourceToPush) {
×
79
                $linkProvider = $linkProvider->withLink((new Link('preload', $resourceToPush))->withAttribute('as', 'fetch'));
×
80
            }
81
            $request->attributes->set('_api_platform_links', $linkProvider);
×
82
        }
83

84
        return $this->processor ? $this->processor->process($serialized, $operation, $uriVariables, $context) : $serialized;
952✔
85
    }
86
}
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