Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[SecurityBundle] Fix profiler dump for non-invokable security listeners #31820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[SecurityBundle] Fix profiler dump for non-invokable security listeners
  • Loading branch information
Robin Chalas authored and nicolas-grekas committed Jul 8, 2019
commit f7738d934bba4bf3d33168cae2d30aab8e30e80d
25 changes: 19 additions & 6 deletions src/Symfony/Bundle/SecurityBundle/Debug/WrappedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ final class WrappedListener implements ListenerInterface
public function __construct($listener)
{
$this->listener = $listener;

if (null === self::$hasVarDumper) {
self::$hasVarDumper = class_exists(ClassStub::class);
}
}

/**
Expand Down Expand Up @@ -76,8 +72,25 @@ public function getWrappedListener()

public function getInfo(): array
{
if (null === $this->stub) {
$this->stub = self::$hasVarDumper ? new ClassStub(\get_class($this->listener)) : \get_class($this->listener);
if (null !== $this->stub) {
// no-op
} elseif (self::$hasVarDumper ?? self::$hasVarDumper = class_exists(ClassStub::class)) {
$this->stub = ClassStub::wrapCallable($this->listener);
} elseif (\is_array($this->listener)) {
$this->stub = (\is_object($this->listener[0]) ? \get_class($this->listener[0]) : $this->listener[0]).'::'.$this->listener[1];
} elseif ($this->listener instanceof \Closure) {
$r = new \ReflectionFunction($this->listener);
if (false !== strpos($r->name, '{closure}')) {
$this->stub = 'closure';
} elseif ($class = $r->getClosureScopeClass()) {
$this->stub = $class->name.'::'.$r->name;
} else {
$this->stub = $r->name;
}
} elseif (\is_string($this->listener)) {
$this->stub = $this->listener;
} else {
$this->stub = \get_class($this->listener).'::__invoke';
}

return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\Security\Http\Logout\LogoutUrlGenerator;
use Symfony\Component\VarDumper\Caster\ClassStub;

/**
* @group time-sensitive
Expand Down Expand Up @@ -56,9 +55,6 @@ public function testOnKernelRequestRecordsListeners()

$listeners = $firewall->getWrappedListeners();
$this->assertCount(1, $listeners);
$this->assertSame($response, $listeners[0]['response']);
$this->assertInstanceOf(ClassStub::class, $listeners[0]['stub']);
$this->assertSame(\get_class($listener), (string) $listeners[0]['stub']);
$this->assertSame(1, $listenerCalled);
$this->assertSame($listener, $listeners[0]['stub']);
}
}