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

api-platform / core / 3904303394

pending completion
3904303394

Pull #5332

github

GitHub
Merge 2e0a3ceae into 965332bc8
Pull Request #5332: Revert "chore(deprecation): Only use ValueResolverInterface if it exists"

2 of 2 new or added lines in 1 file covered. (100.0%)

7939 of 12085 relevant lines covered (65.69%)

81.77 hits per line

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

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

16
use ApiPlatform\Doctrine\Common\PropertyHelperTrait;
17
use ApiPlatform\Doctrine\Odm\PropertyHelperTrait as MongoDbOdmPropertyHelperTrait;
18
use ApiPlatform\Metadata\Operation;
19
use Doctrine\ODM\MongoDB\Aggregation\Builder;
20
use Doctrine\Persistence\ManagerRegistry;
21
use Psr\Log\LoggerInterface;
22
use Psr\Log\NullLogger;
23
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
24

25
/**
26
 * {@inheritdoc}
27
 *
28
 * Abstract class for easing the implementation of a filter.
29
 *
30
 * @author Alan Poulain <contact@alanpoulain.eu>
31
 */
32
abstract class AbstractFilter implements FilterInterface
33
{
34
    use MongoDbOdmPropertyHelperTrait;
35
    use PropertyHelperTrait;
36
    protected LoggerInterface $logger;
37

38
    public function __construct(protected ManagerRegistry $managerRegistry, LoggerInterface $logger = null, protected ?array $properties = null, protected ?NameConverterInterface $nameConverter = null)
39
    {
40
        $this->logger = $logger ?? new NullLogger();
×
41
    }
42

43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function apply(Builder $aggregationBuilder, string $resourceClass, Operation $operation = null, array &$context = []): void
47
    {
48
        foreach ($context['filters'] as $property => $value) {
×
49
            $this->filterProperty($this->denormalizePropertyName($property), $value, $aggregationBuilder, $resourceClass, $operation, $context);
×
50
        }
51
    }
52

53
    /**
54
     * Passes a property through the filter.
55
     */
56
    abstract protected function filterProperty(string $property, $value, Builder $aggregationBuilder, string $resourceClass, Operation $operation = null, array &$context = []): void;
57

58
    protected function getManagerRegistry(): ManagerRegistry
59
    {
60
        return $this->managerRegistry;
×
61
    }
62

63
    protected function getProperties(): ?array
64
    {
65
        return $this->properties;
×
66
    }
67

68
    protected function getLogger(): LoggerInterface
69
    {
70
        return $this->logger;
×
71
    }
72

73
    /**
74
     * Determines whether the given property is enabled.
75
     */
76
    protected function isPropertyEnabled(string $property, string $resourceClass): bool
77
    {
78
        if (null === $this->properties) {
×
79
            // to ensure sanity, nested properties must still be explicitly enabled
80
            return !$this->isPropertyNested($property, $resourceClass);
×
81
        }
82

83
        return \array_key_exists($property, $this->properties);
×
84
    }
85

86
    protected function denormalizePropertyName(string|int $property): string
87
    {
88
        if (!$this->nameConverter instanceof NameConverterInterface) {
×
89
            return $property;
×
90
        }
91

92
        return implode('.', array_map($this->nameConverter->denormalize(...), explode('.', (string) $property)));
×
93
    }
94

95
    protected function normalizePropertyName(string $property): string
96
    {
97
        if (!$this->nameConverter instanceof NameConverterInterface) {
×
98
            return $property;
×
99
        }
100

101
        return implode('.', array_map($this->nameConverter->normalize(...), explode('.', $property)));
×
102
    }
103
}
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