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

api-platform / core / 17581213192

09 Sep 2025 11:31AM UTC coverage: 0.0% (-22.6%) from 22.604%
17581213192

Pull #7374

github

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

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

12081 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/JsonLd/JsonStreamer/WritePropertyMetadataLoader.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\JsonLd\JsonStreamer;
15

16
use ApiPlatform\Hydra\Collection;
17
use ApiPlatform\Hydra\IriTemplate;
18
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
19
use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
20
use ApiPlatform\Metadata\ResourceClassResolverInterface;
21
use ApiPlatform\Metadata\Util\TypeHelper;
22
use Symfony\Component\JsonStreamer\Mapping\PropertyMetadata;
23
use Symfony\Component\JsonStreamer\Mapping\PropertyMetadataLoaderInterface;
24
use Symfony\Component\TypeInfo\Type;
25

26
final class WritePropertyMetadataLoader implements PropertyMetadataLoaderInterface
27
{
28
    public function __construct(
29
        private readonly PropertyMetadataLoaderInterface $loader,
30
        private readonly ResourceClassResolverInterface $resourceClassResolver,
31
        private readonly PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory,
32
        private readonly PropertyMetadataFactoryInterface $propertyMetadataFactory,
33
    ) {
UNCOV
34
    }
×
35

36
    public function load(string $className, array $options = [], array $context = []): array
37
    {
UNCOV
38
        $properties = $this->loader->load($className, $options, $context);
×
39

UNCOV
40
        if (IriTemplate::class === $className) {
×
UNCOV
41
            $properties['template'] = new PropertyMetadata(
×
UNCOV
42
                'template',
×
UNCOV
43
                Type::string(),
×
UNCOV
44
                ['api_platform.hydra.json_streamer.write.value_transformer.template'],
×
UNCOV
45
            );
×
46

UNCOV
47
            return $properties;
×
48
        }
49

UNCOV
50
        if (Collection::class !== $className && !$this->resourceClassResolver->isResourceClass($className)) {
×
UNCOV
51
            return $properties;
×
52
        }
53

NEW
54
        $originalClassName = TypeHelper::getClassName($context['original_type']);
×
NEW
55
        $hasIri = true;
×
NEW
56
        $virtualProperty = 'id';
×
57

NEW
58
        if ($className !== $originalClassName) {
×
NEW
59
            foreach ($this->propertyNameCollectionFactory->create($originalClassName) as $property) {
×
NEW
60
                $propertyMetadata = $this->propertyMetadataFactory->create($originalClassName, $property);
×
NEW
61
                if ($propertyMetadata->isIdentifier()) {
×
NEW
62
                    $virtualProperty = $property;
×
63
                }
64

NEW
65
                if ($propertyMetadata->getNativeType()->isIdentifiedBy($className)) {
×
NEW
66
                    $hasIri = $propertyMetadata->getGenId();
×
NEW
67
                    $virtualProperty = iterator_to_array($this->propertyNameCollectionFactory->create($className))[0];
×
68
                }
69
            }
70
        }
71

NEW
72
        if ($hasIri) {
×
NEW
73
            $properties['@id'] = new PropertyMetadata(
×
NEW
74
                $virtualProperty, // virtual property
×
NEW
75
                Type::mixed(), // virtual property
×
NEW
76
                ['api_platform.jsonld.json_streamer.write.value_transformer.iri'],
×
NEW
77
            );
×
78
        }
79

UNCOV
80
        $properties['@type'] = new PropertyMetadata(
×
NEW
81
            $virtualProperty, // virtual property
×
UNCOV
82
            Type::mixed(), // virtual property
×
UNCOV
83
            ['api_platform.jsonld.json_streamer.write.value_transformer.type'],
×
UNCOV
84
        );
×
85

NEW
86
        if ($className !== $originalClassName) {
×
NEW
87
            return $properties;
×
88
        }
89

UNCOV
90
        if (Collection::class === $originalClassName || ($this->resourceClassResolver->isResourceClass($originalClassName) && !isset($context['generated_classes'][Collection::class]))) {
×
UNCOV
91
            $properties['@context'] = new PropertyMetadata(
×
NEW
92
                $virtualProperty, // virual property
×
UNCOV
93
                Type::string(), // virtual property
×
UNCOV
94
                ['api_platform.jsonld.json_streamer.write.value_transformer.context'],
×
UNCOV
95
            );
×
96
        }
97

UNCOV
98
        return $properties;
×
99
    }
100
}
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