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

api-platform / core / 17562281609

08 Sep 2025 07:47PM UTC coverage: 0.0% (-22.6%) from 22.604%
17562281609

Pull #7374

github

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

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

12082 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/Hal/Serializer/ObjectNormalizer.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\Hal\Serializer;
15

16
use ApiPlatform\Metadata\IriConverterInterface;
17
use Symfony\Component\Serializer\Exception\LogicException;
18
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
19
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
20

21
/**
22
 * Decorates the output with JSON HAL metadata when appropriate, but otherwise
23
 * just passes through to the decorated normalizer.
24
 */
25
final class ObjectNormalizer implements NormalizerInterface, DenormalizerInterface
26
{
27
    public const FORMAT = 'jsonhal';
28

29
    public function __construct(private readonly NormalizerInterface $decorated, private readonly IriConverterInterface $iriConverter)
30
    {
UNCOV
31
    }
×
32

33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
37
    {
UNCOV
38
        return self::FORMAT === $format && $this->decorated->supportsNormalization($data, $format, $context);
×
39
    }
40

41
    /**
42
     * @param string|null $format
43
     */
44
    public function getSupportedTypes($format): array
45
    {
UNCOV
46
        return self::FORMAT === $format ? $this->decorated->getSupportedTypes($format) : [];
×
47
    }
48

49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
53
    {
54
        if (isset($context['api_resource'])) {
×
55
            $originalResource = $context['api_resource'];
×
56
            unset($context['api_resource']);
×
57
        }
58

59
        $data = $this->decorated->normalize($object, $format, $context);
×
60
        if (!\is_array($data)) {
×
61
            return $data;
×
62
        }
63

64
        if (!isset($originalResource)) {
×
65
            return $data;
×
66
        }
67

68
        $metadata = [
×
69
            '_links' => [
×
70
                'self' => [
×
71
                    'href' => $this->iriConverter->getIriFromResource($originalResource),
×
72
                ],
×
73
            ],
×
74
        ];
×
75

76
        return $metadata + $data;
×
77
    }
78

79
    /**
80
     * {@inheritdoc}
81
     */
82
    public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []): bool
83
    {
84
        // prevent the use of lower priority normalizers (e.g. serializer.normalizer.object) for this format
UNCOV
85
        return self::FORMAT === $format;
×
86
    }
87

88
    /**
89
     * {@inheritdoc}
90
     *
91
     * @throws LogicException
92
     */
93
    public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed
94
    {
UNCOV
95
        throw new LogicException(\sprintf('%s is a read-only format.', self::FORMAT));
×
96
    }
97
}
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