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

api-platform / core / 14854709983

06 May 2025 08:07AM UTC coverage: 8.457% (-0.002%) from 8.459%
14854709983

Pull #7122

github

web-flow
Merge 6b1cde96f into f55606b01
Pull Request #7122: Cherry picks from main (deprecations)

0 of 35 new or added lines in 9 files covered. (0.0%)

2157 existing lines in 159 files now uncovered.

13397 of 158416 relevant lines covered (8.46%)

22.88 hits per line

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

89.47
/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 ApiPlatform\State\Util\StateOptionsTrait;
24
use Doctrine\ODM\MongoDB\DocumentManager;
25
use Doctrine\ODM\MongoDB\Repository\DocumentRepository;
26
use Doctrine\Persistence\ManagerRegistry;
27
use Psr\Container\ContainerInterface;
28

29
/**
30
 * Collection state provider using the Doctrine ODM.
31
 */
32
final class CollectionProvider implements ProviderInterface
33
{
34
    use LinksHandlerLocatorTrait;
35
    use LinksHandlerTrait;
36
    use StateOptionsTrait;
37

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

48
    public function provide(Operation $operation, array $uriVariables = [], array $context = []): iterable
49
    {
UNCOV
50
        $documentClass = $this->getStateOptionsClass($operation, $operation->getClass(), Options::class);
276✔
51

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

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

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

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

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

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

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

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