Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Messenger] Add debug:messenger CLI command
- Loading branch information
Showing
4 changed files
with
97 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/Symfony/Component/Messenger/Command/MessengerDebugCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* 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 <franssen.roland@gmail.com> | ||
* | ||
* @experimental in 4.1 | ||
*/ | ||
class MessengerDebugCommand 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 <info>%command.name%</info> command displays all messages that can be | ||
dispatched using the message bus: | ||
<info>php %command.full_name%</info> | ||
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('<fg=cyan>%s</fg=cyan>', $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.'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters