+ *
+ * @experimental in 4.1
+ */
+class DebugCommand extends Command
+{
+ protected static $defaultName = 'debug:messenger';
+
+ private $mapping;
+
+ public function __construct(array $mapping)
+ {
+ parent::__construct();
+
+ $this->mapping = $mapping;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function configure()
+ {
+ $this
+ ->setDescription('Lists messages you can dispatch using the message bus')
+ ->setHelp(<<<'EOF'
+The %command.name% command displays all messages that can be
+dispatched using the message bus:
+
+ php %command.full_name%
+
+EOF
+ )
+ ;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $io = new SymfonyStyle($input, $output);
+ $io->title('Messenger');
+ $io->text('The following messages can be dispatched:');
+ $io->newLine();
+
+ $tableRows = array();
+ foreach ($this->mapping as $message => $handlers) {
+ $tableRows[] = array(sprintf('%s', $message));
+ foreach ($handlers as $handler) {
+ $tableRows[] = array(sprintf(' handled by %s', $handler));
+ }
+ }
+
+ if ($tableRows) {
+ $io->table(array(), $tableRows);
+ } else {
+ $io->text('No messages were found that have valid handlers.');
+ }
+ }
+}
diff --git a/src/Symfony/Component/Messenger/DependencyInjection/MessengerPass.php b/src/Symfony/Component/Messenger/DependencyInjection/MessengerPass.php
index 1fd76db8fee25..2af6577f485a8 100644
--- a/src/Symfony/Component/Messenger/DependencyInjection/MessengerPass.php
+++ b/src/Symfony/Component/Messenger/DependencyInjection/MessengerPass.php
@@ -104,26 +104,29 @@ private function registerHandlers(ContainerBuilder $container)
}
$definitions = array();
+ $handlersLocatorMapping = array();
foreach ($handlersByMessage as $message => $handlers) {
if (1 === \count($handlers)) {
- $handlersByMessage[$message] = current($handlers);
+ $handlersLocatorMapping['handler.'.$message] = current($handlers);
} else {
$d = new Definition(ChainHandler::class, array($handlers));
$d->setPrivate(true);
$serviceId = hash('sha1', $message);
$definitions[$serviceId] = $d;
- $handlersByMessage[$message] = new Reference($serviceId);
+ $handlersLocatorMapping['handler.'.$message] = new Reference($serviceId);
}
}
$container->addDefinitions($definitions);
- $handlersLocatorMapping = array();
- foreach ($handlersByMessage as $message => $handler) {
- $handlersLocatorMapping['handler.'.$message] = $handler;
- }
-
$handlerResolver = $container->getDefinition('messenger.handler_resolver');
$handlerResolver->replaceArgument(0, ServiceLocatorTagPass::register($container, $handlersLocatorMapping));
+
+ if ($container->hasDefinition('console.command.messenger_debug')) {
+ $container->getDefinition('console.command.messenger_debug')
+ ->replaceArgument(0, array_map(function (array $handlers): array {
+ return array_map('strval', $handlers);
+ }, $handlersByMessage));
+ }
}
private function guessHandledClasses(\ReflectionClass $handlerClass, string $serviceId): array
pFad - Phonifier reborn
Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy