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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
Emitter.php
001 <?php
002 namespace GuzzleHttp\Event;
003
004 /**
005 * Guzzle event emitter.
006 *
007 * Some of this class is based on the Symfony EventDispatcher component, which
008 * ships with the following license:
009 *
010 * This file is part of the Symfony package.
011 *
012 * (c) Fabien Potencier <fabien@symfony.com>
013 *
014 * For the full copyright and license information, please view the LICENSE
015 * file that was distributed with this source code.
016 *
017 * @link https://github.com/symfony/symfony/tree/master/src/Symfony/Component/EventDispatcher
018 */
019 class Emitter implements EmitterInterface
020 {
021 /** @var array */
022 private $listeners = [];
023
024 /** @var array */
025 private $sorted = [];
026
027 public function on($eventName, callable $listener, $priority = 0)
028 {
029 if ($priority === 'first') {
030 $priority = isset($this->listeners[$eventName])
031 ? max(array_keys($this->listeners[$eventName])) + 1
032 : 1;
033 } elseif ($priority === 'last') {
034 $priority = isset($this->listeners[$eventName])
035 ? min(array_keys($this->listeners[$eventName])) - 1
036 : -1;
037 }
038
039 $this->listeners[$eventName][$priority][] = $listener;
040 unset($this->sorted[$eventName]);
041 }
042
043 public function once($eventName, callable $listener, $priority = 0)
044 {
045 $onceListener = function (
046 EventInterface $event
047 ) use (&$onceListener, $eventName, $listener, $priority) {
048 $this->removeListener($eventName, $onceListener);
049 $listener($event, $eventName);
050 };
051
052 $this->on($eventName, $onceListener, $priority);
053 }
054
055 public function removeListener($eventName, callable $listener)
056 {
057 if (empty($this->listeners[$eventName])) {
058 return;
059 }
060
061 foreach ($this->listeners[$eventName] as $priority => $listeners) {
062 if (false !== ($key = array_search($listener, $listeners, true))) {
063 unset(
064 $this->listeners[$eventName][$priority][$key],
065 $this->sorted[$eventName]
066 );
067 }
068 }
069 }
070
071 public function listeners($eventName = null)
072 {
073 // Return all events in a sorted priority order
074 if ($eventName === null) {
075 foreach (array_keys($this->listeners) as $eventName) {
076 if (empty($this->sorted[$eventName])) {
077 $this->listeners($eventName);
078 }
079 }
080 return $this->sorted;
081 }
082
083 // Return the listeners for a specific event, sorted in priority order
084 if (empty($this->sorted[$eventName])) {
085 $this->sorted[$eventName] = [];
086 if (isset($this->listeners[$eventName])) {
087 krsort($this->listeners[$eventName], SORT_NUMERIC);
088 foreach ($this->listeners[$eventName] as $listeners) {
089 foreach ($listeners as $listener) {
090 $this->sorted[$eventName][] = $listener;
091 }
092 }
093 }
094 }
095
096 return $this->sorted[$eventName];
097 }
098
099 public function hasListeners($eventName)
100 {
101 return !empty($this->listeners[$eventName]);
102 }
103
104 public function emit($eventName, EventInterface $event)
105 {
106 if (isset($this->listeners[$eventName])) {
107 foreach ($this->listeners($eventName) as $listener) {
108 $listener($event, $eventName);
109 if ($event->isPropagationStopped()) {
110 break;
111 }
112 }
113 }
114
115 return $event;
116 }
117
118 public function attach(SubscriberInterface $subscriber)
119 {
120 foreach ($subscriber->getEvents() as $eventName => $listeners) {
121 if (is_array($listeners[0])) {
122 foreach ($listeners as $listener) {
123 $this->on(
124 $eventName,
125 [$subscriber, $listener[0]],
126 isset($listener[1]) ? $listener[1] : 0
127 );
128 }
129 } else {
130 $this->on(
131 $eventName,
132 [$subscriber, $listeners[0]],
133 isset($listeners[1]) ? $listeners[1] : 0
134 );
135 }
136 }
137 }
138
139 public function detach(SubscriberInterface $subscriber)
140 {
141 foreach ($subscriber->getEvents() as $eventName => $listener) {
142 $this->removeListener($eventName, [$subscriber, $listener[0]]);
143 }
144 }
145 }
146