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

api-platform / core / 19192661240

08 Nov 2025 11:10AM UTC coverage: 0.0%. Remained the same
19192661240

push

github

soyuka
Merge remote-tracking branch 'upstream/4.1' into 4.2

0 of 56693 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
    ) {
34
    }
×
35

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

40
        if (IriTemplate::class === $className) {
×
41
            return $properties;
×
42
        }
43

44
        if (Collection::class !== $className && !$this->resourceClassResolver->isResourceClass($className)) {
×
45
            return $properties;
×
46
        }
47

48
        $originalClassName = TypeHelper::getClassName($context['original_type']);
×
49
        $hasIri = true;
×
50
        $virtualProperty = 'id';
×
51

52
        foreach ($this->propertyNameCollectionFactory->create($originalClassName) as $property) {
×
53
            $propertyMetadata = $this->propertyMetadataFactory->create($originalClassName, $property);
×
54
            if ($propertyMetadata->isIdentifier()) {
×
55
                $virtualProperty = $property;
×
56
            }
57

58
            if ($className === $originalClassName) {
×
59
                continue;
×
60
            }
61

62
            if ($propertyMetadata->getNativeType()->isIdentifiedBy($className)) {
×
63
                $hasIri = $propertyMetadata->getGenId();
×
64
                $virtualProperty = iterator_to_array($this->propertyNameCollectionFactory->create($className))[0];
×
65
            }
66
        }
67

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

76
        $properties['@type'] = new PropertyMetadata(
×
77
            $virtualProperty, // virtual property
×
78
            Type::mixed(), // virtual property
×
79
            ['api_platform.jsonld.json_streamer.write.value_transformer.type'],
×
80
        );
×
81

82
        if ($className !== $originalClassName) {
×
83
            return $properties;
×
84
        }
85

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

94
        return $properties;
×
95
    }
96
}
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