[Messenger] Add a SenderLocator decoupled from ContainerInterface#28399
Merged
Conversation
ffb169c to
11a457f
Compare
sroze
suggested changes
Sep 8, 2018
sroze
left a comment
Contributor
There was a problem hiding this comment.
A test for the SenderLocator? 😉
| ----- | ||
|
|
||
| * [BC BREAK] `SenderLocator` has been renamed to `ContainerSenderLocator` | ||
| Be careful as there is still a `SenderLocator` class, but it does not rely on a ContainerInterface to find senders |
Contributor
There was a problem hiding this comment.
- but it does not rely on a ContainerInterface to find senders
+ but it does not rely on a `ContainerInterface` to find senders. Instead, it accepts the sender instance itself instead of its identifier in the container.?
| } | ||
|
|
||
| return null; | ||
| return self::getValueFromMessageRouting($this->messageToSenderMapping, $message); |
Contributor
There was a problem hiding this comment.
Especially with the BC-break, it would be very good to have an explicit exception if this return value is not a SenderInterface. For example:
if (!$sender instanceof SenderInterface) {
throw new RuntimeException(sprintf('The sender instance provided for the message "%s" should be of type "%s" but got "%s"', $message, SenderInterface::class, is_object($sender) ? get_class($sender) : gettype($sender));
}11a457f to
4204d54
Compare
sroze
reviewed
Sep 8, 2018
| return $mapping['*']; | ||
| $sender = self::getValueFromMessageRouting($this->messageToSenderMapping, $message); | ||
| if (!$sender instanceof SenderInterface) { | ||
| throw new RuntimeException(sprintf('The sender instance provided for message "%s" should be of type "%s" but got "%s".', \get_class($message), SenderInterface::class, is_object($sender) ? get_class($sender) : gettype($sender))); |
ecc9a92 to
9bed828
Compare
Member
Author
|
Now with some tests. |
sroze
reviewed
Sep 8, 2018
| /** | ||
| * @author Samuel Roze <[email protected]> | ||
| */ | ||
| abstract class AbstractSenderLocator implements SenderLocatorInterface |
Contributor
There was a problem hiding this comment.
What's the reasoning for using an abstract class over a trait for this static method?
Member
Author
There was a problem hiding this comment.
As it is used in SendMessageMiddleware, I think it's "better" like this.
9bed828 to
e658e15
Compare
sroze
approved these changes
Sep 8, 2018
fabpot
added a commit
that referenced
this pull request
Sep 8, 2018
…erInterface (fabpot)
This PR was merged into the 4.2-dev branch.
Discussion
----------
[Messenger] Add a SenderLocator decoupled from ContainerInterface
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | yes
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | n/a
| License | MIT
| Doc PR | upcoming
For handler locators, we have a generic `HandlerLocator` class that takes a simple mapping instead of a service locator. The same did not exist for sender locators. So, this PR adds this possibility as well. That allows for something like this:
```php
new MessageBus([
new SendMessageMiddleware(new SenderLocator([
Message::class => new AmqpTransport($encoderDecoder, $encoderDecoder, $connection),
])),
new HandleMessageMiddleware(new HandlerLocator([
Message::class => new MessageHandler(),
])),
]);
```
Commits
-------
e658e15 [Messenger] added a SenderLocator decoupled from ContainerInterface
This was referenced Nov 3, 2018
Closed
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For handler locators, we have a generic
HandlerLocatorclass that takes a simple mapping instead of a service locator. The same did not exist for sender locators. So, this PR adds this possibility as well. That allows for something like this: