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

api-platform / core / 16531587208

25 Jul 2025 09:05PM UTC coverage: 0.0% (-22.1%) from 22.07%
16531587208

Pull #7225

github

web-flow
Merge 23f449a58 into 02a764950
Pull Request #7225: feat: json streamer

0 of 294 new or added lines in 31 files covered. (0.0%)

11514 existing lines in 375 files now uncovered.

0 of 51976 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/Provider/ObjectMapperProvider.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\Provider;
15

16
use ApiPlatform\Doctrine\Odm\State\Options as OdmOptions;
17
use ApiPlatform\Doctrine\Orm\State\Options;
18
use ApiPlatform\Metadata\Operation;
19
use ApiPlatform\Metadata\Util\CloneTrait;
20
use ApiPlatform\State\Pagination\ArrayPaginator;
21
use ApiPlatform\State\Pagination\PaginatorInterface;
22
use ApiPlatform\State\ProviderInterface;
23
use Symfony\Component\ObjectMapper\Attribute\Map;
24
use Symfony\Component\ObjectMapper\ObjectMapperInterface;
25

26
/**
27
 * @implements ProviderInterface<object>
28
 */
29
final class ObjectMapperProvider implements ProviderInterface
30
{
31
    use CloneTrait;
32

33
    /**
34
     * @param ProviderInterface<object> $decorated
35
     */
36
    public function __construct(
37
        private readonly ?ObjectMapperInterface $objectMapper,
38
        private readonly ProviderInterface $decorated,
39
    ) {
UNCOV
40
    }
×
41

42
    public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
43
    {
UNCOV
44
        $data = $this->decorated->provide($operation, $uriVariables, $context);
×
45

UNCOV
46
        if (!$this->objectMapper || !\is_object($data)) {
×
UNCOV
47
            return $data;
×
48
        }
49

UNCOV
50
        $request = $context['request'] ?? null;
×
UNCOV
51
        $entityClass = null;
×
UNCOV
52
        if (($options = $operation->getStateOptions()) && $options instanceof Options && $options->getEntityClass()) {
×
UNCOV
53
            $entityClass = $options->getEntityClass();
×
54
        }
55

UNCOV
56
        if (($options = $operation->getStateOptions()) && $options instanceof OdmOptions && $options->getDocumentClass()) {
×
57
            $entityClass = $options->getDocumentClass();
×
58
        }
59

UNCOV
60
        $entityClass ??= $data::class;
×
61

UNCOV
62
        if (!(new \ReflectionClass($entityClass))->getAttributes(Map::class)) {
×
UNCOV
63
            return $data;
×
64
        }
65

UNCOV
66
        if ($data instanceof PaginatorInterface) {
×
UNCOV
67
            $data = new ArrayPaginator(array_map(fn ($v) => $this->objectMapper->map($v, $operation->getClass()), iterator_to_array($data)), 0, \count($data));
×
68
        } else {
UNCOV
69
            $data = $this->objectMapper->map($data, $operation->getClass());
×
70
        }
71

UNCOV
72
        $request?->attributes->set('data', $data);
×
UNCOV
73
        $request?->attributes->set('previous_data', $this->clone($data));
×
74

UNCOV
75
        return $data;
×
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

© 2025 Coveralls, Inc