vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php line 104

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\Component\EventDispatcher\Debug;
  11. use Symfony\Component\Stopwatch\Stopwatch;
  12. use Symfony\Component\EventDispatcher\Event;
  13. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  14. use Symfony\Component\VarDumper\Caster\ClassStub;
  15. /**
  16.  * @author Fabien Potencier <fabien@symfony.com>
  17.  */
  18. class WrappedListener
  19. {
  20.     private $listener;
  21.     private $name;
  22.     private $called;
  23.     private $stoppedPropagation;
  24.     private $stopwatch;
  25.     private $dispatcher;
  26.     private $pretty;
  27.     private $stub;
  28.     private static $hasClassStub;
  29.     public function __construct($listener$nameStopwatch $stopwatchEventDispatcherInterface $dispatcher null)
  30.     {
  31.         $this->listener $listener;
  32.         $this->name $name;
  33.         $this->stopwatch $stopwatch;
  34.         $this->dispatcher $dispatcher;
  35.         $this->called false;
  36.         $this->stoppedPropagation false;
  37.         if (is_array($listener)) {
  38.             $this->name is_object($listener[0]) ? get_class($listener[0]) : $listener[0];
  39.             $this->pretty $this->name.'::'.$listener[1];
  40.         } elseif ($listener instanceof \Closure) {
  41.             $this->pretty $this->name 'closure';
  42.         } elseif (is_string($listener)) {
  43.             $this->pretty $this->name $listener;
  44.         } else {
  45.             $this->name get_class($listener);
  46.             $this->pretty $this->name.'::__invoke';
  47.         }
  48.         if (null !== $name) {
  49.             $this->name $name;
  50.         }
  51.         if (null === self::$hasClassStub) {
  52.             self::$hasClassStub class_exists(ClassStub::class);
  53.         }
  54.     }
  55.     public function getWrappedListener()
  56.     {
  57.         return $this->listener;
  58.     }
  59.     public function wasCalled()
  60.     {
  61.         return $this->called;
  62.     }
  63.     public function stoppedPropagation()
  64.     {
  65.         return $this->stoppedPropagation;
  66.     }
  67.     public function getPretty()
  68.     {
  69.         return $this->pretty;
  70.     }
  71.     public function getInfo($eventName)
  72.     {
  73.         if (null === $this->stub) {
  74.             $this->stub self::$hasClassStub ? new ClassStub($this->pretty.'()'$this->listener) : $this->pretty.'()';
  75.         }
  76.         return array(
  77.             'event' => $eventName,
  78.             'priority' => null !== $this->dispatcher $this->dispatcher->getListenerPriority($eventName$this->listener) : null,
  79.             'pretty' => $this->pretty,
  80.             'stub' => $this->stub,
  81.         );
  82.     }
  83.     public function __invoke(Event $event$eventNameEventDispatcherInterface $dispatcher)
  84.     {
  85.         $this->called true;
  86.         $e $this->stopwatch->start($this->name'event_listener');
  87.         call_user_func($this->listener$event$eventName$this->dispatcher ?: $dispatcher);
  88.         if ($e->isStarted()) {
  89.             $e->stop();
  90.         }
  91.         if ($event->isPropagationStopped()) {
  92.             $this->stoppedPropagation true;
  93.         }
  94.     }
  95. }