8000 Make MessengerPass less strict when auto-register handlers · symfony/symfony@49ab2cd · GitHub
[go: up one dir, main page]

Skip to content

Commit 49ab2cd

Browse files
committed
Make MessengerPass less strict when auto-register handlers
1 parent 7b03bff commit 49ab2cd

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/Symfony/Component/Messenger/DependencyInjection/MessengerPass.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,11 @@ private function guessHandledClasses(\ReflectionClass $handlerClass, string $ser
206206
throw new RuntimeException(sprintf('Invalid handler service "%s": class "%s" must have an "__invoke()" method.', $serviceId, $handlerClass->getName()));
207207
}
208208

209-
$parameters = $method->getParameters();
210-
if (1 !== \count($parameters)) {
211-
throw new RuntimeException(sprintf('Invalid handler service "%s": method "%s::__invoke()" must have exactly one argument corresponding to the message it handles.', $serviceId, $handlerClass->getName()));
209+
if (0 === $method->getNumberOfRequiredParameters()) {
210+
throw new RuntimeException(sprintf('Invalid handler service "%s": method "%s::__invoke()" requires at least one argument, first one being the message it handles.', $serviceId, $handlerClass->getName()));
212211
}
213212

213+
$parameters = $method->getParameters();
214214
if (!$type = $parameters[0]->getType()) {
215215
throw new RuntimeException(sprintf('Invalid handler service "%s": argument "$%s" of method "%s::__invoke()" must have a type-hint corresponding to the message class it handles.', $serviceId, $parameters[0]->getName(), $handlerClass->getName()));
216216
}

src/Symfony/Component/Messenger/Tests/DependencyInjection/MessengerPassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ public function testNotInvokableHandler()
391391

392392
/**
393393
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
394-
* @expectedExceptionMessage Invalid handler service "Symfony\Component\Messenger\Tests\DependencyInjection\MissingArgumentHandler": method "Symfony\Component\Messenger\Tests\DependencyInjection\MissingArgumentHandler::__invoke()" must have exactly one argument corresponding to the message it handles.
394+
* @expectedExceptionMessage Invalid handler service "Symfony\Component\Messenger\Tests\DependencyInjection\MissingArgumentHandler": method "Symfony\Component\Messenger\Tests\DependencyInjection\MissingArgumentHandler::__invoke()" requires at least one argument, first one being the message it handles.
395395
*/
396396
public function testMissingArgumentHandler()
397397
{

0 commit comments

Comments
 (0)
0