Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9793522

Browse files
committed
minor #29525 [Messenger] Make MessengerPass less strict when auto-register handlers (nicholasruunu)
This PR was merged into the 4.3-dev branch. Discussion ---------- [Messenger] Make MessengerPass less strict when auto-register handlers | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | License | MIT | Doc PR | not needed This allows you to auto-register handlers that have more than one argument, which is useful when having custom middleware to pass more parameters. #symfonyconhackday2018 Commits ------- 49ab2cd Make MessengerPass less strict when auto-register handlers
2 parents 550a569 + 49ab2cd commit 9793522

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
@@ -201,11 +201,11 @@ private function guessHandledClasses(\ReflectionClass $handlerClass, string $ser
201201
throw new RuntimeException(sprintf('Invalid handler service "%s": class "%s" must have an "__invoke()" method.', $serviceId, $handlerClass->getName()));
202202
}
203203

204-
$parameters = $method->getParameters();
205-
if (1 !== \count($parameters)) {
206-
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()));
204+
if (0 === $method->getNumberOfRequiredParameters()) {
205+
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()));
207206
}
208207

208+
$parameters = $method->getParameters();
209209
if (!$type = $parameters[0]->getType()) {
210210
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()));
211211
}

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

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

406406
/**
407407
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
408-
* @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.
408+
* @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.
409409
*/
410410
public function testMissingArgumentHandler()
411411
{

0 commit comments

Comments
 (0)