• 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/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\Odm\Extension\AggregationItemExtensionInterface;
17
use ApiPlatform\Doctrine\Odm\Extension\AggregationResultItemExtensionInterface;
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
 * Item state provider using the Doctrine ODM.
28
 *
29
 * @author Kévin Dunglas <kevin@dunglas.fr>
30
 * @author Samuel ROZE <samuel.roze@gmail.com>
31
 */
32
final class ItemProvider implements ProviderInterface
33
{
34
    use LinksHandlerTrait;
35

36
    /**
37
     * @param AggregationItemExtensionInterface[] $itemExtensions
38
     */
39
    public function __construct(private readonly ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory, private readonly ManagerRegistry $managerRegistry, private readonly iterable $itemExtensions = [])
40
    {
41
    }
42

43
    public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?object
44
    {
45
        $resourceClass = $operation->getClass();
×
46
        /** @var DocumentManager $manager */
47
        $manager = $this->managerRegistry->getManagerForClass($resourceClass);
×
48

49
        $fetchData = $context['fetch_data'] ?? true;
×
50
        if (!$fetchData) {
×
51
            return $manager->getReference($resourceClass, reset($uriVariables));
×
52
        }
53

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

59
        $aggregationBuilder = $repository->createAggregationBuilder();
×
60

61
        $this->handleLinks($aggregationBuilder, $uriVariables, $context, $resourceClass, $operation);
×
62

63
        foreach ($this->itemExtensions as $extension) {
×
64
            $extension->applyToItem($aggregationBuilder, $resourceClass, $uriVariables, $operation, $context);
×
65

66
            if ($extension instanceof AggregationResultItemExtensionInterface && $extension->supportsResult($resourceClass, $operation, $context)) {
×
67
                return $extension->getResult($aggregationBuilder, $resourceClass, $operation, $context);
×
68
            }
69
        }
70

71
        $executeOptions = $operation->getExtraProperties()['doctrine_mongodb']['execute_options'] ?? [];
×
72

73
        return $aggregationBuilder->hydrate($resourceClass)->execute($executeOptions)->current() ?: null;
×
74
    }
75
}
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