Skip to content

Commit 11334c2

Browse files
committed
AutoRegister > Only when register_public_methods: true
1 parent 99c9b2d commit 11334c2

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/DependencyInjection/Compiler/AutoRegister.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@ public function process(ContainerBuilder $container)
2323
{
2424
foreach ($container->findTaggedServiceIds($this->tagName) as $serviceId => $tags) {
2525
foreach ($tags as $tagAttributes) {
26-
27-
// if tag attributes are set, skip
26+
// if tag attribute is set, skip
2827
if (isset($tagAttributes[$this->tagAttribute])) {
2928
continue;
3029
}
3130

31+
$registerPublicMethods = false;
32+
if (isset($tagAttributes['register_public_methods']) && true === $tagAttributes['register_public_methods']) {
33+
$registerPublicMethods = true;
34+
}
35+
3236
$definition = $container->getDefinition($serviceId);
3337

3438
// check if service id is class name
@@ -37,7 +41,6 @@ public function process(ContainerBuilder $container)
3741
$methods = $reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC);
3842

3943
$tagAttributes = [];
40-
4144
foreach ($methods as $method) {
4245
if (true === $method->isConstructor()) {
4346
continue;
@@ -47,6 +50,10 @@ public function process(ContainerBuilder $container)
4750
continue;
4851
}
4952

53+
if (false === $registerPublicMethods && '__invoke' !== $method->getName()) {
54+
continue;
55+
}
56+
5057
$parameters = $method->getParameters();
5158

5259
// if no param or optional param, skip

tests/Functional/SmokeTest/config2.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ services:
1010
auto_command_handler_using_public_method:
1111
class: SimpleBus\SymfonyBridge\Tests\Functional\SmokeTest\Auto\AutoCommandHandlerUsingPublicMethod
1212
tags:
13-
- { name: command_handler }
13+
- { name: command_handler, register_public_methods: true }
1414

1515
auto_event_subscriber_using_invoke:
1616
class: SimpleBus\SymfonyBridge\Tests\Functional\SmokeTest\Auto\AutoEventSubscriberUsingInvoke
@@ -20,4 +20,4 @@ services:
2020
auto_event_subscriber_using_public_method:
2121
class: SimpleBus\SymfonyBridge\Tests\Functional\SmokeTest\Auto\AutoEventSubscriberUsingPublicMethod
2222
tags:
23-
- { name: event_subscriber }
23+
- { name: event_subscriber, register_public_methods: true }

0 commit comments

Comments
 (0)