8000 [SecurityBundle] Fix profiler dump for non-invokable security listeners · symfony/symfony@f7738d9 · GitHub
[go: up one dir, main page]

Skip to content

Commit f7738d9

Browse files
Robin Chalasnicolas-grekas
Robin Chalas
authored andcommitted
[SecurityBundle] Fix profiler dump for non-invokable security listeners
1 parent d8224b8 commit f7738d9

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

src/Symfony/Bundle/SecurityBundle/Debug/WrappedListener.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ final class WrappedListener implements ListenerInterface
3939
public function __construct($listener)
4040
{
4141
$this->listener = $listener;
42-
43-
if (null === self::$hasVarDumper) {
44-
self::$hasVarDumper = class_exists(ClassStub::class);
45-
}
4642
}
4743

4844
/**
@@ -76,8 +72,25 @@ public function getWrappedListener()
7672

7773
public function getInfo(): array
7874
{
79-
if (null === $this->stub) {
80-
$this->stub = self::$hasVarDumper ? new ClassStub(\get_class($this->listener)) : \get_class($this->listener);
75+
if (null !== $this->stub) {
76+
// no-op
77+
} elseif (self::$hasVarDumper ?? self::$hasVarDumper = class_exists(ClassStub::class)) {
78+
$this->stub = ClassStub::wrapCallable($this->listener);
79+
} elseif (\is_array($this->listener)) {
80+
$this->stub = (\is_object($this->listener[0]) ? \get_class($this->listener[0]) : $this->listener[0]).'::'.$this->listener[1];
81+
} elseif ($this->listener instanceof \Closure) {
82+
$r = new \ReflectionFunction($this->listener);
83+
if (false !== strpos($r->name, '{closure}')) {
84+
$this->stub = 'closure';
85+
} elseif ($class = $r->getClosureScopeClass()) {
86+
$this->stub = $class->name.'::'.$r->name;
87+
} else {
88+
$this->stub = $r->name;
89+
}
90+
} elseif (\is_string($this->listener)) {
91+
$this->stub = $this->listener;
92+
} else {
93+
$this->stub = \get_class($this->listener).'::__invoke';
8194
}
8295

8396
return [

src/Symfony/Bundle/SecurityBundle/Tests/Debug/TraceableFirewallListenerTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use Symfony\Component\HttpKernel\Event\RequestEvent;
2121
use Symfony\Component\HttpKernel\HttpKernelInterface;
2222
use Symfony\Component\Security\Http\Logout\LogoutUrlGenerator;
23-
use Symfony\Component\VarDumper\Caster\ClassStub;
2423

2524
/**
2625
* @group time-sensitive
@@ -56,9 +55,6 @@ public function testOnKernelRequestRecordsListeners()
5655

5756
$listeners = $firewall->getWrappedListeners();
5857
$this->assertCount(1, $listeners);
59-
$this->assertSame($response, $listeners[0]['response']);
60-
$this->assertInstanceOf(ClassStub::class, $listeners[0]['stub']);
61-
$this->assertSame(\get_class($listener), (string) $listeners[0]['stub']);
62-
$this->assertSame(1, $listenerCalled);
58+
$this->assertSame($listener, $listeners[0]['stub']);
6359
}
6460
}

0 commit comments

Comments
 (0)
0