• 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

90.48
/src/Doctrine/Odm/State/CollectionProvider.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\AggregationCollectionExtensionInterface;
18
use ApiPlatform\Doctrine\Odm\Extension\AggregationResultCollectionExtensionInterface;
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
 * Collection state provider using the Doctrine ODM.
30
 */
31
final class CollectionProvider implements ProviderInterface
32
{
33
    use LinksHandlerLocatorTrait;
34
    use LinksHandlerTrait;
35

36
    /**
37
     * @param AggregationCollectionExtensionInterface[] $collectionExtensions
38
     */
39
    public function __construct(ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory, ManagerRegistry $managerRegistry, private readonly iterable $collectionExtensions = [], ?ContainerInterface $handleLinksLocator = null)
40
    {
UNCOV
41
        $this->resourceMetadataCollectionFactory = $resourceMetadataCollectionFactory;
279✔
UNCOV
42
        $this->handleLinksLocator = $handleLinksLocator;
279✔
UNCOV
43
        $this->managerRegistry = $managerRegistry;
279✔
44
    }
45

46
    public function provide(Operation $operation, array $uriVariables = [], array $context = []): iterable
47
    {
UNCOV
48
        $documentClass = $operation->getClass();
276✔
UNCOV
49
        if (($options = $operation->getStateOptions()) && $options instanceof Options && $options->getDocumentClass()) {
276✔
UNCOV
50
            $documentClass = $options->getDocumentClass();
2✔
51
        }
52

53
        /** @var DocumentManager $manager */
UNCOV
54
        $manager = $this->managerRegistry->getManagerForClass($documentClass);
276✔
55

UNCOV
56
        $repository = $manager->getRepository($documentClass);
276✔
UNCOV
57
        if (!$repository instanceof DocumentRepository) {
276✔
58
            throw new RuntimeException(\sprintf('The repository for "%s" must be an instance of "%s".', $documentClass, DocumentRepository::class));
×
59
        }
60

UNCOV
61
        $aggregationBuilder = $repository->createAggregationBuilder();
276✔
62

UNCOV
63
        if ($handleLinks = $this->getLinksHandler($operation)) {
276✔
UNCOV
64
            $handleLinks($aggregationBuilder, $uriVariables, ['documentClass' => $documentClass, 'operation' => $operation] + $context);
276✔
65
        } else {
66
            $this->handleLinks($aggregationBuilder, $uriVariables, $context, $documentClass, $operation);
×
67
        }
68

UNCOV
69
        foreach ($this->collectionExtensions as $extension) {
276✔
UNCOV
70
            $extension->applyToCollection($aggregationBuilder, $documentClass, $operation, $context);
276✔
71

UNCOV
72
            if ($extension instanceof AggregationResultCollectionExtensionInterface && $extension->supportsResult($documentClass, $operation, $context)) {
274✔
UNCOV
73
                return $extension->getResult($aggregationBuilder, $documentClass, $operation, $context);
269✔
74
            }
75
        }
76

UNCOV
77
        $attribute = $operation->getExtraProperties()['doctrine_mongodb'] ?? [];
3✔
UNCOV
78
        $executeOptions = $attribute['execute_options'] ?? [];
3✔
79

UNCOV
80
        return $aggregationBuilder->hydrate($documentClass)->getAggregation($executeOptions)->getIterator();
3✔
81
    }
82
}
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