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

api-platform / core / 10739011304

06 Sep 2024 01:11PM UTC coverage: 7.159% (-0.5%) from 7.645%
10739011304

push

github

web-flow
 feat(laravel): eloquent filters (search, date, equals, or) (#6593)

* feat(laravel): Eloquent filters search date or

* feat(laravel): eloquent filters order range equals afterdate

* fix(laravel): order afterDate filters

* temp

* test(laravel): filter with eloquent

---------

Co-authored-by: Nathan <nathan@les-tilleuls.coop>

0 of 144 new or added lines in 16 files covered. (0.0%)

4792 existing lines in 155 files now uncovered.

11736 of 163930 relevant lines covered (7.16%)

22.8 hits per line

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

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

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

49
    public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?object
50
    {
UNCOV
51
        $documentClass = $operation->getClass();
440✔
UNCOV
52
        if (($options = $operation->getStateOptions()) && $options instanceof Options && $options->getDocumentClass()) {
440✔
UNCOV
53
            $documentClass = $options->getDocumentClass();
2✔
54
        }
55

56
        /** @var DocumentManager $manager */
UNCOV
57
        $manager = $this->managerRegistry->getManagerForClass($documentClass);
440✔
58

UNCOV
59
        $fetchData = $context['fetch_data'] ?? true;
440✔
UNCOV
60
        if (!$fetchData) {
440✔
UNCOV
61
            return $manager->getReference($documentClass, reset($uriVariables));
8✔
62
        }
63

UNCOV
64
        $repository = $manager->getRepository($documentClass);
432✔
UNCOV
65
        if (!$repository instanceof DocumentRepository) {
432✔
66
            throw new RuntimeException(\sprintf('The repository for "%s" must be an instance of "%s".', $documentClass, DocumentRepository::class));
×
67
        }
68

UNCOV
69
        $aggregationBuilder = $repository->createAggregationBuilder();
432✔
70

UNCOV
71
        if ($handleLinks = $this->getLinksHandler($operation)) {
432✔
UNCOV
72
            $handleLinks($aggregationBuilder, $uriVariables, ['documentClass' => $documentClass, 'operation' => $operation] + $context);
432✔
73
        } else {
74
            $this->handleLinks($aggregationBuilder, $uriVariables, $context, $documentClass, $operation);
×
75
        }
76

UNCOV
77
        foreach ($this->itemExtensions as $extension) {
432✔
UNCOV
78
            $extension->applyToItem($aggregationBuilder, $documentClass, $uriVariables, $operation, $context);
432✔
79

UNCOV
80
            if ($extension instanceof AggregationResultItemExtensionInterface && $extension->supportsResult($documentClass, $operation, $context)) {
432✔
81
                return $extension->getResult($aggregationBuilder, $documentClass, $operation, $context);
×
82
            }
83
        }
84

UNCOV
85
        $executeOptions = $operation->getExtraProperties()['doctrine_mongodb']['execute_options'] ?? [];
432✔
86

UNCOV
87
        return $aggregationBuilder->hydrate($documentClass)->execute($executeOptions)->current() ?: null;
432✔
88
    }
89
}
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