[ Index ]

PHP Cross Reference of phpBB-3.3.5-deutsch

title

Body

[close]

/vendor/symfony/event-dispatcher/Debug/ -> WrappedListener.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the Symfony package.
   5   *
   6   * (c) Fabien Potencier <fabien@symfony.com>
   7   *
   8   * For the full copyright and license information, please view the LICENSE
   9   * file that was distributed with this source code.
  10   */
  11  
  12  namespace Symfony\Component\EventDispatcher\Debug;
  13  
  14  use Symfony\Component\EventDispatcher\Event;
  15  use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  16  use Symfony\Component\Stopwatch\Stopwatch;
  17  use Symfony\Component\VarDumper\Caster\ClassStub;
  18  
  19  /**
  20   * @author Fabien Potencier <fabien@symfony.com>
  21   */
  22  class WrappedListener
  23  {
  24      private $listener;
  25      private $name;
  26      private $called;
  27      private $stoppedPropagation;
  28      private $stopwatch;
  29      private $dispatcher;
  30      private $pretty;
  31      private $stub;
  32      private $priority;
  33      private static $hasClassStub;
  34  
  35      public function __construct($listener, $name, Stopwatch $stopwatch, EventDispatcherInterface $dispatcher = null)
  36      {
  37          $this->listener = $listener;
  38          $this->stopwatch = $stopwatch;
  39          $this->dispatcher = $dispatcher;
  40          $this->called = false;
  41          $this->stoppedPropagation = false;
  42  
  43          if (\is_array($listener)) {
  44              $this->name = \is_object($listener[0]) ? \get_class($listener[0]) : $listener[0];
  45              $this->pretty = $this->name.'::'.$listener[1];
  46          } elseif ($listener instanceof \Closure) {
  47              $r = new \ReflectionFunction($listener);
  48              if (false !== strpos($r->name, '{closure}')) {
  49                  $this->pretty = $this->name = 'closure';
  50              } elseif ($class = $r->getClosureScopeClass()) {
  51                  $this->name = $class->name;
  52                  $this->pretty = $this->name.'::'.$r->name;
  53              } else {
  54                  $this->pretty = $this->name = $r->name;
  55              }
  56          } elseif (\is_string($listener)) {
  57              $this->pretty = $this->name = $listener;
  58          } else {
  59              $this->name = \get_class($listener);
  60              $this->pretty = $this->name.'::__invoke';
  61          }
  62  
  63          if (null !== $name) {
  64              $this->name = $name;
  65          }
  66  
  67          if (null === self::$hasClassStub) {
  68              self::$hasClassStub = class_exists(ClassStub::class);
  69          }
  70      }
  71  
  72      public function getWrappedListener()
  73      {
  74          return $this->listener;
  75      }
  76  
  77      public function wasCalled()
  78      {
  79          return $this->called;
  80      }
  81  
  82      public function stoppedPropagation()
  83      {
  84          return $this->stoppedPropagation;
  85      }
  86  
  87      public function getPretty()
  88      {
  89          return $this->pretty;
  90      }
  91  
  92      public function getInfo($eventName)
  93      {
  94          if (null === $this->stub) {
  95              $this->stub = self::$hasClassStub ? new ClassStub($this->pretty.'()', $this->listener) : $this->pretty.'()';
  96          }
  97  
  98          return [
  99              'event' => $eventName,
 100              'priority' => null !== $this->priority ? $this->priority : (null !== $this->dispatcher ? $this->dispatcher->getListenerPriority($eventName, $this->listener) : null),
 101              'pretty' => $this->pretty,
 102              'stub' => $this->stub,
 103          ];
 104      }
 105  
 106      public function __invoke(Event $event, $eventName, EventDispatcherInterface $dispatcher)
 107      {
 108          $dispatcher = $this->dispatcher ?: $dispatcher;
 109  
 110          $this->called = true;
 111          $this->priority = $dispatcher->getListenerPriority($eventName, $this->listener);
 112  
 113          $e = $this->stopwatch->start($this->name, 'event_listener');
 114  
 115          \call_user_func($this->listener, $event, $eventName, $dispatcher);
 116  
 117          if ($e->isStarted()) {
 118              $e->stop();
 119          }
 120  
 121          if ($event->isPropagationStopped()) {
 122              $this->stoppedPropagation = true;
 123          }
 124      }
 125  }


Generated: Mon Oct 4 17:42:11 2021 Cross-referenced by PHPXref 0.7.1