-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Messenger] remove AllowNoHandlerMiddleware in favor of a constructor argument on HandleMessageMiddleware #28945
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
namespace Symfony\Component\Messenger\Middleware; | ||
|
||
use Symfony\Component\Messenger\Envelope; | ||
use Symfony\Component\Messenger\Exception\NoHandlerForMessageException; | ||
use Symfony\Component\Messenger\Handler\Locator\HandlerLocatorInterface; | ||
|
||
/** | ||
|
@@ -20,19 +21,26 @@ | |
class HandleMessageMiddleware implements MiddlewareInterface | ||
{ | ||
private $messageHandlerLocator; | ||
private $allowNoHandlers; | ||
|
||
public function __construct(HandlerLocatorInterface $messageHandlerLocator) | ||
public function __construct(HandlerLocatorInterface $messageHandlerLocator, bool $allowNoHandlers = false) | ||
{ | ||
$this->messageHandlerLocator = $messageHandlerLocator; | ||
$this->allowNoHandlers = $allowNoHandlers; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @throws NoHandlerForMessageException When no handler is found and $allowNoHandlers is false | ||
*/ | ||
public function handle(Envelope $envelope, callable $next): void | ||
{ | ||
$handler = $this->messageHandlerLocator->getHandler($envelope); | ||
$handler($envelope->getMessage()); | ||
$next($envelope); | ||
if (null !== $handler = $this->messageHandlerLocator->getHandler($envelope)) { | ||
$handler($envelope->getMessage()); | ||
$next($envelope); | ||
} elseif (!$this->allowNoHandlers) { | ||
throw new NoHandlerForMessageException(sprintf('No handler for message "%s".', \get_class($envelope->getMessage()))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will become There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct, one PR or the other will need a rebase once merged. |
||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.