-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
[7.x] Improve event subscribers #33191
Conversation
147a498
to
9434ff2
Compare
|
||
if (is_array($events)) { | ||
foreach ($events as $event => $listeners) { | ||
foreach (array_unique($listeners) as $listener) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👎 for the array_unique
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
foreach ($events as $event => $listeners) { |
this is copied from the above link, I kept it an exact copy, in case you want to extract the logic into a single method, to be reused.
If it is to be removed, better to be removed from both places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is in the service provider for a different reason. It is not needed here. I will remove it.
75c1b5d
to
e1dd3ba
Compare
47fb6cf
to
f9109fb
Compare
f9109fb
to
929d326
Compare
This allows the event subscribers to return an array like the
$listen
property on theEventsServiceProvider
In fact, it introduces some syntactic sugar, by removing
$events->listen(
also improves the doc-block of the public interface.
The example in laravel documentation:
Can be refactored to:
This is mostly backward compatible except in case someone returns a sequential array from the subscriber for no reason.
(It is possible to make is fully backward compatible by checking the array is assoc but it has performance hit, in the boot phase.)
EventServiceProvider.php
which can be refactored if accepted.(the two nested foreach loops are copy/pasted)
framework/src/Illuminate/Foundation/Support/Providers/EventServiceProvider.php
Line 34 in 192356b