Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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:58 - Dateigröße: 5.44 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   * @api
029   */
030  class EventDispatcher implements EventDispatcherInterface
031  {
032      private $listeners = array();
033      private $sorted = array();
034   
035      /**
036       * @see EventDispatcherInterface::dispatch
037       *
038       * @api
039       */
040      public function dispatch($eventName, Event $event = null)
041      {
042          if (null === $event) {
043              $event = new Event();
044          }
045   
046          $event->setDispatcher($this);
047          $event->setName($eventName);
048   
049          if (!isset($this->listeners[$eventName])) {
050              return $event;
051          }
052   
053          $this->doDispatch($this->getListeners($eventName), $eventName, $event);
054   
055          return $event;
056      }
057   
058      /**
059       * @see EventDispatcherInterface::getListeners
060       */
061      public function getListeners($eventName = null)
062      {
063          if (null !== $eventName) {
064              if (!isset($this->sorted[$eventName])) {
065                  $this->sortListeners($eventName);
066              }
067   
068              return $this->sorted[$eventName];
069          }
070   
071          foreach (array_keys($this->listeners) as $eventName) {
072              if (!isset($this->sorted[$eventName])) {
073                  $this->sortListeners($eventName);
074              }
075          }
076   
077          return array_filter($this->sorted);
078      }
079   
080      /**
081       * @see EventDispatcherInterface::hasListeners
082       */
083      public function hasListeners($eventName = null)
084      {
085          return (bool) count($this->getListeners($eventName));
086      }
087   
088      /**
089       * @see EventDispatcherInterface::addListener
090       *
091       * @api
092       */
093      public function addListener($eventName, $listener, $priority = 0)
094      {
095          $this->listeners[$eventName][$priority][] = $listener;
096          unset($this->sorted[$eventName]);
097      }
098   
099      /**
100       * @see EventDispatcherInterface::removeListener
101       */
102      public function removeListener($eventName, $listener)
103      {
104          if (!isset($this->listeners[$eventName])) {
105              return;
106          }
107   
108          foreach ($this->listeners[$eventName] as $priority => $listeners) {
109              if (false !== ($key = array_search($listener, $listeners, true))) {
110                  unset($this->listeners[$eventName][$priority][$key], $this->sorted[$eventName]);
111              }
112          }
113      }
114   
115      /**
116       * @see EventDispatcherInterface::addSubscriber
117       *
118       * @api
119       */
120      public function addSubscriber(EventSubscriberInterface $subscriber)
121      {
122          foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
123              if (is_string($params)) {
124                  $this->addListener($eventName, array($subscriber, $params));
125              } elseif (is_string($params[0])) {
126                  $this->addListener($eventName, array($subscriber, $params[0]), isset($params[1]) ? $params[1] : 0);
127              } else {
128                  foreach ($params as $listener) {
129                      $this->addListener($eventName, array($subscriber, $listener[0]), isset($listener[1]) ? $listener[1] : 0);
130                  }
131              }
132          }
133      }
134   
135      /**
136       * @see EventDispatcherInterface::removeSubscriber
137       */
138      public function removeSubscriber(EventSubscriberInterface $subscriber)
139      {
140          foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
141              if (is_array($params) && is_array($params[0])) {
142                  foreach ($params as $listener) {
143                      $this->removeListener($eventName, array($subscriber, $listener[0]));
144                  }
145              } else {
146                  $this->removeListener($eventName, array($subscriber, is_string($params) ? $params : $params[0]));
147              }
148          }
149      }
150   
151      /**
152       * Triggers the listeners of an event.
153       *
154       * This method can be overridden to add functionality that is executed
155       * for each listener.
156       *
157       * @param array[callback] $listeners The event listeners.
158       * @param string          $eventName The name of the event to dispatch.
159       * @param Event           $event     The event object to pass to the event handlers/listeners.
160       */
161      protected function doDispatch($listeners, $eventName, Event $event)
162      {
163          foreach ($listeners as $listener) {
164              call_user_func($listener, $event);
165              if ($event->isPropagationStopped()) {
166                  break;
167              }
168          }
169      }
170   
171      /**
172       * Sorts the internal list of listeners for the given event by priority.
173       *
174       * @param string $eventName The name of the event.
175       */
176      private function sortListeners($eventName)
177      {
178          $this->sorted[$eventName] = array();
179   
180          if (isset($this->listeners[$eventName])) {
181              krsort($this->listeners[$eventName]);
182              $this->sorted[$eventName] = call_user_func_array('array_merge', $this->listeners[$eventName]);
183          }
184      }
185  }
186