浏览代码

merged branch drak/trace_static (PR #3977)

Commits
-------

3939c90 [FrameworkBundle] Fix TraceableEventDispatcher unable to trace static class callables

Discussion
----------

[FrameworkBundle] Fix TraceableEventDispatcher unable to trace static class callables

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: -
Todo: -
Fabien Potencier 13 年之前
父节点
当前提交
968dded8e7

+ 1 - 1
src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php

@@ -178,7 +178,7 @@ class TraceableEventDispatcher extends ContainerAwareEventDispatcher implements
             if (!is_array($listener)) {
                 $listener = array($listener, '__invoke');
             }
-            $class = get_class($listener[0]);
+            $class = is_object($listener[0]) ? get_class($listener[0]) : $listener[0];
             try {
                 $r = new \ReflectionMethod($class, $listener[1]);
                 $file = $r->getFileName();

+ 22 - 0
src/Symfony/Bundle/FrameworkBundle/Tests/Debug/TraceableEventDispatcherTest.php

@@ -26,4 +26,26 @@ class TraceableEventDispatcherTest extends TestCase
         $dispatcher = new TraceableEventDispatcher($container);
         $dispatcher->addListener('onFooEvent', new \stdClass());
     }
+
+    public function testStaticCallable()
+    {
+        $container  = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
+        $dispatcher = new TraceableEventDispatcher($container);
+
+        $dispatcher->addListener('onFooEvent', array(__NAMESPACE__.'\StaticClassFixture', 'staticListener'));
+
+        $dispatcher->dispatch('onFooEvent');
+
+        $this->assertTrue(StaticClassFixture::$called);
+    }
+}
+
+class StaticClassFixture
+{
+    static public $called = false;
+
+    static public function staticListener($event)
+    {
+        self::$called = true;
+    }
 }