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

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.         if (null === self::$hasVarDumper) {
  37.             self::$hasVarDumper class_exists(ClassStub::class);
  38.         }
  39.     }
  40.     /**
  41.      * {@inheritdoc}
  42.      */
  43.     public function __invoke(RequestEvent $event)
  44.     {
  45.         $startTime microtime(true);
  46.         if (\is_callable($this->listener)) {
  47.             ($this->listener)($event);
  48.         } else {
  49.             @trigger_error(sprintf('Calling the "%s::handle()" method from the firewall is deprecated since Symfony 4.3, implement "__invoke()" instead.', \get_class($this)), E_USER_DEPRECATED);
  50.             $this->listener->handle($event);
  51.         }
  52.         $this->time microtime(true) - $startTime;
  53.         $this->response $event->getResponse();
  54.     }
  55.     /**
  56.      * Proxies all method calls to the original listener.
  57.      */
  58.     public function __call($method$arguments)
  59.     {
  60.         return $this->listener->{$method}(...$arguments);
  61.     }
  62.     public function getWrappedListener()
  63.     {
  64.         return $this->listener;
  65.     }
  66.     public function getInfo(): array
  67.     {
  68.         if (null === $this->stub) {
  69.             $this->stub self::$hasVarDumper ? new ClassStub(\get_class($this->listener)) : \get_class($this->listener);
  70.         }
  71.         return [
  72.             'response' => $this->response,
  73.             'time' => $this->time,
  74.             'stub' => $this->stub,
  75.         ];
  76.     }
  77. }