diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
index d8f4b61699a9e..dafdc40219f95 100644
--- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
+++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
@@ -277,6 +277,7 @@ public function load(array $configs, ContainerBuilder $container)
$this->registerMessengerConfiguration($config['messenger'], $container, $loader, $config['serializer'], $config['validation']);
} else {
$container->removeDefinition('console.command.messenger_consume_messages');
+ $container->removeDefinition('console.command.messenger_debug');
}
if ($this->isConfigEnabled($container, $config['web_link'])) {
diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/console.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/console.xml
index cb71bbb8de8f7..21fe28375f6fb 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/console.xml
+++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/console.xml
@@ -77,6 +77,11 @@
+
+
+
+
+
diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json
index 8c1c32194fdea..3dfca6a069709 100644
--- a/src/Symfony/Bundle/FrameworkBundle/composer.json
+++ b/src/Symfony/Bundle/FrameworkBundle/composer.json
@@ -41,7 +41,7 @@
"symfony/security": "~3.4|~4.0",
"symfony/form": "^4.1",
"symfony/expression-language": "~3.4|~4.0",
- "symfony/messenger": "^4.1",
+ "symfony/messenger": "^4.1-beta2",
"symfony/process": "~3.4|~4.0",
"symfony/security-core": "~3.4|~4.0",
"symfony/security-csrf": "~3.4|~4.0",
diff --git a/src/Symfony/Component/Messenger/Command/DebugCommand.php b/src/Symfony/Component/Messenger/Command/DebugCommand.php
new file mode 100644
index 0000000000000..f41747dc0f649
--- /dev/null
+++ b/src/Symfony/Component/Messenger/Command/DebugCommand.php
@@ -0,0 +1,81 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\Component\Messenger\Command;
+
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Style\SymfonyStyle;
+
+/**
+ * A console command to debug Messenger information.
+ *
+ * @author Roland Franssen
+ *
+ * @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