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: -
This commit is contained in:
Fabien Potencier 2012-04-18 16:51:19 +02:00
commit 968dded8e7
2 changed files with 23 additions and 1 deletions

View File

@ -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();

View File

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