8000 Bus argument is a required option when multiple buses are defined · symfony/symfony@99a4f5f · GitHub
[go: up one dir, main page]

Skip to content

Commit 99a4f5f

Browse files
committed
Bus argument is a required option when multiple buses are defined
1 parent 78b7d8a commit 99a4f5f

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

src/Symfony/Bundle/FrameworkBundle/Resources/config/console.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
<argument type="service" id="messenger.receiver_locator" />
7575
<argument type="service" id="logger" on-invalid="null" />
7676
<argument>null</argument> <!-- Default receiver name -->
77-
<argument type="collection" /> <!-- Message buses names -->
77+
<argument type="collection" /> <!-- Message bus names -->
7878

7979
<tag name="console.command" command="messenger:consume-messages" />
8080
</service>

src/Symfony/Component/Messenger/Command/ConsumeMessagesCommand.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,15 @@ public function __construct(ContainerInterface $busLocator, ContainerInterface $
5757
protected function configure(): void
5858
{
5959
$defaultReceiverName = 1 === \count($this->receiverNames) ? current($this->receiverNames) : null;
60+
$defaultBusName = 1 === \count($this->busNames) ? current($this->busNames) : null;
6061

6162
$this
6263
->setDefinition(array(
6364
new InputArgument('receiver', $defaultReceiverName ? InputArgument::OPTIONAL : InputArgument::REQUIRED, 'Name of the receiver', $defaultReceiverName),
6465
new InputOption('limit', 'l', InputOption::VALUE_REQUIRED, 'Limit the number of received messages'),
6566
new InputOption('memory-limit', 'm', InputOption::VALUE_REQUIRED, 'The memory limit the worker can consume'),
6667
new InputOption('time-limit', 't', InputOption::VALUE_REQUIRED, 'The time limit in seconds the worker can run'),
67-
new InputOption('bus', 'b', InputOption::VALUE_REQUIRED, 'Name of the bus to which received messages should be dispatched', 'message_bus'),
68+
new InputOption('bus', 'b', InputOption::VALUE_REQUIRED, 'Name of the bus to which received messages should be dispatched', $defaultBusName),
6869
))
6970
->setDescription('Consumes messages')
7071
->setHelp(<<<'EOF'
@@ -107,11 +108,12 @@ protected function interact(InputInterface $input, OutputInterface $output)
107108
}
108109
}
109110

110-
111111
$busName = $input->getOption('bus');
112-
113-
if ($busName && $this->busNames && !$this->busLocator->has($busName) && $alternatives = $this->findAlternatives($busName, $this->busNames)) {
114-
if ($alternatives = $this->findAlternatives($busName, $this->busNames)) {
112+
if ($this->busNames && !$this->busLocator->has($busName)) {
113+
if (null === $busName) {
114+
$style->block('Missing bus argument.', null, 'error', ' ', true);
115+
$input->setOption('bus', $style->choice('Select one of the available buses', $this->busNames));
116+
} elseif ($alternatives = $this->findAlternatives($busName, $this->busNames)) {
115117
$style->block(sprintf('Bus "%s" is not defined.', $busName), null, 'error', ' ', true);
116118

117119
if (1 === \count($alternatives)) {
@@ -135,7 +137,7 @@ protected function execute(InputInterface $input, OutputInterface $output): void
135137
}
136138

137139
if (!$this->busLocator->has($busName = $input->getOption('bus'))) {
138-
throw new RuntimeException(sprintf('Bus "%s" does not exist.', $receiverName));
140+
throw new RuntimeException(sprintf('Bus "%s" does not exist.', $busName));
139141
}
140142

141143
$receiver = $this->receiverLocator->get($receiverName);

src/Symfony/Component/Messenger/DependencyInjection/MessengerPass.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ private function registerHandlers(ContainerBuilder $container, array $busIds)
195195
->replaceArgument(0, ServiceLocatorTagPass::register($container, $buses))
196196
->replaceArgument(4, $busIds);
197197
}
198-
199198
}
200199

201200
private function guessHandledClasses(\ReflectionClass $handlerClass, string $serviceId): iterable

src/Symfony/Component/Messenger/Tests/Command/ConsumeMessagesCommandTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\DependencyInjection\ServiceLocator;
1616
use Symfony\Component\Messenger\Command\ConsumeMessagesCommand;
17-
use Symfony\Component\Messenger\MessageBus;
1817

1918
class ConsumeMessagesCommandTest extends TestCase
2019
{

src/Symfony/Component/Messenger/Tests/DependencyInjection/MessengerPassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public function testItRegistersMultipleReceiversAndSetsTheReceiverNamesOnTheComm
245245
new Reference('messenger.receiver_locator'),
246246
null,
247247
null,
248-
null
248+
null,
249249
));
250250

251251
$container->register(AmqpReceiver::class, AmqpReceiver::class)->addTag('messenger.receiver', array('alias' => 'amqp'));

0 commit comments

Comments
 (0)
0