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

api-platform / core / 15023181448

14 May 2025 02:19PM UTC coverage: 0.0% (-8.4%) from 8.418%
15023181448

Pull #7139

github

web-flow
Merge 9f45709da into 1862d03b7
Pull Request #7139: refactor(symfony): remove obsolete option `validator.query-parameter-validation`

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

11266 existing lines in 366 files now uncovered.

0 of 50828 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/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\Orm\State;
15

16
use ApiPlatform\Doctrine\Common\State\LinksHandlerLocatorTrait;
17
use ApiPlatform\Doctrine\Orm\Extension\QueryItemExtensionInterface;
18
use ApiPlatform\Doctrine\Orm\Extension\QueryResultItemExtensionInterface;
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 ApiPlatform\State\Util\StateOptionsTrait;
25
use Doctrine\ORM\EntityManagerInterface;
26
use Doctrine\Persistence\ManagerRegistry;
27
use Psr\Container\ContainerInterface;
28

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

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

51
    public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?object
52
    {
UNCOV
53
        $entityClass = $this->getStateOptionsClass($operation, $operation->getClass(), Options::class);
×
54

55
        /** @var EntityManagerInterface|null $manager */
UNCOV
56
        $manager = $this->managerRegistry->getManagerForClass($entityClass);
×
UNCOV
57
        if (null === $manager) {
×
58
            throw new RuntimeException(\sprintf('No manager found for class "%s". Are you sure it\'s an entity?', $entityClass));
×
59
        }
60

UNCOV
61
        $fetchData = $context['fetch_data'] ?? true;
×
UNCOV
62
        if (!$fetchData && \array_key_exists('id', $uriVariables)) {
×
63
            // todo : if uriVariables don't contain the id, this fails. This should behave like it does in the following code
64
            return $manager->getReference($entityClass, $uriVariables);
×
65
        }
66

UNCOV
67
        $repository = $manager->getRepository($entityClass);
×
UNCOV
68
        if (!method_exists($repository, 'createQueryBuilder')) {
×
69
            throw new RuntimeException('The repository class must have a "createQueryBuilder" method.');
×
70
        }
71

UNCOV
72
        $queryBuilder = $repository->createQueryBuilder('o');
×
UNCOV
73
        $queryNameGenerator = new QueryNameGenerator();
×
74

UNCOV
75
        if ($handleLinks = $this->getLinksHandler($operation)) {
×
UNCOV
76
            $handleLinks($queryBuilder, $uriVariables, $queryNameGenerator, ['entityClass' => $entityClass, 'operation' => $operation] + $context);
×
77
        } else {
78
            $this->handleLinks($queryBuilder, $uriVariables, $queryNameGenerator, $context, $entityClass, $operation);
×
79
        }
80

UNCOV
81
        foreach ($this->itemExtensions as $extension) {
×
UNCOV
82
            $extension->applyToItem($queryBuilder, $queryNameGenerator, $entityClass, $uriVariables, $operation, $context);
×
83

UNCOV
84
            if ($extension instanceof QueryResultItemExtensionInterface && $extension->supportsResult($entityClass, $operation, $context)) {
×
85
                return $extension->getResult($queryBuilder, $entityClass, $operation, $context);
×
86
            }
87
        }
88

UNCOV
89
        return $queryBuilder->getQuery()->getOneOrNullResult();
×
90
    }
91
}
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