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

api-platform / core / 15283185369

27 May 2025 06:43PM UTC coverage: 0.0% (-26.4%) from 26.397%
15283185369

Pull #7180

github

web-flow
Merge 9a6703d44 into c022b441b
Pull Request #7180: feat(deps): allow Elasticsearch v9

0 of 51334 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\ApiResource;
20
use ApiPlatform\Metadata\CollectionOperationInterface;
21
use ApiPlatform\Metadata\DeleteOperationInterface;
22
use ApiPlatform\Metadata\Operation;
23
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
24
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
25
use ApiPlatform\State\Util\StateOptionsTrait;
26
use Doctrine\ORM\EntityManagerInterface;
27
use Doctrine\Persistence\ManagerRegistry;
28

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

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

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

44
        /** @var ApiResource $resourceMetadata */
45
        foreach ($resourceMetadataCollection as $i => $resourceMetadata) {
×
46
            $operations = $resourceMetadata->getOperations();
×
47

48
            if ($operations) {
×
49
                /** @var Operation $operation */
50
                foreach ($resourceMetadata->getOperations() as $operationName => $operation) {
×
51
                    $entityClass = $this->getStateOptionsClass($operation, $operation->getClass(), Options::class);
×
52

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

57
                    $operations->add($operationName, $this->addDefaults($operation));
×
58
                }
59

60
                $resourceMetadata = $resourceMetadata->withOperations($operations);
×
61
            }
62

63
            $graphQlOperations = $resourceMetadata->getGraphQlOperations();
×
64

65
            if ($graphQlOperations) {
×
66
                foreach ($graphQlOperations as $operationName => $graphQlOperation) {
×
67
                    $entityClass = $this->getStateOptionsClass($graphQlOperation, $graphQlOperation->getClass(), Options::class);
×
68

69
                    if (!$this->managerRegistry->getManagerForClass($entityClass) instanceof EntityManagerInterface) {
×
70
                        continue;
×
71
                    }
72

73
                    $graphQlOperations[$operationName] = $this->addDefaults($graphQlOperation);
×
74
                }
75

76
                $resourceMetadata = $resourceMetadata->withGraphQlOperations($graphQlOperations);
×
77
            }
78

79
            $resourceMetadataCollection[$i] = $resourceMetadata;
×
80
        }
81

82
        return $resourceMetadataCollection;
×
83
    }
84

85
    private function addDefaults(Operation $operation): Operation
86
    {
87
        if (null === $operation->getProvider()) {
×
88
            $operation = $operation->withProvider($this->getProvider($operation));
×
89
        }
90

91
        $options = $operation->getStateOptions() ?: new Options();
×
92
        if ($options instanceof Options && null === $options->getHandleLinks()) {
×
93
            $options = $options->withHandleLinks('api_platform.doctrine.orm.links_handler');
×
94
            $operation = $operation->withStateOptions($options);
×
95
        }
96

97
        if (null === $operation->getProcessor()) {
×
98
            $operation = $operation->withProcessor($this->getProcessor($operation));
×
99
        }
100

101
        return $operation;
×
102
    }
103

104
    private function getProvider(Operation $operation): string
105
    {
106
        if ($operation instanceof CollectionOperationInterface) {
×
107
            return CollectionProvider::class;
×
108
        }
109

110
        return ItemProvider::class;
×
111
    }
112

113
    private function getProcessor(Operation $operation): string
114
    {
115
        if ($operation instanceof DeleteOperationInterface) {
×
116
            return 'api_platform.doctrine.orm.state.remove_processor';
×
117
        }
118

119
        return 'api_platform.doctrine.orm.state.persist_processor';
×
120
    }
121
}
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