10000 feature #47864 [DoctrineBridge] Deprecate calling `ContainerAwareEven… · symfony/symfony@1ccb56f · GitHub
[go: up one dir, main page]

Skip to content

Commit 1ccb56f

Browse files
committed
feature #47864 [DoctrineBridge] Deprecate calling ContainerAwareEventManager::getListeners() without event name (derrabus)
This PR was merged into the 6.2 branch. Discussion ---------- [DoctrineBridge] Deprecate calling `ContainerAwareEventManager::getListeners()` without event name | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | no | New feature? | no | Deprecations? | yes | Tickets | N/A | License | MIT | Doc PR | N/A With EventManager 1.2, calling `EventManager::getListeners()` without an event name has been deprecated. We should do the same for our `ContainerAwareEventManager`. Commits ------- af24827 Deprecate calling ContainerAwareEventManager::getListeners() without event
2 parents 0055d0f + af24827 commit 1ccb56f

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"composer-runtime-api": ">=2.1",
3737
"ext-xml": "*",
3838
"friendsofphp/proxy-manager-lts": "^1.0.2",
39-
"doctrine/event-manager": "^1|^2",
39+
"doctrine/event-manager": "^1.2|^2",
4040
"doctrine/persistence": "^2|^3",
4141
"twig/twig": "^2.13|^3.0.4",
4242
"psr/cache": "^2.0|^3.0",

src/Symfony/Bridge/Doctrine/ContainerAwareEventManager.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ public function dispatchEvent($eventName, EventArgs $eventArgs = null): void
7070
public function getListeners($event = null): array
7171
{
7272
if (null === $event) {
73+
trigger_deprecation('symfony/doctrine-bridge', '6.2', 'Calling "%s()" without an event name is deprecated. Call "getAllListeners()" instead.', __METHOD__);
74+
7375
return $this->getAllListeners();
7476
}
7577
if (!$this->initializedSubscribers) {

src/Symfony/Bridge/Doctrine/Tests/ContainerAwareEventManagerTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@
1414
use Doctrine\Common\EventSubscriber;
1515
use PHPUnit\Framework\TestCase;
1616
use Symfony\Bridge\Doctrine\ContainerAwareEventManager;
17+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1718
use Symfony\Component\DependencyInjection\Container;
1819

1920
class ContainerAwareEventManagerTest extends TestCase
2021
{
22+
use ExpectDeprecationTrait;
23+
2124
private $container;
2225
private $evm;
2326

@@ -171,12 +174,17 @@ public function testGetListenersForEvent()
171174
$this->assertSame([$subscriber1, $listener1, $listener2], array_values($this->evm->getListeners('foo')));
172175
}
173176

177+
/**
178+
* @group legacy
179+
*/
174180
public function testGetListeners()
175181
{
176182
$this->container->set('lazy', $listener1 = new MyListener());
177183
$this->evm->addEventListener('foo', 'lazy');
178184
$this->evm->addEventListener('foo', $listener2 = new MyListener());
179185

186+
$this->expectDeprecation('Since symfony/doctrine-bridge 6.2: Calling "Symfony\Bridge\Doctrine\ContainerAwareEventManager::getListeners()" without an event name is deprecated. Call "getAllListeners()" instead.');
187+
180188
$this->assertSame([$listener1, $listener2], array_values($this->evm->getListeners()['foo']));
181189
}
182190

src/Symfony/Bridge/Doctrine/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=8.1",
20-
"doctrine/event-manager": "^1|^2",
20+
"doctrine/event-manager": "^1.2|^2",
2121
"doctrine/persistence": "^2|^3",
2222
"symfony/deprecation-contracts": "^2.1|^3",
2323
"symfony/polyfill-ctype": "~1.8",

0 commit comments

Comments
 (0)
0