Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[2.3][EventDispatcher] Make events lighter

  • Loading branch information...
commit e2bff32de77a444b0912d2c6399e75b5aa1605d6 1 parent 1099858
Drak authored fabpot committed
View
8 src/Symfony/Component/EventDispatcher/Event.php
@@ -76,6 +76,8 @@ public function stopPropagation()
*
* @param EventDispatcherInterface $dispatcher
*
+ * @deprecated since 2.3 remove in 3.0
+ *
* @api
*/
public function setDispatcher(EventDispatcherInterface $dispatcher)
@@ -88,6 +90,8 @@ public function setDispatcher(EventDispatcherInterface $dispatcher)
*
* @return EventDispatcherInterface
*
+ * @deprecated since 2.3 remove in 3.0
+ *
* @api
*/
public function getDispatcher()
@@ -100,6 +104,8 @@ public function getDispatcher()
*
* @return string
*
+ * @deprecated since 2.3 remove in 3.0
+ *
* @api
*/
public function getName()
@@ -112,6 +118,8 @@ public function getName()
*
* @param string $name The event name.
*
+ * @deprecated since 2.3 remove in 3.0
+ *
* @api
*/
public function setName($name)
View
2  src/Symfony/Component/EventDispatcher/EventDispatcher.php
@@ -161,7 +161,7 @@ public function removeSubscriber(EventSubscriberInterface $subscriber)
protected function doDispatch($listeners, $eventName, Event $event)
{
foreach ($listeners as $listener) {
- call_user_func($listener, $event);
+ call_user_func($listener, $event, $eventName, $this);
if ($event->isPropagationStopped()) {
break;
}
View
27 src/Symfony/Component/EventDispatcher/Tests/EventDispatcherTest.php
@@ -23,6 +23,9 @@ class EventDispatcherTest extends \PHPUnit_Framework_TestCase
const preBar = 'pre.bar';
const postBar = 'post.bar';
+ /**
+ * @var EventDispatcher
+ */
private $dispatcher;
private $listener;
@@ -237,7 +240,6 @@ public function testRemoveSubscriberWithMultipleListeners()
public function testEventReceivesTheDispatcherInstance()
{
- $test = $this;
$this->dispatcher->addListener('test', function ($event) use (&$dispatcher) {
$dispatcher = $event->getDispatcher();
});
@@ -245,6 +247,17 @@ public function testEventReceivesTheDispatcherInstance()
$this->assertSame($this->dispatcher, $dispatcher);
}
+ public function testEventReceivesTheDispatcherInstanceAsArgument()
+ {
+ $listener = new TestWithDispatcher();
+ $this->dispatcher->addListener('test', array($listener, 'foo'));
+ $this->assertNull($listener->name);
+ $this->assertNull($listener->dispatcher);
+ $this->dispatcher->dispatch('test');
+ $this->assertEquals('test', $listener->name);
+ $this->assertSame($this->dispatcher, $listener->dispatcher);
+ }
+
/**
* @see https://bugs.php.net/bug.php?id=62976
*
@@ -289,6 +302,18 @@ public function postFoo(Event $e)
}
}
+class TestWithDispatcher
+{
+ public $name;
+ public $dispatcher;
+
+ public function foo(Event $e, $name, $dispatcher)
+ {
+ $this->name = $name;
+ $this->dispatcher = $dispatcher;
+ }
+}
+
class TestEventSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
Please sign in to comment.
Something went wrong with that request. Please try again.