Skip to content

Commit def7896

Browse files
committed
Address the last reviews
1 parent dee278c commit def7896

File tree

9 files changed

+25
-18
lines changed

9 files changed

+25
-18
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/MessageConsumeCommand.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,15 @@ protected function configure()
5050
new InputArgument('receiver', InputArgument::REQUIRED, 'Name of the receiver'),
5151
new InputOption('limit', 'l', InputOption::VALUE_REQUIRED, 'Limit the number of received messages'),
5252
))
53-
->setDescription('Consumes a message')
53+
->setDescription('Consumes messages')
5454
->setHelp(<<<'EOF'
55-
The <info>%command.name%</info> command consumes a message and dispatches it to the message bus.
55+
The <info>%command.name%</info> command consumes messages and dispatches them to the message bus.
5656
57-
<info>php %command.full_name% <consumer-service-name></info>
57+
<info>php %command.full_name% <receiver-name></info>
58+
59+
Use the --limit option to limit the number of messages received:
60+
61+
<info>php %command.full_name% <receiver-name> --limit=10</info>
5862
EOF
5963
)
6064
;

src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -388,14 +388,12 @@ protected function isCsrfTokenValid(string $id, ?string $token): bool
388388
*
389389
* @param object $message The message to dispatch
390390
*
391-
* @return mixed The result from the bus
392-
*
393391
* @final
394392
*/
395-
protected function dispatch($message)
393+
protected function dispatchMessage($message)
396394
{
397395
if (!$this->container->has('message_bus')) {
398-
throw new \LogicException('The message bus is not enabled in your application. Enable it with the "message" key in "config/packages/framework.yaml".');
396+
throw new \LogicException('The message bus is not enabled in your application. Try running "composer require symfony/message".');
399397
}
400398

401399
return $this->container->get('message_bus')->dispatch($message);

src/Symfony/Component/Message/Asynchronous/Routing/SenderLocatorInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
interface SenderLocatorInterface
2020
{
2121
/**
22-
* Get the producer (if applicable) for the given message object.
22+
* Gets the producer (if applicable) for the given message object.
2323
*
2424
* @param object $message
2525
*

src/Symfony/Component/Message/ContainerHandlerLocator.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ public function __construct(ContainerInterface $container)
2929

3030
public function resolve($message): callable
3131
{
32-
$messageKey = get_class($message);
32+
$messageClass = get_class($message);
33+
$handlerKey = 'handler.'.$messageClass;
3334

34-
if (!$this->container->has($messageKey)) {
35-
throw new NoHandlerForMessageException(sprintf('No handler for message "%s".', $messageKey));
35+
if (!$this->container->has($handlerKey)) {
36+
throw new NoHandlerForMessageException(sprintf('No handler for message "%s".', $messageClass));
3637
}
3738

38-
return $this->container->get($messageKey);
39+
return $this->container->get($handlerKey);
3940
}
4041
}

src/Symfony/Component/Message/DependencyInjection/MessagePass.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,13 @@ private function registerHandlers(ContainerBuilder $container)
9393
}
9494
$container->addDefinitions($definitions);
9595

96+
$handlersLocatorMapping = [];
97+
foreach ($handlersByMessage as $message => $handler) {
98+
$handlersLocatorMapping['handles.'.$message] = $handler;
99+
}
100+
96101
$handlerResolver = $container->getDefinition($this->messageHandlerResolverService);
97-
$handlerResolver->replaceArgument(0, ServiceLocatorTagPass::register($container, $handlersByMessage));
102+
$handlerResolver->replaceArgument(0, ServiceLocatorTagPass::register($container, $handlersLocatorMapping));
98103
}
99104

100105
private function guessHandledClass(ContainerBuilder $container, string $serviceId): string

src/Symfony/Component/Message/HandlerLocatorInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
interface HandlerLocatorInterface
2020
{
2121
/**
22-
* Return the handler for the given message.
22+
* Returns the handler for the given message.
2323
*
2424
* @param object $message
2525
*

src/Symfony/Component/Message/MiddlewareInterface.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
interface MiddlewareInterface
1818
{
1919
/**
20-
* @param object $message
21-
* @param callable $next
20+
* @param object $message
2221
*
2322
* @return mixed
2423
*/

src/Symfony/Component/Message/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Message Component
22
=================
33

4-
The Message component helps application to send and receive messages to/from other applications or via
4+
The Message component helps application send and receive messages to/from other applications or via
55
message queues.
66

77
Resources

src/Symfony/Component/Message/Transport/Enhancers/MaximumCountReceiver.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function receive(): iterable
4040
$iterator->throw($e);
4141
}
4242

43-
if (++$receivedMessages > $this->maximumNumberOfMessages) {
43+
if (++$receivedMessages >= $this->maximumNumberOfMessages) {
4444
break;
4545
}
4646
}

0 commit comments

Comments
 (0)