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

api-platform / core / 13814792797

12 Mar 2025 03:09PM UTC coverage: 5.889% (-1.4%) from 7.289%
13814792797

Pull #7012

github

web-flow
Merge 199d44919 into 284937039
Pull Request #7012: doc: comment typo in ApiResource.php

10048 of 170615 relevant lines covered (5.89%)

5.17 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\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
    {
41
        $this->resourceMetadataCollectionFactory = $resourceMetadataCollectionFactory;
×
42
        $this->handleLinksLocator = $handleLinksLocator;
×
43
        $this->managerRegistry = $managerRegistry;
×
44
    }
45

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

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

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

61
        $aggregationBuilder = $repository->createAggregationBuilder();
×
62

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

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

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

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

80
        return $aggregationBuilder->hydrate($documentClass)->execute($executeOptions);
×
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