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

api-platform / core / 3904303394

pending completion
3904303394

Pull #5332

github

GitHub
Merge 2e0a3ceae into 965332bc8
Pull Request #5332: Revert "chore(deprecation): Only use ValueResolverInterface if it exists"

2 of 2 new or added lines in 1 file covered. (100.0%)

7939 of 12085 relevant lines covered (65.69%)

81.77 hits per line

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

0.0
/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\Odm\Extension\AggregationCollectionExtensionInterface;
17
use ApiPlatform\Doctrine\Odm\Extension\AggregationResultCollectionExtensionInterface;
18
use ApiPlatform\Exception\RuntimeException;
19
use ApiPlatform\Metadata\Operation;
20
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
21
use ApiPlatform\State\ProviderInterface;
22
use Doctrine\ODM\MongoDB\DocumentManager;
23
use Doctrine\ODM\MongoDB\Repository\DocumentRepository;
24
use Doctrine\Persistence\ManagerRegistry;
25

26
/**
27
 * Collection state provider using the Doctrine ODM.
28
 */
29
final class CollectionProvider implements ProviderInterface
30
{
31
    use LinksHandlerTrait;
32

33
    /**
34
     * @param AggregationCollectionExtensionInterface[] $collectionExtensions
35
     */
36
    public function __construct(private readonly ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory, private readonly ManagerRegistry $managerRegistry, private readonly iterable $collectionExtensions = [])
37
    {
38
    }
39

40
    public function provide(Operation $operation, array $uriVariables = [], array $context = []): iterable
41
    {
42
        $resourceClass = $operation->getClass();
×
43
        /** @var DocumentManager $manager */
44
        $manager = $this->managerRegistry->getManagerForClass($resourceClass);
×
45

46
        $repository = $manager->getRepository($resourceClass);
×
47
        if (!$repository instanceof DocumentRepository) {
×
48
            throw new RuntimeException(sprintf('The repository for "%s" must be an instance of "%s".', $resourceClass, DocumentRepository::class));
×
49
        }
50

51
        $aggregationBuilder = $repository->createAggregationBuilder();
×
52

53
        $this->handleLinks($aggregationBuilder, $uriVariables, $context, $resourceClass, $operation);
×
54

55
        foreach ($this->collectionExtensions as $extension) {
×
56
            $extension->applyToCollection($aggregationBuilder, $resourceClass, $operation, $context);
×
57

58
            if ($extension instanceof AggregationResultCollectionExtensionInterface && $extension->supportsResult($resourceClass, $operation, $context)) {
×
59
                return $extension->getResult($aggregationBuilder, $resourceClass, $operation, $context);
×
60
            }
61
        }
62

63
        $attribute = $operation->getExtraProperties()['doctrine_mongodb'] ?? [];
×
64
        $executeOptions = $attribute['execute_options'] ?? [];
×
65

66
        return $aggregationBuilder->hydrate($resourceClass)->execute($executeOptions);
×
67
    }
68
}
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