Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Messenger] Add a SenderLocator decoupled from ContainerInterface#28399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:masterfromfabpot:sender-locator
Sep 8, 2018

Conversation

@fabpot
Copy link
Member

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?yes
Deprecations?no
Tests pass?yes
Fixed ticketsn/a
LicenseMIT
Doc PRupcoming

For handler locators, we have a genericHandlerLocator 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:

newMessageBus([newSendMessageMiddleware(newSenderLocator([        Message::class =>newAmqpTransport($encoderDecoder,$encoderDecoder,$connection),    ])),newHandleMessageMiddleware(newHandlerLocator([        Message::class =>newMessageHandler(),    ])),]);

Copy link
Contributor

@srozesroze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

A test for theSenderLocator? 😉

-----

*[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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

- 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.

?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

done

}

returnnull;
returnself::getValueFromMessageRouting($this->messageToSenderMapping,$message);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Especially with the BC-break, it would be very good to have an explicit exception if this return value is not aSenderInterface. For example:

if (!$senderinstanceof SenderInterface) {thrownewRuntimeException(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));}

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Done

return$mapping['*'];
$sender =self::getValueFromMessageRouting($this->messageToSenderMapping,$message);
if (!$senderinstanceof SenderInterface) {
thrownewRuntimeException(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)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

2ndget_class hidden 😉

@fabpotfabpotforce-pushed thesender-locator branch 2 times, most recently fromecc9a92 to9bed828CompareSeptember 8, 2018 12:11
@fabpot
Copy link
MemberAuthor

Now with some tests.

/**
* @author Samuel Roze <samuel.roze@gmail.com>
*/
abstractclass AbstractSenderLocatorimplements SenderLocatorInterface
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

What's the reasoning for using an abstract class over a trait for thisstatic method?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

As it is used inSendMessageMiddleware, I think it's "better" like this.

@fabpotfabpot merged commite658e15 intosymfony:masterSep 8, 2018
fabpot added a commit that referenced this pull requestSep 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        | upcomingFor 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:```phpnew 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 referencedNov 3, 2018
@fabpotfabpot deleted the sender-locator branchJanuary 14, 2019 11:01
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

1 more reviewer

@srozesrozesroze approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@fabpot@sroze@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp