Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #23105 [SecurityBundle][Profiler] Give info about called secu…
…rity listeners in profiler (chalasr) This PR was merged into the 3.4 branch. Discussion ---------- [SecurityBundle][Profiler] Give info about called security listeners in profiler | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #11134 | License | MIT | Doc PR | n/a Currently the profiler gives no info about security listeners (see fixed ticket), this displays each called listener with the time spent at calling it and its response if any. ![preview](https://image.prntscr.com/image/Wx-n-Ni_RQK5JGTdTZsdGw.png) Commits ------- 369f19f Give info about called security listeners in profiler
- Loading branch information
Showing
11 changed files
with
317 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/Symfony/Bundle/SecurityBundle/Debug/TraceableFirewallListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\SecurityBundle\Debug; | ||
|
||
use Symfony\Bundle\SecurityBundle\EventListener\FirewallListener; | ||
use Symfony\Component\HttpKernel\Event\GetResponseEvent; | ||
|
||
/** | ||
* Firewall collecting called listeners. | ||
* | ||
* @author Robin Chalas <robin.chalas@gmail.com> | ||
*/ | ||
final class TraceableFirewallListener extends FirewallListener | ||
{ | ||
private $wrappedListeners; | ||
|
||
public function getWrappedListeners() | ||
{ | ||
return $this->wrappedListeners; | ||
} | ||
|
||
protected function handleRequest(GetResponseEvent $event, $listeners) | ||
{ | ||
foreach ($listeners as $listener) { | ||
$wrappedListener = new WrappedListener($listener); | ||
$wrappedListener->handle($event); | ||
$this->wrappedListeners[] = $wrappedListener->getInfo(); | ||
|
||
if ($event->hasResponse()) { | ||
break; | ||
} | ||
} | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
src/Symfony/Bundle/SecurityBundle/Debug/WrappedListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\SecurityBundle\Debug; | ||
|
||
use Symfony\Component\HttpKernel\Event\GetResponseEvent; | ||
use Symfony\Component\Security\Http\Firewall\ListenerInterface; | ||
use Symfony\Component\VarDumper\Caster\ClassStub; | ||
|
||
/** | ||
* Wraps a security listener for calls record. | ||
* | ||
* @author Robin Chalas <robin.chalas@gmail.com> | ||
*/ | ||
final class WrappedListener implements ListenerInterface | ||
{ | ||
private $response; | ||
private $listener; | ||
private $time; | ||
private $stub; | ||
private static $hasVarDumper; | ||
|
||
public function __construct(ListenerInterface $listener) | ||
{ | ||
$this->listener = $listener; | ||
|
||
if (null === self::$hasVarDumper) { | ||
self::$hasVarDumper = class_exists(ClassStub::class); | ||
} | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function handle(GetResponseEvent $event) | ||
{ | ||
$startTime = microtime(true); | ||
$this->listener->handle($event); | ||
$this->time = microtime(true) - $startTime; | ||
$this->response = $event->getResponse(); | ||
} | ||
|
||
/** | ||
* Proxies all method calls to the original listener. | ||
*/ | ||
public function __call($method, $arguments) | ||
{ | ||
return call_user_func_array(array($this->listener, $method), $arguments); | ||
} | ||
|
||
public function getWrappedListener() | ||
{ | ||
return $this->listener; | ||
} | ||
|
||
public function getInfo() | ||
{ | ||
if (null === $this->stub) { | ||
$this->stub = self::$hasVarDumper ? new ClassStub(get_class($this->listener)) : get_class($this->listener); | ||
} | ||
|
||
return array( | ||
'response' => $this->response, | ||
'time' => $this->time, | ||
'stub' => $this->stub, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.