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

api-platform / core / 17585586101

09 Sep 2025 02:16PM UTC coverage: 0.0% (-22.6%) from 22.592%
17585586101

push

github

web-flow
fix(state): transform uri variable using ReadLinkParameterProvider (#7375)

0 of 4 new or added lines in 1 file covered. (0.0%)

12247 existing lines in 411 files now uncovered.

0 of 52798 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

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

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

UNCOV
64
            if ($className === $originalClassName) {
×
UNCOV
65
                continue;
×
66
            }
67

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

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

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

UNCOV
88
        if ($className !== $originalClassName) {
×
UNCOV
89
            return $properties;
×
90
        }
91

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

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