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

api-platform / core / 14635100171

24 Apr 2025 06:39AM UTC coverage: 8.271% (+0.02%) from 8.252%
14635100171

Pull #6904

github

web-flow
Merge c9cefd82e into a3e5e53ea
Pull Request #6904: feat(graphql): added support for graphql subscriptions to work for actions

0 of 73 new or added lines in 3 files covered. (0.0%)

1999 existing lines in 144 files now uncovered.

13129 of 158728 relevant lines covered (8.27%)

13.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.96
/src/Doctrine/Odm/State/ItemProvider.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\Odm\State;
15

16
use ApiPlatform\Doctrine\Common\State\LinksHandlerLocatorTrait;
17
use ApiPlatform\Doctrine\Odm\Extension\AggregationItemExtensionInterface;
18
use ApiPlatform\Doctrine\Odm\Extension\AggregationResultItemExtensionInterface;
19
use ApiPlatform\Metadata\Exception\RuntimeException;
20
use ApiPlatform\Metadata\Operation;
21
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
22
use ApiPlatform\State\ProviderInterface;
23
use Doctrine\ODM\MongoDB\DocumentManager;
24
use Doctrine\ODM\MongoDB\Repository\DocumentRepository;
25
use Doctrine\Persistence\ManagerRegistry;
26
use Psr\Container\ContainerInterface;
27

28
/**
29
 * Item state provider using the Doctrine ODM.
30
 *
31
 * @author Kévin Dunglas <kevin@dunglas.fr>
32
 * @author Samuel ROZE <samuel.roze@gmail.com>
33
 */
34
final class ItemProvider implements ProviderInterface
35
{
36
    use LinksHandlerLocatorTrait;
37
    use LinksHandlerTrait;
38

39
    /**
40
     * @param AggregationItemExtensionInterface[] $itemExtensions
41
     */
42
    public function __construct(ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory, ManagerRegistry $managerRegistry, private readonly iterable $itemExtensions = [], ?ContainerInterface $handleLinksLocator = null)
43
    {
UNCOV
44
        $this->resourceMetadataCollectionFactory = $resourceMetadataCollectionFactory;
226✔
UNCOV
45
        $this->handleLinksLocator = $handleLinksLocator;
226✔
UNCOV
46
        $this->managerRegistry = $managerRegistry;
226✔
47
    }
48

49
    public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?object
50
    {
UNCOV
51
        $documentClass = $operation->getClass();
221✔
UNCOV
52
        if (($options = $operation->getStateOptions()) && $options instanceof Options && $options->getDocumentClass()) {
221✔
UNCOV
53
            $documentClass = $options->getDocumentClass();
1✔
54
        }
55

56
        /** @var DocumentManager $manager */
UNCOV
57
        $manager = $this->managerRegistry->getManagerForClass($documentClass);
221✔
58

UNCOV
59
        $fetchData = $context['fetch_data'] ?? true;
221✔
UNCOV
60
        if (!$fetchData) {
221✔
UNCOV
61
            return $manager->getReference($documentClass, reset($uriVariables));
4✔
62
        }
63

UNCOV
64
        $repository = $manager->getRepository($documentClass);
217✔
UNCOV
65
        if (!$repository instanceof DocumentRepository) {
217✔
66
            throw new RuntimeException(\sprintf('The repository for "%s" must be an instance of "%s".', $documentClass, DocumentRepository::class));
×
67
        }
68

UNCOV
69
        $aggregationBuilder = $repository->createAggregationBuilder();
217✔
70

UNCOV
71
        if ($handleLinks = $this->getLinksHandler($operation)) {
217✔
UNCOV
72
            $handleLinks($aggregationBuilder, $uriVariables, ['documentClass' => $documentClass, 'operation' => $operation] + $context);
217✔
73
        } else {
74
            $this->handleLinks($aggregationBuilder, $uriVariables, $context, $documentClass, $operation);
×
75
        }
76

UNCOV
77
        foreach ($this->itemExtensions as $extension) {
217✔
UNCOV
78
            $extension->applyToItem($aggregationBuilder, $documentClass, $uriVariables, $operation, $context);
217✔
79

UNCOV
80
            if ($extension instanceof AggregationResultItemExtensionInterface && $extension->supportsResult($documentClass, $operation, $context)) {
217✔
81
                return $extension->getResult($aggregationBuilder, $documentClass, $operation, $context);
×
82
            }
83
        }
84

UNCOV
85
        $executeOptions = $operation->getExtraProperties()['doctrine_mongodb']['execute_options'] ?? [];
217✔
86

UNCOV
87
        return $aggregationBuilder->hydrate($documentClass)->getAggregation($executeOptions)->getIterator()->current() ?: null;
217✔
88
    }
89
}
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