-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle][EventDispatcher] Add priorities to the debug:event-dispatcher command #14563
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/event_dispatcher_1_event1.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
[ | ||
{ | ||
"type": "function", | ||
"name": "global_function" | ||
"name": "global_function", | ||
"priority": 255 | ||
}, | ||
{ | ||
"type": "closure" | ||
"type": "closure", | ||
"priority": -1 | ||
} | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,9 @@ | |
|
||
- Type: `function` | ||
- Name: `global_function` | ||
- Priority: `255` | ||
|
||
## Listener 2 | ||
|
||
- Type: `closure` | ||
- Priority: `-1` |
12 changes: 6 additions & 6 deletions
12
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/event_dispatcher_1_event1.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
<info>[event_dispatcher]</info> Registered listeners for event <info>event1</info> | ||
|
||
+-------+-------------------+ | ||
| Order | Callable | | ||
+-------+-------------------+ | ||
| #1 | global_function() | | ||
| #2 | \Closure() | | ||
+-------+-------------------+ | ||
+-------+-------------------+----------+ | ||
| Order | Callable | Priority | | ||
+-------+-------------------+----------+ | ||
| #1 | global_function() | 255 | | ||
| #2 | \Closure() | -1 | | ||
+-------+-------------------+----------+ |
4 changes: 2 additions & 2 deletions
4
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/event_dispatcher_1_event1.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<event-dispatcher> | ||
<callable type="function" name="global_function"/> | ||
<callable type="closure"/> | ||
<callable type="function" name="global_function" priority="255"/> | ||
<callable type="closure" priority="-1"/> | ||
</event-dispatcher> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 11 additions & 11 deletions
22
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/event_dispatcher_1_events.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
<info>[event_dispatcher]</info> Registered listeners by event | ||
|
||
<info>[Event]</info> event1 | ||
+-------+-------------------+ | ||
| Order | Callable | | ||
+-------+-------------------+ | ||
| #1 | global_function() | | ||
| #2 | \Closure() | | ||
+-------+-------------------+ | ||
+-------+-------------------+----------+ | ||
| Order | Callable | Priority | | ||
+-------+-------------------+----------+ | ||
| #1 | global_function() | 255 | | ||
| #2 | \Closure() | -1 | | ||
+-------+-------------------+----------+ | ||
|
||
<info>[Event]</info> event2 | ||
+-------+-----------------------------------------------------------------------------------+ | ||
| Order | Callable | | ||
+-------+-----------------------------------------------------------------------------------+ | ||
| #1 | Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor\CallableClass::__invoke() | | ||
+-------+-----------------------------------------------------------------------------------+ | ||
+-------+-----------------------------------------------------------------------------------+----------+ | ||
| Order | Callable | Priority | | ||
+-------+-----------------------------------------------------------------------------------+----------+ | ||
| #1 | Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor\CallableClass::__invoke() | 0 | | ||
+-------+-----------------------------------------------------------------------------------+----------+ |
6 changes: 3 additions & 3 deletions
6
src/Symfony/Bundle/FrameworkBundle/Tests/Fixtures/Descriptor/event_dispatcher_1_events.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<event-dispatcher> | ||
<event name="event1"> | ||
<callable type="function" name="global_function"/> | ||
<callable type="closure"/> | ||
<callable type="function" name="global_function" priority="255"/> | ||
<callable type="closure" priority="-1"/> | ||
</event> | ||
<event name="event2"> | ||
<callable type="object" name="Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor\CallableClass"/> | ||
<callable type="object" name="Symfony\Bundle\FrameworkBundle\Tests\Console\Descriptor\CallableClass" priority="0"/> | ||
</event> | ||
</event-dispatcher> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,8 +58,12 @@ public function dispatch($eventName, Event $event = null) | |
/** | ||
* @see EventDispatcherInterface::getListeners() | ||
*/ | ||
public function getListeners($eventName = null) | ||
public function getListeners($eventName = null, $withPriorities = false) | ||
{ | ||
if (true === $withPriorities) { | ||
return $eventName ? $this->listeners[$eventName] : array_filter($this->listeners); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is broken when there is no listener for $eventName |
||
} | ||
|
||
if (null !== $eventName) { | ||
if (!isset($this->sorted[$eventName])) { | ||
$this->sortListeners($eventName); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We could just replace the "Order" column with priority don't you think ? The "Order" column was just there because it was impossible to get priorities in dispatcher !
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.
Yes I wasn't quite sure why the Order column was there, maybe for people who can't count :P If you'd like to send a PR to remove it from the TextDescriptor that sounds good to me.
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.
I prefer to keep both , the order is useful when events have the same priority.
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.
The command already list the events by order so the information is still available. But finally I think it's more developer friendly to keep it, you don't have to know how Symfony manage order internally 👍