Skip to content

Mark all dispatched event classes as final #33152

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
Aug 21, 2019

Conversation

Tobion
Copy link
Contributor

@Tobion Tobion commented Aug 13, 2019

Q A
Branch? 4.4
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

I think we should mark all our Event classes as final. There is no point in people extending them as the libraries that use the event, will only dispatch this event. So extending events in user-land achieves nothing as the subclasses won't be dispatched.
I'm not talking about the base events that are meant to be extended like KernelEvent, but the leaf events like ExceptionEvent, ResponseEvent etc.
Then we can also make them real final in 5.0 as the events are value objects that should not be mocked.

@@ -20,7 +20,7 @@
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class MessageEvent extends Event
final class MessageEvent extends Event
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fabpot there is a MessageEvents class in the same mailer namespace. This can easily be confused with the event class and should maybe be renamed or relocated or even made internal.

Copy link
Member

Choose a reason for hiding this comment

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

isn't MessageEvents the class holding all event names as constants ? This is not internal

Copy link
Contributor Author

@Tobion Tobion Aug 21, 2019

Choose a reason for hiding this comment

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

The Mailer MessageEvents is a class used for logging and data collecting. It collects events but is not an event itself.

@chalasr chalasr added this to the next milestone Aug 13, 2019
nicolas-grekas added a commit that referenced this pull request Aug 21, 2019
…so we can make it final (Tobion)

This PR was merged into the 4.3 branch.

Discussion
----------

[HttpKernel] Do not extend the new SF 4.3 ControllerEvent so we can make it final

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | no
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| BC breaks?    | unlikely
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets |
| License       | MIT
| Doc PR        |

See #33152 (comment)
Remember the ControllerEvent is new in SF 4.3 so we just go back to what it was before 4.3

Commits
-------

00140b6 Do not extend the new SF 4.3 ControllerEvent so we can make it final
@nicolas-grekas
Copy link
Member

Thank you @Tobion.

nicolas-grekas added a commit that referenced this pull request Aug 21, 2019
This PR was merged into the 4.4 branch.

Discussion
----------

Mark all dispatched event classes as final

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets |
| License       | MIT
| Doc PR        |

I think we should mark all our Event classes as final. There is no point in people extending them as the libraries that use the event, will only dispatch this event. So extending events in user-land achieves nothing as the subclasses won't be dispatched.
I'm not talking about the base events that are meant to be extended like KernelEvent, but the leaf events like ExceptionEvent, ResponseEvent etc.
Then we can also make them real final in 5.0 as the events are value objects that should not be mocked.

Commits
-------

4bb38ee Mark all dispatched event classes as final
@nicolas-grekas nicolas-grekas merged commit 4bb38ee into symfony:4.4 Aug 21, 2019
@Tobion Tobion deleted the final-events branch August 21, 2019 15:51
fabpot added a commit that referenced this pull request Sep 8, 2019
This PR was merged into the 5.0-dev branch.

Discussion
----------

Make dispatched events really final

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets |
| License       | MIT
| Doc PR        |

Continuation of #33152 for master

Commits
-------

953057f Make dispatched events really final
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.4 Oct 27, 2019
This was referenced Nov 12, 2019
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.