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

api-platform / core / 13200284839

07 Feb 2025 12:56PM UTC coverage: 0.0% (-8.2%) from 8.164%
13200284839

Pull #6952

github

web-flow
Merge 519fbf8cc into 62377f880
Pull Request #6952: fix: errors retrieval and documentation

0 of 206 new or added lines in 17 files covered. (0.0%)

10757 existing lines in 366 files now uncovered.

0 of 47781 relevant lines covered (0.0%)

0.0 hits per line

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

0.0
/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\Common\State\LinksHandlerLocatorTrait;
17
use ApiPlatform\Doctrine\Orm\Extension\QueryCollectionExtensionInterface;
18
use ApiPlatform\Doctrine\Orm\Extension\QueryResultCollectionExtensionInterface;
19
use ApiPlatform\Doctrine\Orm\Util\QueryNameGenerator;
20
use ApiPlatform\Metadata\Exception\RuntimeException;
21
use ApiPlatform\Metadata\Operation;
22
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
23
use ApiPlatform\State\ProviderInterface;
24
use Doctrine\ORM\EntityManagerInterface;
25
use Doctrine\Persistence\ManagerRegistry;
26
use Psr\Container\ContainerInterface;
27

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

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

49
    public function provide(Operation $operation, array $uriVariables = [], array $context = []): iterable
50
    {
UNCOV
51
        $entityClass = $operation->getClass();
×
UNCOV
52
        if (($options = $operation->getStateOptions()) && $options instanceof Options && $options->getEntityClass()) {
×
UNCOV
53
            $entityClass = $options->getEntityClass();
×
54
        }
55

56
        /** @var EntityManagerInterface $manager */
UNCOV
57
        $manager = $this->managerRegistry->getManagerForClass($entityClass);
×
58

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

UNCOV
64
        $queryBuilder = $repository->createQueryBuilder('o');
×
UNCOV
65
        $queryNameGenerator = new QueryNameGenerator();
×
66

UNCOV
67
        if ($handleLinks = $this->getLinksHandler($operation)) {
×
UNCOV
68
            $handleLinks($queryBuilder, $uriVariables, $queryNameGenerator, ['entityClass' => $entityClass, 'operation' => $operation] + $context);
×
69
        } else {
70
            $this->handleLinks($queryBuilder, $uriVariables, $queryNameGenerator, $context, $entityClass, $operation);
×
71
        }
72

UNCOV
73
        foreach ($this->collectionExtensions as $extension) {
×
UNCOV
74
            $extension->applyToCollection($queryBuilder, $queryNameGenerator, $entityClass, $operation, $context);
×
75

UNCOV
76
            if ($extension instanceof QueryResultCollectionExtensionInterface && $extension->supportsResult($entityClass, $operation, $context)) {
×
UNCOV
77
                return $extension->getResult($queryBuilder, $entityClass, $operation, $context);
×
78
            }
79
        }
80

81
        return $queryBuilder->getQuery()->getResult();
×
82
    }
83
}
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