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

api-platform / core / 7142557150

08 Dec 2023 02:28PM UTC coverage: 36.003% (-1.4%) from 37.36%
7142557150

push

github

web-flow
fix(jsonld): remove link to ApiDocumentation when doc is disabled (#6029)

0 of 1 new or added line in 1 file covered. (0.0%)

2297 existing lines in 182 files now uncovered.

9992 of 27753 relevant lines covered (36.0%)

147.09 hits per line

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

94.74
/src/Doctrine/Orm/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\Orm\State;
15

16
use ApiPlatform\Doctrine\Orm\Extension\QueryCollectionExtensionInterface;
17
use ApiPlatform\Doctrine\Orm\Extension\QueryResultCollectionExtensionInterface;
18
use ApiPlatform\Doctrine\Orm\Util\QueryNameGenerator;
19
use ApiPlatform\Exception\RuntimeException;
20
use ApiPlatform\Metadata\Operation;
21
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
22
use ApiPlatform\State\ProviderInterface;
23
use Doctrine\ORM\EntityManagerInterface;
24
use Doctrine\Persistence\ManagerRegistry;
25
use Psr\Container\ContainerInterface;
26

27
/**
28
 * Collection state provider using the Doctrine ORM.
29
 *
30
 * @author Kévin Dunglas <kevin@dunglas.fr>
31
 * @author Samuel ROZE <samuel.roze@gmail.com>
32
 */
33
final class CollectionProvider implements ProviderInterface
34
{
35
    use LinksHandlerTrait;
36

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

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

53
        /** @var EntityManagerInterface $manager */
54
        $manager = $this->managerRegistry->getManagerForClass($entityClass);
882✔
55

56
        $repository = $manager->getRepository($entityClass);
882✔
57
        if (!method_exists($repository, 'createQueryBuilder')) {
882✔
UNCOV
58
            throw new RuntimeException('The repository class must have a "createQueryBuilder" method.');
×
59
        }
60

61
        $queryBuilder = $repository->createQueryBuilder('o');
882✔
62
        $queryNameGenerator = new QueryNameGenerator();
882✔
63

64
        if ($handleLinks = $this->getLinksHandler($operation)) {
882✔
65
            $handleLinks($queryBuilder, $uriVariables, $queryNameGenerator, ['entityClass' => $entityClass, 'operation' => $operation] + $context);
3✔
66
        } else {
67
            $this->handleLinks($queryBuilder, $uriVariables, $queryNameGenerator, $context, $entityClass, $operation);
879✔
68
        }
69

70
        foreach ($this->collectionExtensions as $extension) {
882✔
71
            $extension->applyToCollection($queryBuilder, $queryNameGenerator, $entityClass, $operation, $context);
882✔
72

73
            if ($extension instanceof QueryResultCollectionExtensionInterface && $extension->supportsResult($entityClass, $operation, $context)) {
882✔
74
                return $extension->getResult($queryBuilder, $entityClass, $operation, $context);
867✔
75
            }
76
        }
77

78
        return $queryBuilder->getQuery()->getResult();
9✔
79
    }
80
}
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