Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

EventDispatcher.php

Zuletzt modifiziert: 09.10.2024, 12:54 - Dateigröße: 5.78 KiB


001  <?php
002   
003  /*
004   * This file is part of the Symfony package.
005   *
006   * (c) Fabien Potencier <fabien@symfony.com>
007   *
008   * For the full copyright and license information, please view the LICENSE
009   * file that was distributed with this source code.
010   */
011   
012  namespace Symfony\Component\EventDispatcher;
013   
014  /**
015   * The EventDispatcherInterface is the central point of Symfony's event listener system.
016   *
017   * Listeners are registered on the manager and events are dispatched through the
018   * manager.
019   *
020   * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
021   * @author Jonathan Wage <jonwage@gmail.com>
022   * @author Roman Borschel <roman@code-factory.org>
023   * @author Bernhard Schussek <bschussek@gmail.com>
024   * @author Fabien Potencier <fabien@symfony.com>
025   * @author Jordi Boggiano <j.boggiano@seld.be>
026   * @author Jordan Alliot <jordan.alliot@gmail.com>
027   */
028  class EventDispatcher implements EventDispatcherInterface
029  {
030      private $listeners = array();
031      private $sorted = array();
032   
033      /**
034       * {@inheritdoc}
035       */
036      public function dispatch($eventName, Event $event = null)
037      {
038          if (null === $event) {
039              $event = new Event();
040          }
041   
042          $event->setDispatcher($this);
043          $event->setName($eventName);
044   
045          if ($listeners = $this->getListeners($eventName)) {
046              $this->doDispatch($listeners, $eventName, $event);
047          }
048   
049          return $event;
050      }
051   
052      /**
053       * {@inheritdoc}
054       */
055      public function getListeners($eventName = null)
056      {
057          if (null !== $eventName) {
058              if (!isset($this->listeners[$eventName])) {
059                  return array();
060              }
061   
062              if (!isset($this->sorted[$eventName])) {
063                  $this->sortListeners($eventName);
064              }
065   
066              return $this->sorted[$eventName];
067          }
068   
069          foreach ($this->listeners as $eventName => $eventListeners) {
070              if (!isset($this->sorted[$eventName])) {
071                  $this->sortListeners($eventName);
072              }
073          }
074   
075          return array_filter($this->sorted);
076      }
077   
078      /**
079       * Gets the listener priority for a specific event.
080       *
081       * Returns null if the event or the listener does not exist.
082       *
083       * @param string   $eventName The name of the event
084       * @param callable $listener  The listener
085       *
086       * @return int|null The event listener priority
087       */
088      public function getListenerPriority($eventName, $listener)
089      {
090          if (!isset($this->listeners[$eventName])) {
091              return;
092          }
093   
094          foreach ($this->listeners[$eventName] as $priority => $listeners) {
095              if (false !== in_array($listener, $listeners, true)) {
096                  return $priority;
097              }
098          }
099      }
100   
101      /**
102       * {@inheritdoc}
103       */
104      public function hasListeners($eventName = null)
105      {
106          return (bool) count($this->getListeners($eventName));
107      }
108   
109      /**
110       * {@inheritdoc}
111       */
112      public function addListener($eventName, $listener, $priority = 0)
113      {
114          $this->listeners[$eventName][$priority][] = $listener;
115          unset($this->sorted[$eventName]);
116      }
117   
118      /**
119       * {@inheritdoc}
120       */
121      public function removeListener($eventName, $listener)
122      {
123          if (!isset($this->listeners[$eventName])) {
124              return;
125          }
126   
127          foreach ($this->listeners[$eventName] as $priority => $listeners) {
128              if (false !== ($key = array_search($listener, $listeners, true))) {
129                  unset($this->listeners[$eventName][$priority][$key], $this->sorted[$eventName]);
130              }
131          }
132      }
133   
134      /**
135       * {@inheritdoc}
136       */
137      public function addSubscriber(EventSubscriberInterface $subscriber)
138      {
139          foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
140              if (is_string($params)) {
141                  $this->addListener($eventName, array($subscriber, $params));
142              } elseif (is_string($params[0])) {
143                  $this->addListener($eventName, array($subscriber, $params[0]), isset($params[1]) ? $params[1] : 0);
144              } else {
145                  foreach ($params as $listener) {
146                      $this->addListener($eventName, array($subscriber, $listener[0]), isset($listener[1]) ? $listener[1] : 0);
147                  }
148              }
149          }
150      }
151   
152      /**
153       * {@inheritdoc}
154       */
155      public function removeSubscriber(EventSubscriberInterface $subscriber)
156      {
157          foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
158              if (is_array($params) && is_array($params[0])) {
159                  foreach ($params as $listener) {
160                      $this->removeListener($eventName, array($subscriber, $listener[0]));
161                  }
162              } else {
163                  $this->removeListener($eventName, array($subscriber, is_string($params) ? $params : $params[0]));
164              }
165          }
166      }
167   
168      /**
169       * Triggers the listeners of an event.
170       *
171       * This method can be overridden to add functionality that is executed
172       * for each listener.
173       *
174       * @param callable[] $listeners The event listeners
175       * @param string     $eventName The name of the event to dispatch
176       * @param Event      $event     The event object to pass to the event handlers/listeners
177       */
178      protected function doDispatch($listeners, $eventName, Event $event)
179      {
180          foreach ($listeners as $listener) {
181              if ($event->isPropagationStopped()) {
182                  break;
183              }
184              call_user_func($listener, $event, $eventName, $this);
185          }
186      }
187   
188      /**
189       * Sorts the internal list of listeners for the given event by priority.
190       *
191       * @param string $eventName The name of the event
192       */
193      private function sortListeners($eventName)
194      {
195          krsort($this->listeners[$eventName]);
196          $this->sorted[$eventName] = call_user_func_array('array_merge', $this->listeners[$eventName]);
197      }
198  }
199