8000 [EventDispatcher] fix empty prio by hjanuschka · Pull Request #35260 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[EventDispatcher] fix empty prio #35260

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Fa 8000 iled to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Symfony/Component/EventDispatcher/EventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function getListeners(string $eventName = null)
public function getListenerPriority(string $eventName, $listener)
{
if (empty($this->listeners[$eventName])) {
return null;
return 0;
Copy link
Member

Choose a reason for hiding this comment

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

This looks wrong to me. The interface states this:

Returns null if the event or the listener does not exist.

Making this change here violates the contract defined by the interface.

}

if (\is_array($listener) && isset($listener[0]) && $listener[0] instanceof \Closure && 2 >= \count($listener)) {
Expand All @@ -114,7 +114,7 @@ public function getListenerPriority(string $eventName, $listener)
}
}

return null;
return 0;
Copy link
Member

Choose a reason for hiding this comment

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

same above

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function getListeners(string $eventName = null);
*
* @param callable $listener The listener
*
* @return int|null The event listener priority
* @return int The event listener priority, defaults to 0
Copy link
Member

Choose a reason for hiding this comment

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

changing this is a BC break

*/
public function getListenerPriority(string $eventName, $listener);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ public function testGetListenerPriority()

$this->assertSame(-10, $this->dispatcher->getListenerPriority('pre.foo', $listener1));
$this->assertSame(0, $this->dispatcher->getListenerPriority('pre.foo', $listener2));
$this->assertNull($this->dispatcher->getListenerPriority('pre.bar', $listener2));
$this->assertNull($this->dispatcher->getListenerPriority('pre.foo', function () {}));
$this->assertEquals($this->dispatcher->getListenerPriority('pre.bar', $listener2), 0);
$this->assertEquals($this->dispatcher->getListenerPriority('pre.foo', function () {}), 0);
}

public function testDispatch()
Expand Down
0