Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[EventDispatcher] added EventDispatcher::getListenerPriority() #16198

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
Oct 12, 2015

Conversation

fabpot
Copy link
Member

@fabpot fabpot commented Oct 11, 2015

Q A
Bug fix? yes
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #14563, #15825
License MIT
Doc PR n/a

In #14563, we added a way to get the priorities of listeners, but as noted by @Tobion in #15825, the implementation is sub-optimal because of two main reasons: the change is not part of the interface but more importantly, the added boolean changes the return value of getListeners().

This PR reverts most of #14563 to add a getListenerPriority() method. This method is quite slow, but as it should only be used for debugging purposes (on the CLI or the WDT), I think it's not really a problem.

In 3.0, this method should probably be added to EventDispatcherInterface.

ping @Tobion

@@ -177,8 +192,6 @@ protected function doDispatch($listeners, $eventName, Event $event)
*/
private function sortListeners($eventName)
{
$this->sorted[$eventName] = array();
Copy link
Member Author

Choose a reason for hiding this comment

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

not needed as we override the value just afterwards.

@fabpot
Copy link
Member Author

fabpot commented Oct 11, 2015

Doing git diff 2.7...fabpot/event-listener-priorities src/Symfony/Component/EventDispatcher locally can help see the difference between what we have in 2.7 and what we will have in 2.8.

See https://gist.github.com/fabpot/4a32cb5b961a3f454d89

@fabpot fabpot closed this Oct 11, 2015
@fabpot fabpot reopened this Oct 11, 2015
@fabpot fabpot force-pushed the event-listener-priorities branch from 0ebb50f to 309dc63 Compare October 11, 2015 09:34
*/
public function getListenerPriority($eventName, $listener)
{
if (null === $eventName) {
Copy link
Member

Choose a reason for hiding this comment

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

this does not make sense. It cannot be null

Copy link
Member Author

Choose a reason for hiding this comment

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

indeed, wrong copy/paste. fixed

@fabpot fabpot force-pushed the event-listener-priorities branch from 309dc63 to 068e955 Compare October 11, 2015 14:56
@fabpot fabpot merged commit 068e955 into symfony:2.8 Oct 12, 2015
fabpot added a commit that referenced this pull request Oct 12, 2015
…iority() (fabpot)

This PR was merged into the 2.8 branch.

Discussion
----------

[EventDispatcher] added EventDispatcher::getListenerPriority()

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #14563, #15825
| License       | MIT
| Doc PR        | n/a

In #14563, we added a way to get the priorities of listeners, but as noted by @Tobion in #15825, the implementation is sub-optimal because of two main reasons: the change is not part of the interface but more importantly, the added boolean changes the return value of `getListeners()`.

This PR reverts most of #14563 to add a `getListenerPriority()` method. This method is quite slow, but as it should only be used for debugging purposes (on the CLI or the WDT), I think it's not really a problem.

In 3.0, this method should probably be added to `EventDispatcherInterface`.

ping @Tobion

Commits
-------

068e955 [EventDispatcher] added EventDispatcher::getListenerPriority()
* Returns null if the event or the listener does not exist.
*
* @param string $eventName The name of the event
* @param callable $listener The listener to remove
Copy link
Contributor

Choose a reason for hiding this comment

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

typo

Tobion added a commit that referenced this pull request Oct 22, 2015
This PR was merged into the 2.8 branch.

Discussion
----------

[EventDispatcher] fix docblock

| Q             | A
| ------------- | ---
| Fixed tickets | #16198 (comment)
| License       | MIT

Commits
-------

6e515fb [EventDispatcher] fix docblock
Tobion added a commit that referenced this pull request Oct 23, 2015
…interface (xabbuh)

This PR was merged into the 3.0-dev branch.

Discussion
----------

[EventDispatcher] add method getListenerPriority() to interface

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | yes
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #16198
| License       | MIT
| Doc PR        | todo

Commits
-------

f8019c8 add method getListenerPriority() to interface
@fabpot fabpot mentioned this pull request Nov 16, 2015
jmikola added a commit to jmikola/WildcardEventDispatcher that referenced this pull request Sep 9, 2016
For the time being, do not support wildcard patterns with getListenerPriority().

An exception will be thrown if getListenerPriority() is not implemented on the inner dispatcher. The method was added in symfony/symfony#16198 for Symfony 2.8. It was added to the interface in Symfony 3.0, which is relevant for our test cases.
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.

4 participants