Skip to content

Commit

Permalink
Ignore public methods with a single non-class arguments during auto r…
Browse files Browse the repository at this point in the history
…egister
  • Loading branch information
weph authored and ruudk committed Jul 6, 2019
1 parent e6629a4 commit 55d85e5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/DependencyInjection/Compiler/AutoRegister.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace SimpleBus\SymfonyBridge\DependencyInjection\Compiler;

use RuntimeException;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

Expand Down Expand Up @@ -54,16 +53,11 @@ public function process(ContainerBuilder $container)

$parameters = $method->getParameters();

// if no param or optional param, skip
if (count($parameters) !== 1 || $parameters[0]->isOptional()) {
// if no param, optional param or non-class param, skip
if (count($parameters) !== 1 || $parameters[0]->isOptional() || $parameters[0]->getClass() === null) {
continue;
}

if ($parameters[0]->getClass() === null) {
throw new RuntimeException(sprintf('Could not get auto register class %s because the first parameter %s of public method %s should be have a class typehint. Either specify the typehint, make the function non-public, or disable auto registration.', $method->class,
$parameters[0]->getName(), $method->getName()));
}

// get the class name
$handles = $parameters[0]->getClass()->getName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@ public function someHandleMethod(AutoCommand2 $command)
{
$command->setHandled(true);
}

public function randomPublicMethod($value)
{

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@ public function someOtherEventHandler(AutoEvent3 $event)
{
$event->setHandledBy($this);
}

public function randomPublicMethod($value)
{

}
}

0 comments on commit 55d85e5

Please sign in to comment.