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

[Notifier] Remove default transport property in Transports class#35834

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

Conversation

@jschaedl
Copy link
Contributor

QA
Branch?master
Bug fix?no
New feature?yes
Deprecations?no
Tickets-
LicenseMIT
Doc PRtbd.

At the moment theTransports class uses the first element of the injected transports array as the default transport:https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Notifier/Transport/Transports.php#L35

If you try to send a message that doesn't define a transport (!$message->getTransport()) the default transport is used. I see two main drawbacks with this solution that I try to fix with this PR:

  1. There is no check if the given message is supported by the default transport. What means that the transport is going to fail with an Exception, if it's not supporting the given message. E.g. theSlackTransport only supportsChatMessages with nullable options or options from typeSlackOptions. So as a default transport theSlackTransport can't handle all types ofChatMessages.

  2. Why should we only send the message using the default transport if there are more possible transports which are probably supported?

I did the following to fix the mentioned drawbacks:

  • removed the default transport property
  • added a check to make sure the transport defined by the message supports it
  • send the message toall supported transports, in case the given message does not define a transport
  • added a test

{
if (null ===$transportName) {
thrownewLogicException('A Chat notification must have a transport defined.');
}
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I don't see a reason for this restriction. All the other channels don't have it either.

@nicolas-grekasnicolas-grekas added this to thenext milestoneFeb 24, 2020
@jschaedljschaedl mentioned this pull requestFeb 24, 2020
6 tasks
@jschaedljschaedlforce-pushed thenotifier-transports-improvement branch fromb6a2d24 toa5c207bCompareFebruary 28, 2020 14:05
fabpot added a commit that referenced this pull requestMar 16, 2020
This PR was merged into the 5.0 branch.Discussion----------[Notifier] Add unit tests| Q             | A| ------------- | ---| Branch?       | 5.0| Bug fix?      | no| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->| Tickets       | - <!-- prefix each issue number with "Fix #", if any -->| License       | MIT| Doc PR        | - <!-- required for new features -->- [x] `AbstractChannel`- [x] `ChannelPolicy`- [x] `RecipientTest` (done in PR#35773)- [x] `EmailRecipientTest` (done in PR#35773)- [x] `SmsRecipientTest` (done in PR#35773)- [x] `Transports` (see PR#35834)Commits-------022c170 [Notifier] Add tests for AbstractChannel and ChannelPolicy
@jschaedl
Copy link
ContributorAuthor

jschaedl commentedMar 24, 2020
edited
Loading

Hi@fabpot,

what do you think about removing the default transport in theTransports class?

foreach ($this->transportsas$transport) {
if ($transport->supports($message)) {
$transport->send($message);
++$supportedTransportsCount;
Copy link
Member

Choose a reason for hiding this comment

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

Instead of sending it through all available transports, I would only send it to the first one. That would be more consistent with my idea of a default transport and probably what I would expect. I would probably not expect to receive 2 SMSes for instance. When you want to dispatch to more than one transport, you need to be explicit.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Hmm, ok. If I only define a channel name in the channel policy configuration, I actually expected the notification to be broadcasted to all supported transports defined in this channel. For me personally I wouldn't need a default transport. But I also see that this broadcasting approach might be confusing in some situations and a default channel is a good idea. Will change this.

@jschaedljschaedlforce-pushed thenotifier-transports-improvement branch froma5c207b to066990bCompareApril 15, 2020 06:43
@jschaedljschaedlforce-pushed thenotifier-transports-improvement branch from51e8352 to96218d3CompareJune 12, 2020 08:09
@jschaedl
Copy link
ContributorAuthor

@fabpot friendly ping :-)

I changed the code according to your comment. WDYT?

@fabpotfabpotforce-pushed thenotifier-transports-improvement branch from96218d3 to5c167b0CompareJune 12, 2020 12:23
@fabpot
Copy link
Member

Thank you@jschaedl.

jschaedl reacted with hooray emoji

@fabpotfabpot mentioned this pull requestOct 5, 2020
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

+1 more reviewer

@dbrumanndbrumanndbrumann approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

5.2

Development

Successfully merging this pull request may close these issues.

5 participants

@jschaedl@fabpot@dbrumann@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp