Преглед на файлове

[FrameworkBundle] Fix TraceableEventDispatcher unable to trace static class callables

Drak преди 13 години
родител
ревизия
3939c90944

+ 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;
+    }
 }