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

Skip to content

Commit b077e78

Browse files
srozeRobin Chalas
authored and
Robin Chalas
committed
Bus argument is a required option when multiple buses are defined
1 parent 78b7d8a commit b077e78

File tree

7 files changed

+20
-11
lines changed

7 files changed

+20
-11
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/Bundle/FrameworkBundle/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"symfony/security": "~3.4|~4.0",
4242
"symfony/form": "^4.1",
4343
"symfony/expression-language": "~3.4|~4.0",
44-
"symfony/messenger": "^4.1",
44+
"symfony/messenger": "^4.2",
4545
"symfony/process": "~3.4|~4.0",
4646
"symfony/security-core": "~3.4|~4.0",
4747
"symfony/security-csrf": "~3.4|~4.0",
@@ -67,6 +67,7 @@
6767
"symfony/asset": "<3.4",
6868
"symfony/console": "<3.4",
6969
"symfony/form": "<4.1",
70+
"symfony/messenger": "<4.2",
7071
"symfony/property-info": "<3.4",
7172
"symfony/serializer": "<4.1",
7273
"symfony/stopwatch": "<3.4",
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CHANGELOG
2+
=========
3+
4+
4.2.0
5+
-----
6+
7+
* [BC BREAK] The `ConsumeMessagesCommand` class now takes an instance of `Psr\Container\ContainerInterface` as
8+
first constructor argument.

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