vendor/symfony/security-bundle/Debug/WrappedListener.php line 51

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Bundle\SecurityBundle\Debug;
  11. use Symfony\Component\HttpKernel\Event\RequestEvent;
  12. use Symfony\Component\Security\Http\Firewall\LegacyListenerTrait;
  13. use Symfony\Component\Security\Http\Firewall\ListenerInterface;
  14. use Symfony\Component\VarDumper\Caster\ClassStub;
  15. /**
  16.  * Wraps a security listener for calls record.
  17.  *
  18.  * @author Robin Chalas <robin.chalas@gmail.com>
  19.  *
  20.  * @internal since Symfony 4.3
  21.  */
  22. final class WrappedListener implements ListenerInterface
  23. {
  24.     use LegacyListenerTrait;
  25.     private $response;
  26.     private $listener;
  27.     private $time;
  28.     private $stub;
  29.     private static $hasVarDumper;
  30.     /**
  31.      * @param callable $listener
  32.      */
  33.     public function __construct($listener)
  34.     {
  35.         $this->listener $listener;
  36.     }
  37.     /**
  38.      * {@inheritdoc}
  39.      */
  40.     public function __invoke(RequestEvent $event)
  41.     {
  42.         $startTime microtime(true);
  43.         if (\is_callable($this->listener)) {
  44.             ($this->listener)($event);
  45.         } else {
  46.             @trigger_error(sprintf('Calling the "%s::handle()" method from the firewall is deprecated since Symfony 4.3, implement "__invoke()" instead.', \get_class($this->listener)), E_USER_DEPRECATED);
  47.             $this->listener->handle($event);
  48.         }
  49.         $this->time microtime(true) - $startTime;
  50.         $this->response $event->getResponse();
  51.     }
  52.     /**
  53.      * Proxies all method calls to the original listener.
  54.      */
  55.     public function __call($method$arguments)
  56.     {
  57.         return $this->listener->{$method}(...$arguments);
  58.     }
  59.     public function getWrappedListener()
  60.     {
  61.         return $this->listener;
  62.     }
  63.     public function getInfo(): array
  64.     {
  65.         if (null !== $this->stub) {
  66.             // no-op
  67.         } elseif (self::$hasVarDumper ?? self::$hasVarDumper class_exists(ClassStub::class)) {
  68.             $this->stub ClassStub::wrapCallable($this->listener);
  69.         } elseif (\is_array($this->listener)) {
  70.             $this->stub = (\is_object($this->listener[0]) ? \get_class($this->listener[0]) : $this->listener[0]).'::'.$this->listener[1];
  71.         } elseif ($this->listener instanceof \Closure) {
  72.             $r = new \ReflectionFunction($this->listener);
  73.             if (false !== strpos($r->name'{closure}')) {
  74.                 $this->stub 'closure';
  75.             } elseif ($class $r->getClosureScopeClass()) {
  76.                 $this->stub $class->name.'::'.$r->name;
  77.             } else {
  78.                 $this->stub $r->name;
  79.             }
  80.         } elseif (\is_string($this->listener)) {
  81.             $this->stub $this->listener;
  82.         } else {
  83.             $this->stub = \get_class($this->listener).'::__invoke';
  84.         }
  85.         return [
  86.             'response' => $this->response,
  87.             'time' => $this->time,
  88.             'stub' => $this->stub,
  89.         ];
  90.     }
  91. }