From ba70a484f1e252e4a6a1096a99cd72402d255517 Mon Sep 17 00:00:00 2001 From: Abdellatif Ait boudad Date: Mon, 5 Jan 2015 00:09:31 +0000 Subject: [PATCH 1/2] [3.0] [EventDispatcher][Event] removed deprecated setDispatcher and getDispatcher methods. --- .../Component/EventDispatcher/CHANGELOG.md | 6 ++++ .../Component/EventDispatcher/Event.php | 30 ----------------- .../EventDispatcher/EventDispatcher.php | 1 - .../Tests/AbstractEventDispatcherTest.php | 12 ------- .../ContainerAwareEventDispatcherTest.php | 1 - .../EventDispatcher/Tests/EventTest.php | 33 ------------------- 6 files changed, 6 insertions(+), 77 deletions(-) diff --git a/src/Symfony/Component/EventDispatcher/CHANGELOG.md b/src/Symfony/Component/EventDispatcher/CHANGELOG.md index bb42ee19c04ca..b43888d23842b 100644 --- a/src/Symfony/Component/EventDispatcher/CHANGELOG.md +++ b/src/Symfony/Component/EventDispatcher/CHANGELOG.md @@ -1,6 +1,12 @@ CHANGELOG ========= +3.0.0 +----- + + * The methods Event::setDispatcher(), Event::getDispatcher() have been removed. + The event dispatcher is passed to the listener call. + 2.5.0 ----- diff --git a/src/Symfony/Component/EventDispatcher/Event.php b/src/Symfony/Component/EventDispatcher/Event.php index e411ca81360ad..9a2ee15779c70 100644 --- a/src/Symfony/Component/EventDispatcher/Event.php +++ b/src/Symfony/Component/EventDispatcher/Event.php @@ -72,36 +72,6 @@ public function stopPropagation() $this->propagationStopped = true; } - /** - * Stores the EventDispatcher that dispatches this Event. - * - * @param EventDispatcherInterface $dispatcher - * - * @deprecated since version 2.4, to be removed in 3.0. The event dispatcher is passed to the listener call. - * - * @api - */ - public function setDispatcher(EventDispatcherInterface $dispatcher) - { - $this->dispatcher = $dispatcher; - } - - /** - * Returns the EventDispatcher that dispatches this Event. - * - * @return EventDispatcherInterface - * - * @deprecated since version 2.4, to be removed in 3.0. The event dispatcher is passed to the listener call. - * - * @api - */ - public function getDispatcher() - { - trigger_error('The '.__METHOD__.' method is deprecated since version 2.4 and will be removed in 3.0. The event dispatcher instance can be received in the listener call instead.', E_USER_DEPRECATED); - - return $this->dispatcher; - } - /** * Gets the event's name. * diff --git a/src/Symfony/Component/EventDispatcher/EventDispatcher.php b/src/Symfony/Component/EventDispatcher/EventDispatcher.php index 3b032fb081e34..6dc455eb3f9f8 100644 --- a/src/Symfony/Component/EventDispatcher/EventDispatcher.php +++ b/src/Symfony/Component/EventDispatcher/EventDispatcher.php @@ -43,7 +43,6 @@ public function dispatch($eventName, Event $event = null) $event = new Event(); } - $event->setDispatcher($this); $event->setName($eventName); if (!isset($this->listeners[$eventName])) { diff --git a/src/Symfony/Component/EventDispatcher/Tests/AbstractEventDispatcherTest.php b/src/Symfony/Component/EventDispatcher/Tests/AbstractEventDispatcherTest.php index d3278046fe84d..b4994f0500ec4 100644 --- a/src/Symfony/Component/EventDispatcher/Tests/AbstractEventDispatcherTest.php +++ b/src/Symfony/Component/EventDispatcher/Tests/AbstractEventDispatcherTest.php @@ -247,18 +247,6 @@ public function testRemoveSubscriberWithMultipleListeners() $this->assertFalse($this->dispatcher->hasListeners(self::preFoo)); } - public function testLegacyEventReceivesTheDispatcherInstance() - { - $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED); - - $dispatcher = null; - $this->dispatcher->addListener('test', function ($event) use (&$dispatcher) { - $dispatcher = $event->getDispatcher(); - }); - $this->dispatcher->dispatch('test'); - $this->assertSame($this->dispatcher, $dispatcher); - } - public function testEventReceivesTheDispatcherInstanceAsArgument() { $listener = new TestWithDispatcher(); diff --git a/src/Symfony/Component/EventDispatcher/Tests/ContainerAwareEventDispatcherTest.php b/src/Symfony/Component/EventDispatcher/Tests/ContainerAwareEventDispatcherTest.php index 6f2fbcb9df9ad..50326ee321bc3 100644 --- a/src/Symfony/Component/EventDispatcher/Tests/ContainerAwareEventDispatcherTest.php +++ b/src/Symfony/Component/EventDispatcher/Tests/ContainerAwareEventDispatcherTest.php @@ -164,7 +164,6 @@ public function testHasListenersOnLazyLoad() $dispatcher = new ContainerAwareEventDispatcher($container); $dispatcher->addListenerService('onEvent', array('service.listener', 'onEvent')); - $event->setDispatcher($dispatcher); $event->setName('onEvent'); $service diff --git a/src/Symfony/Component/EventDispatcher/Tests/EventTest.php b/src/Symfony/Component/EventDispatcher/Tests/EventTest.php index 8f2fb7358e325..272ab17e8a091 100644 --- a/src/Symfony/Component/EventDispatcher/Tests/EventTest.php +++ b/src/Symfony/Component/EventDispatcher/Tests/EventTest.php @@ -24,11 +24,6 @@ class EventTest extends \PHPUnit_Framework_TestCase */ protected $event; - /** - * @var \Symfony\Component\EventDispatcher\EventDispatcher - */ - protected $dispatcher; - /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. @@ -36,7 +31,6 @@ class EventTest extends \PHPUnit_Framework_TestCase protected function setUp() { $this->event = new Event(); - $this->dispatcher = new EventDispatcher(); } /** @@ -46,7 +40,6 @@ protected function setUp() protected function tearDown() { $this->event = null; - $this->dispatcher = null; } public function testIsPropagationStopped() @@ -59,30 +52,4 @@ public function testStopPropagationAndIsPropagationStopped() $this->event->stopPropagation(); $this->assertTrue($this->event->isPropagationStopped()); } - - public function testLegacySetDispatcher() - { - $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED); - $this->event->setDispatcher($this->dispatcher); - $this->assertSame($this->dispatcher, $this->event->getDispatcher()); - } - - public function testLegacyGetDispatcher() - { - $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED); - $this->assertNull($this->event->getDispatcher()); - } - - public function testLegacyGetName() - { - $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED); - $this->assertNull($this->event->getName()); - } - - public function testLegacySetName() - { - $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED); - $this->event->setName('foo'); - $this->assertEquals('foo', $this->event->getName()); - } } From 4ab3e8bba21f5e801d7652b0768f6475839d912c Mon Sep 17 00:00:00 2001 From: Abdellatif Ait boudad Date: Mon, 5 Jan 2015 16:43:43 +0000 Subject: [PATCH 2/2] [3.0] [EventDispatcher][Event] removed deprecated name methods. --- .../Component/EventDispatcher/CHANGELOG.md | 5 ++- .../Component/EventDispatcher/Event.php | 40 ------------------- .../EventDispatcher/EventDispatcher.php | 2 - .../Tests/AbstractEventDispatcherTest.php | 9 ----- .../ContainerAwareEventDispatcherTest.php | 2 - 5 files changed, 3 insertions(+), 55 deletions(-) diff --git a/src/Symfony/Component/EventDispatcher/CHANGELOG.md b/src/Symfony/Component/EventDispatcher/CHANGELOG.md index b43888d23842b..5057ca137912c 100644 --- a/src/Symfony/Component/EventDispatcher/CHANGELOG.md +++ b/src/Symfony/Component/EventDispatcher/CHANGELOG.md @@ -4,8 +4,9 @@ CHANGELOG 3.0.0 ----- - * The methods Event::setDispatcher(), Event::getDispatcher() have been removed. - The event dispatcher is passed to the listener call. + * The methods Event::setDispatcher(), Event::getDispatcher(), Event::setName() + and Event::setName() have been removed. + The event dispatcher and name is passed to the listener call. 2.5.0 ----- diff --git a/src/Symfony/Component/EventDispatcher/Event.php b/src/Symfony/Component/EventDispatcher/Event.php index 9a2ee15779c70..7b87c50977b31 100644 --- a/src/Symfony/Component/EventDispatcher/Event.php +++ b/src/Symfony/Component/EventDispatcher/Event.php @@ -34,16 +34,6 @@ class Event */ private $propagationStopped = false; - /** - * @var EventDispatcher Dispatcher that dispatched this event - */ - private $dispatcher; - - /** - * @var string This event's name - */ - private $name; - /** * Returns whether further event listeners should be triggered. * @@ -71,34 +61,4 @@ public function stopPropagation() { $this->propagationStopped = true; } - - /** - * Gets the event's name. - * - * @return string - * - * @deprecated since version 2.4, to be removed in 3.0. The event name is passed to the listener call. - * - * @api - */ - public function getName() - { - trigger_error('The '.__METHOD__.' method is deprecated since version 2.4 and will be removed in 3.0. The event name can be received in the listener call instead.', E_USER_DEPRECATED); - - return $this->name; - } - - /** - * Sets the event's name property. - * - * @param string $name The event name. - * - * @deprecated since version 2.4, to be removed in 3.0. The event name is passed to the listener call. - * - * @api - */ - public function setName($name) - { - $this->name = $name; - } } diff --git a/src/Symfony/Component/EventDispatcher/EventDispatcher.php b/src/Symfony/Component/EventDispatcher/EventDispatcher.php index 6dc455eb3f9f8..28db02271622a 100644 --- a/src/Symfony/Component/EventDispatcher/EventDispatcher.php +++ b/src/Symfony/Component/EventDispatcher/EventDispatcher.php @@ -43,8 +43,6 @@ public function dispatch($eventName, Event $event = null) $event = new Event(); } - $event->setName($eventName); - if (!isset($this->listeners[$eventName])) { return $event; } diff --git a/src/Symfony/Component/EventDispatcher/Tests/AbstractEventDispatcherTest.php b/src/Symfony/Component/EventDispatcher/Tests/AbstractEventDispatcherTest.php index b4994f0500ec4..fa4bbbbfbec63 100644 --- a/src/Symfony/Component/EventDispatcher/Tests/AbstractEventDispatcherTest.php +++ b/src/Symfony/Component/EventDispatcher/Tests/AbstractEventDispatcherTest.php @@ -121,15 +121,6 @@ public function testDispatch() $this->assertSame($event, $return); } - public function testLegacyDispatch() - { - $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED); - - $event = new Event(); - $return = $this->dispatcher->dispatch(self::preFoo, $event); - $this->assertEquals('pre.foo', $event->getName()); - } - public function testDispatchForClosure() { $invoked = 0; diff --git a/src/Symfony/Component/EventDispatcher/Tests/ContainerAwareEventDispatcherTest.php b/src/Symfony/Component/EventDispatcher/Tests/ContainerAwareEventDispatcherTest.php index 50326ee321bc3..24a04d9862462 100644 --- a/src/Symfony/Component/EventDispatcher/Tests/ContainerAwareEventDispatcherTest.php +++ b/src/Symfony/Component/EventDispatcher/Tests/ContainerAwareEventDispatcherTest.php @@ -164,8 +164,6 @@ public function testHasListenersOnLazyLoad() $dispatcher = new ContainerAwareEventDispatcher($container); $dispatcher->addListenerService('onEvent', array('service.listener', 'onEvent')); - $event->setName('onEvent'); - $service ->expects($this->once()) ->method('onEvent')