You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature symfony#28275 [Messenger] Only subscribe to a given bus from the MessageSubscriber (sroze)
This PR was merged into the 4.2-dev branch.
Discussion
----------
[Messenger] Only subscribe to a given bus from the MessageSubscriber
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #... <!-- #-prefixed issue number(s), if any -->
| License | MIT
| Doc PR | ø
symfony#27275 introduced the ability to listen to only a few buses from the handler tag. This adds that ability directly from the message subscriber.
It has also highlighted to me that most of the configuration can be done using `yield` (like the example I've added in this PR's tests) and that we could remove the support for other ways (especially the obscure `return [['method', -10]]` syntax) but I believe this should be done **in another pull-request** (that I'm happy to do after this one).
Commits
-------
f60e409 Only subscribe to a given bus from the MessageSubscriber
$messageClassLocation = isset($tag['handles']) ? 'declared in your tag attribute "handles"' : $r->implementsInterface(MessageSubscriberInterface::class) ? sprintf('returned by method "%s::getHandledMessages()"', $r->getName()) : sprintf('used as argument type in method "%s::%s()"', $r->getName(), $method);
121
+
122
+
thrownewRuntimeException(sprintf('Invalid configuration %s for message "%s": bus "%s" does not exist.', $messageClassLocation, $messageClass, $method['bus']));
123
+
}
124
+
125
+
$buses = array($method['bus']);
126
+
}
127
+
128
+
if (isset($method['priority'])) {
129
+
$messagePriority = $method['priority'];
130
+
}
131
+
132
+
$method = $method['method'] ?? '__invoke';
133
+
} else {
134
+
$messageClassLocation = isset($tag['handles']) ? 'declared in your tag attribute "handles"' : $r->implementsInterface(MessageSubscriberInterface::class) ? sprintf('returned by method "%s::getHandledMessages()"', $r->getName()) : sprintf('used as argument type in method "%s::%s()"', $r->getName(), $method);
135
+
136
+
thrownewRuntimeException(sprintf('Invalid configuration %s for message "%s".', $messageClassLocation, $messageClass));
137
+
}
115
138
}
116
139
117
140
if (!\class_exists($messageClass)) {
@@ -132,7 +155,7 @@ private function registerHandlers(ContainerBuilder $container, array $busIds)
* @expectedExceptionMessage Invalid configuration returned by method "Symfony\Component\Messenger\Tests\DependencyInjection\HandlerOnUndefinedBus::getHandledMessages()" for message "Symfony\Component\Messenger\Tests\Fixtures\DummyMessage": bus "some_undefined_bus" does not exist.
0 commit comments