Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #26803 [Messenger] Add debug:messenger CLI command (ro0NL, sr…
…oze) This PR was merged into the 4.1 branch. Discussion ---------- [Messenger] Add debug:messenger CLI command | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no <!-- see https://symfony.com/bc --> | Deprecations? | no | Tests pass? | yes <!-- please add some, will be required by reviewers --> | Fixed tickets | #... <!-- #-prefixed issue number(s), if any --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> Adds a `debug:messenger` CLI command to expose message classes that can be dispatched. Heavily inspired by `debug:autowiring`. Commits ------- 7f87309 fix deps 290c7eb Rename the command `DebugCommand` 9847b83 [Messenger] Add debug:messenger CLI command
- Loading branch information
Showing
5 changed files
with
98 additions
and
8 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
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
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 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 <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