|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Component\Messenger\Command; |
| 13 | + |
| 14 | +use Symfony\Component\Console\Command\Command; |
| 15 | +use Symfony\Component\Console\Input\InputInterface; |
| 16 | +use Symfony\Component\Console\Output\OutputInterface; |
| 17 | +use Symfony\Component\Console\Style\SymfonyStyle; |
| 18 | + |
| 19 | +/** |
| 20 | + * A console command to debug Messenger information. |
| 21 | + * |
| 22 | + * @author Roland Franssen <[email protected]> |
| 23 | + * |
| 24 | + * @experimental in 4.1 |
| 25 | + */ |
| 26 | +class DebugCommand extends Command |
| 27 | +{ |
| 28 | + protected static $defaultName = 'debug:messenger'; |
| 29 | + |
| 30 | + private $mapping; |
| 31 | + |
| 32 | + public function __construct(array $mapping) |
| 33 | + { |
| 34 | + parent::__construct(); |
| 35 | + |
| 36 | + $this->mapping = $mapping; |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * {@inheritdoc} |
| 41 | + */ |
| 42 | + protected function configure() |
| 43 | + { |
| 44 | + $this |
| 45 | + ->setDescription('Lists messages you can dispatch using the message bus') |
| 46 | + ->setHelp(<<<'EOF' |
| 47 | +The <info>%command.name%</info> command displays all messages that can be |
| 48 | +dispatched using the message bus: |
| 49 | +
|
| 50 | + <info>php %command.full_name%</info> |
| 51 | + |
| 52 | +EOF |
| 53 | + ) |
| 54 | + ; |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * {@inheritdoc} |
| 59 | + */ |
| 60 | + protected function execute(InputInterface $input, OutputInterface $output) |
| 61 | + { |
| 62 | + $io = new SymfonyStyle($input, $output); |
| 63 | + $io->title('Messenger'); |
| 64 | + $io->text('The following messages can be dispatched:'); |
| 65 | + $io->newLine(); |
| 66 | + |
| 67 | + $tableRows = array(); |
| 68 | + foreach ($this->mapping as $message => $handlers) { |
| 69 | + $tableRows[] = array(sprintf('<fg=cyan>%s</fg=cyan>', $message)); |
| 70 | + foreach ($handlers as $handler) { |
| 71 | + $tableRows[] = array(sprintf(' handled by %s', $handler)); |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + if ($tableRows) { |
| 76 | + $io->table(array(), $tableRows); |
| 77 | + } else { |
| 78 | + $io->text('No messages were found that have valid handlers.'); |
| 79 | + } |
| 80 | + } |
| 81 | +} |
0 commit comments