diff --git a/src/Symfony/Component/Messenger/Command/DebugCommand.php b/src/Symfony/Component/Messenger/Command/DebugCommand.php index b86dc4b547..b50d97d1b9 100644 --- a/src/Symfony/Component/Messenger/Command/DebugCommand.php +++ b/src/Symfony/Component/Messenger/Command/DebugCommand.php @@ -80,12 +80,20 @@ EOF $tableRows = []; foreach ($handlersByMessage as $message => $handlers) { + if ($description = self::getClassDescription($message)) { + $tableRows[] = [sprintf('%s', $description)]; + } + $tableRows[] = [sprintf('%s', $message)]; foreach ($handlers as $handler) { $tableRows[] = [ sprintf(' handled by %s', $handler[0]).$this->formatConditions($handler[1]), ]; + if ($handlerDescription = self::getClassDescription($handler[0])) { + $tableRows[] = [sprintf(' %s', $handlerDescription)]; + } } + $tableRows[] = ['']; } if ($tableRows) { @@ -113,4 +121,20 @@ EOF return ' (when '.implode(', ', $optionsMapping).')'; } + + private static function getClassDescription(string $class): string + { + try { + $r = new \ReflectionClass($class); + + if ($docComment = $r->getDocComment()) { + $docComment = preg_split('#\n\s*\*\s*[\n@]#', substr($docComment, 3, -2), 2)[0]; + + return trim(preg_replace('#\s*\n\s*\*\s*#', ' ', $docComment)); + } + } catch (\ReflectionException $e) { + } + + return ''; + } } diff --git a/src/Symfony/Component/Messenger/Tests/Command/DebugCommandTest.php b/src/Symfony/Component/Messenger/Tests/Command/DebugCommandTest.php index e637d51dd3..e12ba9de1f 100644 --- a/src/Symfony/Component/Messenger/Tests/Command/DebugCommandTest.php +++ b/src/Symfony/Component/Messenger/Tests/Command/DebugCommandTest.php @@ -16,6 +16,8 @@ use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Messenger\Command\DebugCommand; use Symfony\Component\Messenger\Tests\Fixtures\DummyCommand; use Symfony\Component\Messenger\Tests\Fixtures\DummyCommandHandler; +use Symfony\Component\Messenger\Tests\Fixtures\DummyCommandWithDescription; +use Symfony\Component\Messenger\Tests\Fixtures\DummyCommandWithDescriptionHandler; use Symfony\Component\Messenger\Tests\Fixtures\DummyQuery; use Symfony\Component\Messenger\Tests\Fixtures\DummyQueryHandler; use Symfony\Component\Messenger\Tests\Fixtures\MultipleBusesMessage; @@ -41,6 +43,7 @@ class DebugCommandTest extends TestCase $command = new DebugCommand([ 'command_bus' => [ DummyCommand::class => [[DummyCommandHandler::class, ['option1' => '1', 'option2' => '2']]], + DummyCommandWithDescription::class => [[DummyCommandWithDescriptionHandler::class, []]], MultipleBusesMessage::class => [[MultipleBusesMessageHandler::class, []]], ], 'query_bus' => [ @@ -65,8 +68,15 @@ command_bus ----------------------------------------------------------------------------------------------------------- Symfony\Component\Messenger\Tests\Fixtures\DummyCommand handled by Symfony\Component\Messenger\Tests\Fixtures\DummyCommandHandler (when option1=1, option2=2) + + Used whenever a test needs to show a message with a class description. + Symfony\Component\Messenger\Tests\Fixtures\DummyCommandWithDescription + handled by Symfony\Component\Messenger\Tests\Fixtures\DummyCommandWithDescriptionHandler + Used whenever a test needs to show a message handler with a class description. + Symfony\Component\Messenger\Tests\Fixtures\MultipleBusesMessage handled by Symfony\Component\Messenger\Tests\Fixtures\MultipleBusesMessageHandler + ----------------------------------------------------------------------------------------------------------- query_bus @@ -77,8 +87,10 @@ query_bus --------------------------------------------------------------------------------------- Symfony\Component\Messenger\Tests\Fixtures\DummyQuery handled by Symfony\Component\Messenger\Tests\Fixtures\DummyQueryHandler + Symfony\Component\Messenger\Tests\Fixtures\MultipleBusesMessage handled by Symfony\Component\Messenger\Tests\Fixtures\MultipleBusesMessageHandler + --------------------------------------------------------------------------------------- @@ -101,8 +113,10 @@ query_bus --------------------------------------------------------------------------------------- Symfony\Component\Messenger\Tests\Fixtures\DummyQuery handled by Symfony\Component\Messenger\Tests\Fixtures\DummyQueryHandler + Symfony\Component\Messenger\Tests\Fixtures\MultipleBusesMessage handled by Symfony\Component\Messenger\Tests\Fixtures\MultipleBusesMessageHandler + --------------------------------------------------------------------------------------- diff --git a/src/Symfony/Component/Messenger/Tests/Fixtures/DummyCommandWithDescription.php b/src/Symfony/Component/Messenger/Tests/Fixtures/DummyCommandWithDescription.php new file mode 100644 index 0000000000..8f61cf8527 --- /dev/null +++ b/src/Symfony/Component/Messenger/Tests/Fixtures/DummyCommandWithDescription.php @@ -0,0 +1,19 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Messenger\Tests\Fixtures; + +/** + * Used whenever a test needs to show a message with a class description. + */ +class DummyCommandWithDescription +{ +} diff --git a/src/Symfony/Component/Messenger/Tests/Fixtures/DummyCommandWithDescriptionHandler.php b/src/Symfony/Component/Messenger/Tests/Fixtures/DummyCommandWithDescriptionHandler.php new file mode 100644 index 0000000000..d51c1ad70f --- /dev/null +++ b/src/Symfony/Component/Messenger/Tests/Fixtures/DummyCommandWithDescriptionHandler.php @@ -0,0 +1,22 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Messenger\Tests\Fixtures; + +/** + * Used whenever a test needs to show a message handler with a class description. + */ +class DummyCommandWithDescriptionHandler +{ + public function __invoke(DummyCommandWithDescription $command) + { + } +}