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

api-platform / core / 19171073905

07 Nov 2025 02:17PM UTC coverage: 0.0% (-24.3%) from 24.303%
19171073905

push

github

web-flow
feat(symfony): allow symfony makers namespace configuration (#7497)

0 of 19 new or added lines in 6 files covered. (0.0%)

14716 existing lines in 467 files now uncovered.

0 of 56762 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/Doctrine/Orm/Metadata/Resource/DoctrineOrmResourceCollectionMetadataFactory.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\Doctrine\Orm\Metadata\Resource;
15

16
use ApiPlatform\Doctrine\Orm\State\CollectionProvider;
17
use ApiPlatform\Doctrine\Orm\State\ItemProvider;
18
use ApiPlatform\Doctrine\Orm\State\Options;
19
use ApiPlatform\Metadata\CollectionOperationInterface;
20
use ApiPlatform\Metadata\DeleteOperationInterface;
21
use ApiPlatform\Metadata\Operation;
22
use ApiPlatform\Metadata\Patch;
23
use ApiPlatform\Metadata\Put;
24
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
25
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
26
use ApiPlatform\State\Util\StateOptionsTrait;
27
use Doctrine\ORM\EntityManagerInterface;
28
use Doctrine\Persistence\ManagerRegistry;
29

30
final class DoctrineOrmResourceCollectionMetadataFactory implements ResourceMetadataCollectionFactoryInterface
31
{
32
    use StateOptionsTrait;
33

34
    public function __construct(private readonly ManagerRegistry $managerRegistry, private readonly ResourceMetadataCollectionFactoryInterface $decorated)
35
    {
UNCOV
36
    }
×
37

38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function create(string $resourceClass): ResourceMetadataCollection
42
    {
UNCOV
43
        $resourceMetadataCollection = $this->decorated->create($resourceClass);
×
44

UNCOV
45
        foreach ($resourceMetadataCollection as $i => $resourceMetadata) {
×
UNCOV
46
            $operations = $resourceMetadata->getOperations();
×
47

UNCOV
48
            if ($operations) {
×
UNCOV
49
                foreach ($operations as $operationName => $operation) {
×
UNCOV
50
                    $entityClass = $this->getStateOptionsClass($operation, $operation->getClass(), Options::class);
×
51

UNCOV
52
                    $manager = $this->managerRegistry->getManagerForClass($entityClass);
×
UNCOV
53
                    if (!$manager instanceof EntityManagerInterface) {
×
UNCOV
54
                        continue;
×
55
                    }
56

UNCOV
57
                    $classMetadata = $manager->getClassMetadata($entityClass);
×
58
                    // @see https://www.doctrine-project.org/projects/doctrine-orm/en/3.5/reference/improving-performance.html#read-only-entities
59
                    // Read-Only allows to persist new entities of a kind and remove existing ones, they are just not considered for updates.
UNCOV
60
                    if ($classMetadata->isReadOnly && ($operation instanceof Put || $operation instanceof Patch)) {
×
UNCOV
61
                        $operations->remove($operationName);
×
UNCOV
62
                        continue;
×
63
                    }
64

UNCOV
65
                    $operations->add($operationName, $this->addDefaults($operation));
×
66
                }
67

UNCOV
68
                $resourceMetadata = $resourceMetadata->withOperations($operations);
×
69
            }
70

UNCOV
71
            $graphQlOperations = $resourceMetadata->getGraphQlOperations();
×
72

UNCOV
73
            if ($graphQlOperations) {
×
UNCOV
74
                foreach ($graphQlOperations as $operationName => $graphQlOperation) {
×
UNCOV
75
                    $entityClass = $this->getStateOptionsClass($graphQlOperation, $graphQlOperation->getClass(), Options::class);
×
76

UNCOV
77
                    if (!$this->managerRegistry->getManagerForClass($entityClass) instanceof EntityManagerInterface) {
×
UNCOV
78
                        continue;
×
79
                    }
80

UNCOV
81
                    $graphQlOperations[$operationName] = $this->addDefaults($graphQlOperation);
×
82
                }
83

UNCOV
84
                $resourceMetadata = $resourceMetadata->withGraphQlOperations($graphQlOperations);
×
85
            }
86

UNCOV
87
            $resourceMetadataCollection[$i] = $resourceMetadata;
×
88
        }
89

UNCOV
90
        return $resourceMetadataCollection;
×
91
    }
92

93
    private function addDefaults(Operation $operation): Operation
94
    {
UNCOV
95
        if (null === $operation->getProvider()) {
×
UNCOV
96
            $operation = $operation->withProvider($this->getProvider($operation));
×
97
        }
98

UNCOV
99
        $options = $operation->getStateOptions() ?: new Options();
×
UNCOV
100
        if ($options instanceof Options && null === $options->getHandleLinks()) {
×
UNCOV
101
            $options = $options->withHandleLinks('api_platform.doctrine.orm.links_handler');
×
UNCOV
102
            $operation = $operation->withStateOptions($options);
×
103
        }
104

UNCOV
105
        if (null === $operation->getProcessor()) {
×
UNCOV
106
            $operation = $operation->withProcessor($this->getProcessor($operation));
×
107
        }
108

UNCOV
109
        return $operation;
×
110
    }
111

112
    private function getProvider(Operation $operation): string
113
    {
UNCOV
114
        if ($operation instanceof CollectionOperationInterface) {
×
UNCOV
115
            return CollectionProvider::class;
×
116
        }
117

UNCOV
118
        return ItemProvider::class;
×
119
    }
120

121
    private function getProcessor(Operation $operation): string
122
    {
UNCOV
123
        if ($operation instanceof DeleteOperationInterface) {
×
UNCOV
124
            return 'api_platform.doctrine.orm.state.remove_processor';
×
125
        }
126

UNCOV
127
        return 'api_platform.doctrine.orm.state.persist_processor';
×
128
    }
129
}
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

© 2026 Coveralls, Inc