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

api-platform / core / 10315659289

09 Aug 2024 07:49AM UTC coverage: 7.841% (-0.006%) from 7.847%
10315659289

push

github

soyuka
style: cs fixes

70 of 529 new or added lines in 176 files covered. (13.23%)

160 existing lines in 58 files now uncovered.

12688 of 161818 relevant lines covered (7.84%)

26.86 hits per line

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

0.0
/docs/src/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\Playground\DependencyInjection\Compiler;
15

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

23
/**
24
 * @author Antoine Bluchet <soyuka@gmail.com>
25
 */
26
final class AttributeFilterPass implements CompilerPassInterface
27
{
28
    use AttributeFilterExtractorTrait;
29

30
    private const TAG_FILTER_NAME = 'api_platform.playground.filter';
31

32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function process(ContainerBuilder $container): void
36
    {
37
        foreach (get_declared_classes() as $class) {
×
38
            $r = new \ReflectionClass($class);
×
39
            if (str_contains((string) $r->getFileName(), 'guides')) {
×
40
                $this->createFilterDefinitions($r, $container);
×
41
            }
42
        }
43
    }
44

45
    /**
46
     * @throws InvalidArgumentException
47
     */
48
    private function createFilterDefinitions(\ReflectionClass $resourceReflectionClass, ContainerBuilder $container): void
49
    {
50
        foreach ($this->readFilterAttributes($resourceReflectionClass) as $id => [$arguments, $filterClass]) {
×
51
            if ($container->has($id)) {
×
52
                continue;
×
53
            }
54

55
            if (null === $filterReflectionClass = $container->getReflectionClass($filterClass, false)) {
×
NEW
56
                throw new InvalidArgumentException(\sprintf('Class "%s" used for service "%s" cannot be found.', $filterClass, $id));
×
57
            }
58

59
            if ($container->has($filterClass) && ($parentDefinition = $container->findDefinition($filterClass))->isAbstract()) {
×
60
                $definition = new ChildDefinition($parentDefinition->getClass());
×
61
            } else {
62
                $definition = new Definition($filterReflectionClass->getName());
×
63
                $definition->setAutoconfigured(true);
×
64
            }
65

66
            $definition->addTag(self::TAG_FILTER_NAME);
×
67
            $definition->setAutowired(true);
×
68

69
            $parameterNames = [];
×
70
            if (null !== $constructorReflectionMethod = $filterReflectionClass->getConstructor()) {
×
71
                foreach ($constructorReflectionMethod->getParameters() as $reflectionParameter) {
×
72
                    $parameterNames[$reflectionParameter->name] = true;
×
73
                }
74
            }
75

76
            foreach ($arguments as $key => $value) {
×
77
                if (!isset($parameterNames[$key])) {
×
NEW
78
                    throw new InvalidArgumentException(\sprintf('Class "%s" does not have argument "$%s".', $filterClass, $key));
×
79
                }
80

81
                $definition->setArgument("$$key", $value);
×
82
            }
83

84
            $container->setDefinition($id, $definition);
×
85
        }
86
    }
87
}
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