Skip to content

Commit bc3f598

Browse files
committed
Allow WrappedListener to describe uncallable listeners.
1 parent ce26936 commit bc3f598

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class WrappedListener
4141
public function __construct($listener, ?string $name, Stopwatch $stopwatch, EventDispatcherInterface $dispatcher = null)
4242
{
4343
$this->listener = $listener;
44-
$this->optimizedListener = $listener instanceof \Closure ? $listener : \Closure::fromCallable($listener);
44+
$this->optimizedListener = $listener instanceof \Closure ? $listener : (\is_callable($listener) ? \Closure::fromCallable($listener) : null);
4545
$this->stopwatch = $stopwatch;
4646
$this->dispatcher = $dispatcher;
4747
$this->called = false;
@@ -123,7 +123,7 @@ public function __invoke(Event $event, $eventName, EventDispatcherInterface $dis
123123

124124
$e = $this->stopwatch->start($this->name, 'event_listener');
125125

126-
($this->optimizedListener)($event, $eventName, $dispatcher);
126+
($this->optimizedListener ?? $this->listener)($event, $eventName, $dispatcher);
127127

128128
if ($e->isStarted()) {
129129
$e->stop();

src/Symfony/Component/EventDispatcher/Tests/Debug/WrappedListenerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class WrappedListenerTest extends TestCase
2121
/**
2222
* @dataProvider provideListenersToDescribe
2323
*/
24-
public function testListenerDescription(callable $listener, $expected)
24+
public function testListenerDescription($listener, $expected)
2525
{
2626
$wrappedListener = new WrappedListener($listener, null, $this->getMockBuilder(Stopwatch::class)->getMock(), $this->getMockBuilder(EventDispatcherInterface::class)->getMock());
2727

@@ -34,6 +34,7 @@ public function provideListenersToDescribe()
3434
[new FooListener(), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::__invoke'],
3535
[[new FooListener(), 'listen'], 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listen'],
3636
[['Symfony\Component\EventDispatcher\Tests\Debug\FooListener', 'listenStatic'], 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listenStatic'],
37+
[['Symfony\Component\EventDispatcher\Tests\Debug\FooListener', 'invalidMethod'], 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::invalidMethod'],
3738
['var_dump', 'var_dump'],
3839
[function () {}, 'closure'],
3940
[\Closure::fromCallable([new FooListener(), 'listen']), 'Symfony\Component\EventDispatcher\Tests\Debug\FooListener::listen'],

0 commit comments

Comments
 (0)