mirror of
https://github.com/doctrine/event-manager.git
synced 2026-03-23 22:32:21 +01:00
Made the $event parameter of EventManager::getListeners() mandatory (#57)
This commit is contained in:
committed by
GitHub
parent
4eb21e37be
commit
95c15e5838
@@ -1,3 +1,11 @@
|
||||
# Upgrade to 2.0
|
||||
|
||||
## Made the `$event` parameter of `EventManager::getListeners()` mandatory
|
||||
|
||||
When calling `EventManager::getListeners()` you need to specify the event that
|
||||
you want to fetch the listeners for. Call `getAllListeners()` instead if you
|
||||
want to access the listeners of all events.
|
||||
|
||||
# Upgrade to 1.2
|
||||
|
||||
## Deprecated calling `EventManager::getListeners()` without an event name
|
||||
|
||||
@@ -4,8 +4,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Common;
|
||||
|
||||
use Doctrine\Deprecations\Deprecation;
|
||||
|
||||
use function spl_object_hash;
|
||||
|
||||
/**
|
||||
@@ -47,24 +45,12 @@ class EventManager
|
||||
/**
|
||||
* Gets the listeners of a specific event.
|
||||
*
|
||||
* @param string|null $event The name of the event.
|
||||
* @param string $event The name of the event.
|
||||
*
|
||||
* @return object[]|array<string, object[]> The event listeners for the specified event, or all event listeners.
|
||||
* @psalm-return ($event is null ? array<string, object[]> : object[])
|
||||
* @return object[]
|
||||
*/
|
||||
public function getListeners(string|null $event = null): array
|
||||
public function getListeners(string $event): array
|
||||
{
|
||||
if ($event === null) {
|
||||
Deprecation::trigger(
|
||||
'doctrine/event-manager',
|
||||
'https://github.com/doctrine/event-manager/pull/50',
|
||||
'Calling %s without an event name is deprecated. Call getAllListeners() instead.',
|
||||
__METHOD__
|
||||
);
|
||||
|
||||
return $this->getAllListeners();
|
||||
}
|
||||
|
||||
return $this->listeners[$event];
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ namespace Doctrine\Tests\Common;
|
||||
use Doctrine\Common\EventArgs;
|
||||
use Doctrine\Common\EventManager;
|
||||
use Doctrine\Common\EventSubscriber;
|
||||
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ReflectionProperty;
|
||||
|
||||
@@ -15,8 +14,6 @@ use function array_keys;
|
||||
|
||||
class EventManagerTest extends TestCase
|
||||
{
|
||||
use VerifyDeprecations;
|
||||
|
||||
/* Some pseudo events */
|
||||
private const PRE_FOO = 'preFoo';
|
||||
private const POST_FOO = 'postFoo';
|
||||
@@ -51,14 +48,6 @@ class EventManagerTest extends TestCase
|
||||
self::assertSame(['preFoo', 'postFoo'], array_keys($this->eventManager->getAllListeners()));
|
||||
}
|
||||
|
||||
public function testGetListenersDeprecation(): void
|
||||
{
|
||||
$this->eventManager->addEventListener(['preFoo', 'postFoo'], $this);
|
||||
|
||||
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/event-manager/pull/50');
|
||||
self::assertCount(2, $this->eventManager->getListeners());
|
||||
}
|
||||
|
||||
public function testDispatchEvent(): void
|
||||
{
|
||||
$this->eventManager->addEventListener(['preFoo', 'postFoo'], $this);
|
||||
|
||||
Reference in New Issue
Block a user