Permalink
Browse files

[2.3][EventDispatcher] Make events lighter

  • Loading branch information...
1 parent 1099858 commit e2bff32de77a444b0912d2c6399e75b5aa1605d6 Drak committed with fabpot Apr 25, 2013
@@ -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)
@@ -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;
}
@@ -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,14 +240,24 @@ public function testRemoveSubscriberWithMultipleListeners()
public function testEventReceivesTheDispatcherInstance()
{
- $test = $this;
$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();
+ $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()

0 comments on commit e2bff32

Please sign in to comment.