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

ICanBoogie / bind-routing / 4495689867

pending completion
4495689867

push

github

Olivier Laviale
Add Route attributes

62 of 62 new or added lines in 8 files covered. (100.0%)

77 of 126 relevant lines covered (61.11%)

0.62 hits per line

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

0.0
/lib/AttributeCompilerPass.php
1
<?php
2

3
namespace ICanBoogie\Binding\Routing;
4

5
use ICanBoogie\Binding\Routing\Attribute\Delete;
6
use ICanBoogie\Binding\Routing\Attribute\Get;
7
use ICanBoogie\Binding\Routing\Attribute\Post;
8
use ICanBoogie\Binding\Routing\Attribute\Put;
9
use ICanBoogie\Binding\Routing\Attribute\Route;
10
use ICanBoogie\HTTP\RequestMethod;
11
use olvlvl\ComposerAttributeCollector\Attributes;
12
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
13
use Symfony\Component\DependencyInjection\ContainerBuilder;
14

15
use function class_exists;
16
use function ICanBoogie\hyphenate;
17
use function ICanBoogie\pluralize;
18
use function str_ends_with;
19
use function str_starts_with;
20
use function strlen;
21
use function strrpos;
22
use function strtolower;
23
use function substr;
24

25
final class AttributeCompilerPass implements CompilerPassInterface
26
{
27
    private const TAG_ACTION_RESPONDER = 'action_responder';
28
    private const CONTROLLER_SUFFIX = 'Controller';
29

30
    public function process(ContainerBuilder $container): void
31
    {
32
        if (!class_exists(Attributes::class)) {
×
33
            return;
×
34
        }
35

36
        $this->process_action_responders($container);
×
37
        $this->process_routes($container);
×
38
        $this->process_actions($container);
×
39
    }
40

41
    /**
42
     * Configures tag `{ name: action_responder }` from classes with the attribute {@link ActionResponder}.
43
     */
44
    private function process_action_responders(ContainerBuilder $container): void
45
    {
46
        $target_classes = Attributes::findTargetClasses(ActionResponder::class);
×
47

48
        foreach ($target_classes as $class) {
×
49
            $definition = $container->findDefinition($class->name);
×
50
            $definition->addTag(self::TAG_ACTION_RESPONDER);
×
51
        }
52
    }
53

54
    /**
55
     * Configures tag `{ name: action_alias, action: X }` from methods with the attribute {@link Action}.
56
     */
57
    private function process_routes(ContainerBuilder $container): void
58
    {
59
        $target_methods = [
×
60
            ...Attributes::findTargetMethods(Get::class),
×
61
            ...Attributes::findTargetMethods(Post::class),
×
62
            ...Attributes::findTargetMethods(Put::class),
×
63
            ...Attributes::findTargetMethods(Delete::class),
×
64
            ...Attributes::findTargetMethods(Route::class),
×
65
        ];
×
66

67
        foreach ($target_methods as $method) {
×
68
            $class = $method->class;
×
69
            $attribute = $method->attribute;
×
70
            $action = $attribute->action ?? ActionResolver::resolve_action($class, $method->name);
×
71

72
            $definition = $container->findDefinition($class);
×
73
            $definition->addTag(ActionAliasCompilerPass::TAG, [ ActionAliasCompilerPass::TAG_KEY => $action ]);
×
74
        }
75
    }
76

77
    /**
78
     * Configures tag `{ name: action_alias, action: X }` from methods with the attribute {@link Action}.
79
     */
80
    private function process_actions(ContainerBuilder $container): void
81
    {
82
        $target_methods = Attributes::findTargetMethods(Action::class);
×
83

84
        foreach ($target_methods as $method) {
×
85
            $class = $method->class;
×
86
            $attribute = $method->attribute;
×
87
            $action = $attribute->action ?? ActionResolver::resolve_action($class, $method->name);
×
88

89
            $definition = $container->findDefinition($class);
×
90
            $definition->addTag(ActionAliasCompilerPass::TAG, [ ActionAliasCompilerPass::TAG_KEY => $action ]);
×
91
        }
92
    }
93
}
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