Skip to content

Commit f553891

Browse files
committed
Merge branch '6.1' into 6.2
* 6.1: [DoctrineBridge] Implement EventManager::getAllListeners()
2 parents f15fa38 + dcccf84 commit f553891

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

ContainerAwareEventManager.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,23 @@ public function dispatchEvent($eventName, EventArgs $eventArgs = null): void
6969
*/
7070
public function getListeners($event = null): array
7171
{
72+
if (null === $event) {
73+
return $this->getAllListeners();
74+
}
7275
if (!$this->initializedSubscribers) {
7376
$this->initializeSubscribers();
7477
}
75-
if (null !== $event) {
76-
if (!isset($this->initialized[$event])) {
77-
$this->initializeListeners($event);
78-
}
78+
if (!isset($this->initialized[$event])) {
79+
$this->initializeListeners($event);
80+
}
7981

80-
return $this->listeners[$event];
82+
return $this->listeners[$event];
83+
}
84+
85+
public function getAllListeners(): array
86+
{
87+
if (!$this->initializedSubscribers) {
88+
$this->initializeSubscribers();
8189
}
8290

8391
foreach ($this->listeners as $event => $listeners) {

Tests/ContainerAwareEventManagerTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,15 @@ public function testGetListeners()
180180
$this->assertSame([$listener1, $listener2], array_values($this->evm->getListeners()['foo']));
181181
}
182182

183+
public function testGetAllListeners()
184+
{
185+
$this->container->set('lazy', $listener1 = new MyListener());
186+
$this->evm->addEventListener('foo', 'lazy');
187+
$this->evm->addEventListener('foo', $listener2 = new MyListener());
188+
189+
$this->assertSame([$listener1, $listener2], array_values($this->evm->getAllListeners()['foo']));
190+
}
191+
183192
public function testRemoveEventListener()
184193
{
185194
$this->container->set('lazy', $listener1 = new MyListener());

0 commit comments

Comments
 (0)