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

api-platform / core / 20001323174

07 Dec 2025 08:10AM UTC coverage: 25.292% (+0.001%) from 25.291%
20001323174

push

github

soyuka
chore: bump metadata to 4.3.x-dev

14642 of 57891 relevant lines covered (25.29%)

28.94 hits per line

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

0.0
/src/Doctrine/Odm/Extension/ParameterExtension.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\Extension;
15

16
use ApiPlatform\Doctrine\Common\Filter\PropertyAwareFilterInterface;
17
use ApiPlatform\Doctrine\Common\ParameterExtensionTrait;
18
use ApiPlatform\Doctrine\Odm\Filter\FilterInterface; // Explicitly import PropertyAwareFilterInterface
19
use ApiPlatform\Metadata\Operation;
20
use ApiPlatform\State\ParameterNotFound;
21
use Doctrine\Bundle\MongoDBBundle\ManagerRegistry;
22
use Doctrine\ODM\MongoDB\Aggregation\Builder;
23
use Psr\Container\ContainerInterface;
24
use Psr\Log\LoggerInterface;
25

26
/**
27
 * Reads operation parameters and execute its filter.
28
 *
29
 * @author Antoine Bluchet <soyuka@gmail.com>
30
 */
31
final class ParameterExtension implements AggregationCollectionExtensionInterface, AggregationItemExtensionInterface
32
{
33
    use ParameterExtensionTrait;
34

35
    public function __construct(
36
        ContainerInterface $filterLocator,
37
        ?ManagerRegistry $managerRegistry = null,
38
        ?LoggerInterface $logger = null,
39
    ) {
40
        $this->filterLocator = $filterLocator;
×
41
        $this->managerRegistry = $managerRegistry;
×
42
        $this->logger = $logger;
×
43
    }
44

45
    /**
46
     * @param array<string, mixed> $context
47
     */
48
    private function applyFilter(Builder $aggregationBuilder, ?string $resourceClass = null, ?Operation $operation = null, array &$context = []): void
49
    {
50
        foreach ($operation->getParameters() ?? [] as $parameter) {
×
51
            if (null === ($v = $parameter->getValue()) || $v instanceof ParameterNotFound) {
×
52
                continue;
×
53
            }
54

55
            $values = $this->extractParameterValue($parameter, $v);
×
56
            if (null === ($filterId = $parameter->getFilter())) {
×
57
                continue;
×
58
            }
59

60
            $filter = match (true) {
×
61
                $filterId instanceof FilterInterface => $filterId,
×
62
                \is_string($filterId) && $this->filterLocator->has($filterId) => $this->filterLocator->get($filterId),
×
63
                default => null,
×
64
            };
×
65

66
            if (!$filter instanceof FilterInterface) {
×
67
                continue;
×
68
            }
69

70
            $this->configureFilter($filter, $parameter);
×
71

72
            $context['filters'] = $values;
×
73
            $context['parameter'] = $parameter;
×
74

75
            $filter->apply($aggregationBuilder, $resourceClass, $operation, $context);
×
76

77
            unset($context['filters'], $context['parameter']);
×
78
        }
79

80
        if (isset($context['match'])) {
×
81
            $aggregationBuilder->match()->addAnd($context['match']);
×
82
        }
83
    }
84

85
    /**
86
     * {@inheritdoc}
87
     */
88
    public function applyToCollection(Builder $aggregationBuilder, string $resourceClass, ?Operation $operation = null, array &$context = []): void
89
    {
90
        $this->applyFilter($aggregationBuilder, $resourceClass, $operation, $context);
×
91
    }
92

93
    /**
94
     * {@inheritdoc}
95
     */
96
    public function applyToItem(Builder $aggregationBuilder, string $resourceClass, array $identifiers, ?Operation $operation = null, array &$context = []): void
97
    {
98
        $this->applyFilter($aggregationBuilder, $resourceClass, $operation, $context);
×
99
    }
100
}
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