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

api-platform / core / 14954769666

11 May 2025 10:14AM UTC coverage: 0.0% (-8.5%) from 8.457%
14954769666

Pull #7135

github

web-flow
Merge bf21e0bc7 into 4dd0cdfc4
Pull Request #7135: fix(symfony,laravel): InvalidUriVariableException status code (e400)

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

11040 existing lines in 370 files now uncovered.

0 of 48303 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/Symfony/Bundle/DependencyInjection/Compiler/AttributeFilterPass.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\Symfony\Bundle\DependencyInjection\Compiler;
15

16
use ApiPlatform\Metadata\ApiFilter;
17
use ApiPlatform\Metadata\Util\AttributeFilterExtractorTrait;
18
use ApiPlatform\Metadata\Util\ReflectionClassRecursiveIterator;
19
use Symfony\Component\DependencyInjection\ChildDefinition;
20
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
21
use Symfony\Component\DependencyInjection\ContainerBuilder;
22
use Symfony\Component\DependencyInjection\Definition;
23
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
24

25
/**
26
 * Registers filter services from {@see ApiFilter} attribute.
27
 *
28
 * @internal
29
 *
30
 * @author Antoine Bluchet <soyuka@gmail.com>
31
 */
32
final class AttributeFilterPass implements CompilerPassInterface
33
{
34
    use AttributeFilterExtractorTrait;
35

36
    private const TAG_FILTER_NAME = 'api_platform.filter';
37

38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function process(ContainerBuilder $container): void
42
    {
UNCOV
43
        $resourceClassDirectories = $container->getParameter('api_platform.resource_class_directories');
×
44

UNCOV
45
        foreach (ReflectionClassRecursiveIterator::getReflectionClassesFromDirectories($resourceClassDirectories) as $className => $reflectionClass) {
×
UNCOV
46
            $this->createFilterDefinitions($reflectionClass, $container);
×
47
        }
48
    }
49

50
    /**
51
     * @throws InvalidArgumentException
52
     */
53
    private function createFilterDefinitions(\ReflectionClass $resourceReflectionClass, ContainerBuilder $container): void
54
    {
UNCOV
55
        foreach ($this->readFilterAttributes($resourceReflectionClass) as $id => [$arguments, $filterClass, $filterAttribute]) {
×
UNCOV
56
            if ($container->has($id)) {
×
UNCOV
57
                continue;
×
58
            }
59

UNCOV
60
            if (null === $filterReflectionClass = $container->getReflectionClass($filterClass, false)) {
×
UNCOV
61
                throw new InvalidArgumentException(\sprintf('Class "%s" used for service "%s" cannot be found.', $filterClass, $id));
×
62
            }
63

UNCOV
64
            if ($container->has($filterClass) && ($parentDefinition = $container->findDefinition($filterClass))->isAbstract()) {
×
UNCOV
65
                $definition = new ChildDefinition($parentDefinition->getClass());
×
66
            } else {
UNCOV
67
                $definition = new Definition($filterReflectionClass->getName());
×
UNCOV
68
                $definition->setAutoconfigured(true);
×
69
            }
70

UNCOV
71
            $definition->addTag(self::TAG_FILTER_NAME);
×
UNCOV
72
            if ($filterAttribute->alias) {
×
UNCOV
73
                $definition->addTag(self::TAG_FILTER_NAME, ['id' => $filterAttribute->alias]);
×
74
            }
75

UNCOV
76
            $definition->setAutowired(true);
×
77

UNCOV
78
            $parameterNames = [];
×
UNCOV
79
            if (null !== $constructorReflectionMethod = $filterReflectionClass->getConstructor()) {
×
UNCOV
80
                foreach ($constructorReflectionMethod->getParameters() as $reflectionParameter) {
×
UNCOV
81
                    $parameterNames[$reflectionParameter->name] = true;
×
82
                }
83
            }
84

UNCOV
85
            foreach ($arguments as $key => $value) {
×
UNCOV
86
                if (!isset($parameterNames[$key])) {
×
87
                    throw new InvalidArgumentException(\sprintf('Class "%s" does not have argument "$%s".', $filterClass, $key));
×
88
                }
89

UNCOV
90
                $definition->setArgument("$$key", $value);
×
91
            }
92

UNCOV
93
            $container->setDefinition($id, $definition);
×
94
        }
95
    }
96
}
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