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

api-platform / core / 15778454820

20 Jun 2025 12:00PM UTC coverage: 22.065%. Remained the same
15778454820

Pull #7237

github

web-flow
Merge 48863f2d5 into 42f0ce79f
Pull Request #7237: ci: bump lowest dependencies

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

125 existing lines in 11 files now uncovered.

11487 of 52060 relevant lines covered (22.06%)

21.72 hits per line

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

100.0
/src/Symfony/EventListener/DeserializeListener.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\HttpOperation;
17
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
18
use ApiPlatform\State\ProviderInterface;
19
use ApiPlatform\State\SerializerContextBuilderInterface;
20
use ApiPlatform\State\Util\OperationRequestInitiatorTrait;
21
use ApiPlatform\State\Util\RequestAttributesExtractor;
22
use Symfony\Component\HttpKernel\Event\RequestEvent;
23
use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException;
24

25
/**
26
 * Updates the entity retrieved by the data provider with data contained in the request body.
27
 *
28
 * @author Kévin Dunglas <dunglas@gmail.com>
29
 */
30
final class DeserializeListener
31
{
32
    use OperationRequestInitiatorTrait;
33

34
    public const OPERATION_ATTRIBUTE_KEY = 'deserialize';
35

36
    /**
37
     * @param ProviderInterface<object> $provider
38
     */
39
    public function __construct(
40
        private ProviderInterface $provider,
41
        ?ResourceMetadataCollectionFactoryInterface $resourceMetadataFactory = null,
42
    ) {
UNCOV
43
        $this->resourceMetadataCollectionFactory = $resourceMetadataFactory;
251✔
44
    }
45

46
    /**
47
     * Deserializes the data sent in the requested format.
48
     *
49
     * @throws UnsupportedMediaTypeHttpException
50
     */
51
    public function onKernelRequest(RequestEvent $event): void
52
    {
UNCOV
53
        $request = $event->getRequest();
251✔
UNCOV
54
        $method = $request->getMethod();
251✔
UNCOV
55
        $operation = $this->initializeOperation($request);
251✔
56

57
        if (
UNCOV
58
            !($attributes = RequestAttributesExtractor::extractAttributes($request))
251✔
UNCOV
59
            || !$attributes['receive']
251✔
UNCOV
60
            || !$operation
251✔
61
        ) {
UNCOV
62
            return;
31✔
63
        }
64

UNCOV
65
        if (null === $operation->canDeserialize() && $operation instanceof HttpOperation) {
222✔
UNCOV
66
            $operation = $operation->withDeserialize(\in_array($method, ['POST', 'PUT', 'PATCH'], true));
222✔
67
        }
68

UNCOV
69
        $denormalizationContext = $operation->getDenormalizationContext() ?? [];
222✔
UNCOV
70
        if ($operation->canDeserialize() && !isset($denormalizationContext[SerializerContextBuilderInterface::ASSIGN_OBJECT_TO_POPULATE])) {
222✔
UNCOV
71
            $method = $operation->getMethod();
8✔
UNCOV
72
            $assignObjectToPopulate = 'POST' === $method
8✔
UNCOV
73
                || 'PATCH' === $method
8✔
UNCOV
74
                || ('PUT' === $method && !($operation->getExtraProperties()['standard_put'] ?? true));
8✔
75

UNCOV
76
            $operation = $operation->withDenormalizationContext($denormalizationContext + [SerializerContextBuilderInterface::ASSIGN_OBJECT_TO_POPULATE => $assignObjectToPopulate]);
8✔
77
        }
78

UNCOV
79
        if (!$operation->canDeserialize()) {
222✔
UNCOV
80
            return;
217✔
81
        }
82

UNCOV
83
        $data = $this->provider->provide($operation, $request->attributes->get('_api_uri_variables') ?? [], [
8✔
UNCOV
84
            'request' => $request,
8✔
UNCOV
85
            'uri_variables' => $request->attributes->get('_api_uri_variables') ?? [],
8✔
UNCOV
86
            'resource_class' => $operation->getClass(),
8✔
UNCOV
87
        ]);
8✔
88

UNCOV
89
        $request->attributes->set('data', $data);
6✔
90
    }
91
}
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