Skip to content

[Notifier] make Message classes extensible #45402

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 19, 2022
Merged

[Notifier] make Message classes extensible #45402

merged 1 commit into from
Feb 19, 2022

Conversation

bitgandtter
Copy link
Contributor

@bitgandtter bitgandtter commented Feb 11, 2022

Q A
Branch? 6.1
Bug fix? no
New feature? yes
Deprecations? no
Tickets NA
License MIT
Doc PR

@carsonbot carsonbot added this to the 6.1 milestone Feb 11, 2022
@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 6.1 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@OskarStark OskarStark changed the title [NotifierComponent] make PushNotificationInterface flexible to extend [Notifier] make PushNotificationInterface flexible to extend Feb 11, 2022
@carsonbot
Copy link

Hey!

I think @norkunas has recently worked with this code. Maybe they can help review this?

Cheers!

Carsonbot

@@ -16,7 +16,7 @@
/**
* @author Tomas Norkūnas <norkunas.tom@gmail.com>
*/
final class PushMessage implements MessageInterface
final class PushMessage implements PushMessageInterface
Copy link
Member

Choose a reason for hiding this comment

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

I'd rather make PushMessage non final and remove the interface; value objects should not be final.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I change it?

Copy link
Member

Choose a reason for hiding this comment

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

that's what I think

Copy link
Contributor Author

Choose a reason for hiding this comment

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

im willing to, but notice that said implementing an interface first introduce a contract and secondly allow implementation vs extension which its always good

Copy link
Member

@nicolas-grekas nicolas-grekas Feb 13, 2022

Choose a reason for hiding this comment

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

My experience is that interfaces are needed to abstract services, but here we are representing data. A value object, thus a class, is SOLID enough to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i have not found on the doc or on the code anyway to pass options to the transport from the notifier service, I can only do it using a new notification and that blocks me because of the message as explained above

Copy link
Contributor

Choose a reason for hiding this comment

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

PushMessage constructor accepts options as a third argument, so your transport could define options on it's own and then in the asPushMessage method you could do something like:

if ($transport === 'pusher') {
  $options = (new PusherOptions())->channels(..);

  return new PushMessage(.., $options);
}

And in the transport you could check if that option is defined then use it to make api call

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got it. I can close this now but I advise to look at the options to include interfaces or drop the final on value objects as Nicolas propose

Copy link
Member

@nicolas-grekas nicolas-grekas Feb 14, 2022

Choose a reason for hiding this comment

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

Putting a final on a class that is referenced by an interface is an API-design bad practice to me, because it kills any extensibility. I'm still for removing the keyword.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed and done

@nicolas-grekas nicolas-grekas changed the title [Notifier] make PushNotificationInterface flexible to extend [Notifier] make Message classes extensible Feb 18, 2022
@carsonbot carsonbot changed the title [Notifier] make Message classes extensible make Message classes extensible Feb 18, 2022
@carsonbot carsonbot changed the title make Message classes extensible [Notifier] make Message classes extensible Feb 19, 2022
@fabpot
Copy link
Member

fabpot commented Feb 19, 2022

Thank you @bitgandtter.

@fabpot fabpot merged commit 41fe721 into symfony:6.1 Feb 19, 2022
@fabpot fabpot mentioned this pull request Apr 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants