From fae70bf0a7f1b566d25e30064f60d58ab150951a Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 7 May 2020 23:35:02 +0200 Subject: Revert "composer updates" This reverts commit dbfe748d274f6843fc91a3071df7be45c4ab5b00 --- vendor/sabre/event/lib/Emitter.php | 9 +- vendor/sabre/event/lib/EmitterInterface.php | 31 +++-- vendor/sabre/event/lib/EmitterTrait.php | 79 ++++++----- vendor/sabre/event/lib/EventEmitter.php | 9 +- vendor/sabre/event/lib/Loop/Loop.php | 147 +++++++++++++-------- vendor/sabre/event/lib/Loop/functions.php | 85 +++++++----- vendor/sabre/event/lib/Promise.php | 73 +++++----- vendor/sabre/event/lib/Promise/functions.php | 53 ++++---- .../event/lib/PromiseAlreadyResolvedException.php | 8 +- vendor/sabre/event/lib/Version.php | 13 +- vendor/sabre/event/lib/WildcardEmitter.php | 13 +- vendor/sabre/event/lib/WildcardEmitterTrait.php | 119 +++++++++++------ vendor/sabre/event/lib/coroutine.php | 52 ++++---- 13 files changed, 412 insertions(+), 279 deletions(-) (limited to 'vendor/sabre/event/lib') diff --git a/vendor/sabre/event/lib/Emitter.php b/vendor/sabre/event/lib/Emitter.php index e1f23fc87..ab5e8c90e 100644 --- a/vendor/sabre/event/lib/Emitter.php +++ b/vendor/sabre/event/lib/Emitter.php @@ -1,6 +1,4 @@ -listeners[$eventName])) { $this->listeners[$eventName] = [ true, // If there's only one item, it's sorted [$priority], - [$callBack], + [$callBack] ]; } else { $this->listeners[$eventName][0] = false; // marked as unsorted $this->listeners[$eventName][1][] = $priority; $this->listeners[$eventName][2][] = $callBack; } + } /** * Subscribe to an event exactly once. + * + * @return void */ - public function once(string $eventName, callable $callBack, int $priority = 100) - { + function once(string $eventName, callable $callBack, int $priority = 100) { + $wrapper = null; - $wrapper = function () use ($eventName, $callBack, &$wrapper) { - $this->removeListener($eventName, $wrapper); + $wrapper = function() use ($eventName, $callBack, &$wrapper) { + $this->removeListener($eventName, $wrapper); return \call_user_func_array($callBack, \func_get_args()); + }; $this->on($eventName, $wrapper, $priority); + } /** * Emits an event. * - * This method will return true if 0 or more listeners were successfully + * This method will return true if 0 or more listeners were succesfully * handled. false is returned if one of the events broke the event chain. * * If the continueCallBack is specified, this callback will be called every @@ -73,35 +79,41 @@ trait EmitterTrait * Lastly, if there are 5 event handlers for an event. The continueCallback * will be called at most 4 times. */ - public function emit(string $eventName, array $arguments = [], callable $continueCallBack = null): bool - { + function emit(string $eventName, array $arguments = [], callable $continueCallBack = null) : bool { + if (\is_null($continueCallBack)) { + foreach ($this->listeners($eventName) as $listener) { + $result = \call_user_func_array($listener, $arguments); - if (false === $result) { + if ($result === false) { return false; } } + } else { + $listeners = $this->listeners($eventName); $counter = \count($listeners); foreach ($listeners as $listener) { - --$counter; + + $counter--; $result = \call_user_func_array($listener, $arguments); - if (false === $result) { + if ($result === false) { return false; } if ($counter > 0) { - if (!$continueCallBack()) { - break; - } + if (!$continueCallBack()) break; } + } + } return true; + } /** @@ -112,14 +124,15 @@ trait EmitterTrait * * @return callable[] */ - public function listeners(string $eventName): array - { + function listeners(string $eventName) : array { + if (!isset($this->listeners[$eventName])) { return []; } // The list is not sorted if (!$this->listeners[$eventName][0]) { + // Sorting \array_multisort($this->listeners[$eventName][1], SORT_NUMERIC, $this->listeners[$eventName][2]); @@ -128,6 +141,7 @@ trait EmitterTrait } return $this->listeners[$eventName][2]; + } /** @@ -136,8 +150,8 @@ trait EmitterTrait * If the listener could not be found, this method will return false. If it * was removed it will return true. */ - public function removeListener(string $eventName, callable $listener): bool - { + function removeListener(string $eventName, callable $listener) : bool { + if (!isset($this->listeners[$eventName])) { return false; } @@ -145,12 +159,11 @@ trait EmitterTrait if ($check === $listener) { unset($this->listeners[$eventName][1][$index]); unset($this->listeners[$eventName][2][$index]); - return true; } } - return false; + } /** @@ -159,20 +172,24 @@ trait EmitterTrait * If the eventName argument is specified, all listeners for that event are * removed. If it is not specified, every listener for every event is * removed. + * + * @return void */ - public function removeAllListeners(string $eventName = null) - { + function removeAllListeners(string $eventName = null) { + if (!\is_null($eventName)) { unset($this->listeners[$eventName]); } else { $this->listeners = []; } + } /** - * The list of listeners. + * The list of listeners * * @var array */ protected $listeners = []; + } diff --git a/vendor/sabre/event/lib/EventEmitter.php b/vendor/sabre/event/lib/EventEmitter.php index 18971e3ee..cae6ac2a6 100644 --- a/vendor/sabre/event/lib/EventEmitter.php +++ b/vendor/sabre/event/lib/EventEmitter.php @@ -1,6 +1,4 @@ -timers) { // Special case when the timers array was empty. $this->timers[] = [$triggerTime, $cb]; - return; } @@ -47,12 +46,14 @@ class Loop [[$triggerTime, $cb]] ); break; - } elseif (0 === $index) { + } elseif ($index === 0) { array_unshift($this->timers, [$triggerTime, $cb]); break; } - --$index; + $index--; + } + } /** @@ -61,12 +62,12 @@ class Loop * The value this function returns can be used to stop the interval with * clearInterval. */ - public function setInterval(callable $cb, float $timeout): array - { + function setInterval(callable $cb, float $timeout) : array { + $keepGoing = true; $f = null; - $f = function () use ($cb, &$f, $timeout, &$keepGoing) { + $f = function() use ($cb, &$f, $timeout, &$keepGoing) { if ($keepGoing) { $cb(); $this->setTimeout($f, $timeout); @@ -81,24 +82,32 @@ class Loop // Because I'm worried people will be confused by using a boolean as a // sort of identifier, I added an extra string. return ['I\'m an implementation detail', &$keepGoing]; + } /** * Stops a running interval. + * + * @return void */ - public function clearInterval(array $intervalId) - { + function clearInterval(array $intervalId) { + $intervalId[1] = false; + } /** * Runs a function immediately at the next iteration of the loop. + * + * @return void */ - public function nextTick(callable $cb) - { + function nextTick(callable $cb) { + $this->nextTick[] = $cb; + } + /** * Adds a read stream. * @@ -109,11 +118,13 @@ class Loop * prevent the eventloop from never stopping. * * @param resource $stream + * @return void */ - public function addReadStream($stream, callable $cb) - { - $this->readStreams[(int) $stream] = $stream; - $this->readCallbacks[(int) $stream] = $cb; + function addReadStream($stream, callable $cb) { + + $this->readStreams[(int)$stream] = $stream; + $this->readCallbacks[(int)$stream] = $cb; + } /** @@ -126,53 +137,65 @@ class Loop * prevent the eventloop from never stopping. * * @param resource $stream + * @return void */ - public function addWriteStream($stream, callable $cb) - { - $this->writeStreams[(int) $stream] = $stream; - $this->writeCallbacks[(int) $stream] = $cb; + function addWriteStream($stream, callable $cb) { + + $this->writeStreams[(int)$stream] = $stream; + $this->writeCallbacks[(int)$stream] = $cb; + } /** * Stop watching a stream for reads. * * @param resource $stream + * @return void */ - public function removeReadStream($stream) - { + function removeReadStream($stream) { + unset( - $this->readStreams[(int) $stream], - $this->readCallbacks[(int) $stream] + $this->readStreams[(int)$stream], + $this->readCallbacks[(int)$stream] ); + } /** * Stop watching a stream for writes. * * @param resource $stream + * @return void */ - public function removeWriteStream($stream) - { + function removeWriteStream($stream) { + unset( - $this->writeStreams[(int) $stream], - $this->writeCallbacks[(int) $stream] + $this->writeStreams[(int)$stream], + $this->writeCallbacks[(int)$stream] ); + } + /** * Runs the loop. * - * This function will run continuously, until there's no more events to + * This function will run continiously, until there's no more events to * handle. + * + * @return void */ - public function run() - { + function run() { + $this->running = true; do { + $hasEvents = $this->tick(true); + } while ($this->running && $hasEvents); $this->running = false; + } /** @@ -187,8 +210,8 @@ class Loop * This function will return true if there are _any_ events left in the * loop after the tick. */ - public function tick(bool $block = false): bool - { + function tick(bool $block = false) : bool { + $this->runNextTicks(); $nextTimeout = $this->runTimers(); @@ -209,15 +232,19 @@ class Loop $this->runStreams($streamWait); - return $this->readStreams || $this->writeStreams || $this->nextTick || $this->timers; + return ($this->readStreams || $this->writeStreams || $this->nextTick || $this->timers); + } /** - * Stops a running eventloop. + * Stops a running eventloop + * + * @return void */ - public function stop() - { + function stop() { + $this->running = false; + } /** @@ -225,14 +252,15 @@ class Loop * * return void */ - protected function runNextTicks() - { + protected function runNextTicks() { + $nextTick = $this->nextTick; $this->nextTick = []; foreach ($nextTick as $cb) { $cb(); } + } /** @@ -245,8 +273,8 @@ class Loop * * @return float|null */ - protected function runTimers() - { + protected function runTimers() { + $now = microtime(true); while (($timer = array_pop($this->timers)) && $timer[0] < $now) { $timer[1](); @@ -254,9 +282,9 @@ class Loop // Add the last timer back to the array. if ($timer) { $this->timers[] = $timer; - return max(0, $timer[0] - microtime(true)); } + } /** @@ -267,31 +295,36 @@ class Loop * * @param float|null timeout */ - protected function runStreams($timeout) - { + protected function runStreams($timeout) { + if ($this->readStreams || $this->writeStreams) { + $read = $this->readStreams; $write = $this->writeStreams; $except = null; - if (stream_select($read, $write, $except, (null === $timeout) ? null : 0, $timeout ? (int) ($timeout * 1000000) : 0)) { + if (stream_select($read, $write, $except, ($timeout === null) ? null : 0, $timeout ? (int)($timeout * 1000000) : 0)) { + // See PHP Bug https://bugs.php.net/bug.php?id=62452 // Fixed in PHP7 foreach ($read as $readStream) { - $readCb = $this->readCallbacks[(int) $readStream]; + $readCb = $this->readCallbacks[(int)$readStream]; $readCb(); } foreach ($write as $writeStream) { - $writeCb = $this->writeCallbacks[(int) $writeStream]; + $writeCb = $this->writeCallbacks[(int)$writeStream]; $writeCb(); } + } + } elseif ($this->running && ($this->nextTick || $this->timers)) { - usleep(null !== $timeout ? intval($timeout * 1000000) : 200000); + usleep($timeout !== null ? intval($timeout * 1000000) : 200000); } + } /** - * Is the main loop active. + * Is the main loop active * * @var bool */ @@ -328,14 +361,16 @@ class Loop /** * List of read callbacks, indexed by stream id. * - * @var callable[] + * @var callback[] */ protected $readCallbacks = []; /** * List of write callbacks, indexed by stream id. * - * @var callable[] + * @var callback[] */ protected $writeCallbacks = []; + + } diff --git a/vendor/sabre/event/lib/Loop/functions.php b/vendor/sabre/event/lib/Loop/functions.php index bf4d933f2..b5884b2b6 100644 --- a/vendor/sabre/event/lib/Loop/functions.php +++ b/vendor/sabre/event/lib/Loop/functions.php @@ -1,15 +1,16 @@ -setTimeout($cb, $timeout); + } /** @@ -18,27 +19,35 @@ function setTimeout(callable $cb, float $timeout) * The value this function returns can be used to stop the interval with * clearInterval. */ -function setInterval(callable $cb, float $timeout): array -{ +function setInterval(callable $cb, float $timeout) : array { + return instance()->setInterval($cb, $timeout); + } /** * Stops a running interval. + * + * @return void */ -function clearInterval(array $intervalId) -{ +function clearInterval(array $intervalId) { + instance()->clearInterval($intervalId); + } /** * Runs a function immediately at the next iteration of the loop. + * + * @return void */ -function nextTick(callable $cb) -{ +function nextTick(callable $cb) { + instance()->nextTick($cb); + } + /** * Adds a read stream. * @@ -49,10 +58,12 @@ function nextTick(callable $cb) * prevent the eventloop from never stopping. * * @param resource $stream + * @return void */ -function addReadStream($stream, callable $cb) -{ +function addReadStream($stream, callable $cb) { + instance()->addReadStream($stream, $cb); + } /** @@ -65,41 +76,51 @@ function addReadStream($stream, callable $cb) * prevent the eventloop from never stopping. * * @param resource $stream + * @return void */ -function addWriteStream($stream, callable $cb) -{ +function addWriteStream($stream, callable $cb) { + instance()->addWriteStream($stream, $cb); + } /** * Stop watching a stream for reads. * * @param resource $stream + * @return void */ -function removeReadStream($stream) -{ +function removeReadStream($stream) { + instance()->removeReadStream($stream); + } /** * Stop watching a stream for writes. * * @param resource $stream + * @return void */ -function removeWriteStream($stream) -{ +function removeWriteStream($stream) { + instance()->removeWriteStream($stream); + } + /** * Runs the loop. * - * This function will run continuously, until there's no more events to + * This function will run continiously, until there's no more events to * handle. + * + * @return void */ -function run() -{ +function run() { + instance()->run(); + } /** @@ -114,30 +135,34 @@ function run() * This function will return true if there are _any_ events left in the * loop after the tick. */ -function tick(bool $block = false): bool -{ +function tick(bool $block = false) : bool { + return instance()->tick($block); + } /** - * Stops a running eventloop. + * Stops a running eventloop + * + * @return void */ -function stop() -{ +function stop() { + instance()->stop(); + } /** * Retrieves or sets the global Loop object. */ -function instance(Loop $newLoop = null): Loop -{ +function instance(Loop $newLoop = null) : Loop { + static $loop; if ($newLoop) { $loop = $newLoop; } elseif (!$loop) { $loop = new Loop(); } - return $loop; + } diff --git a/vendor/sabre/event/lib/Promise.php b/vendor/sabre/event/lib/Promise.php index 1d4ddd74a..1d04bd4d4 100644 --- a/vendor/sabre/event/lib/Promise.php +++ b/vendor/sabre/event/lib/Promise.php @@ -1,6 +1,4 @@ -fulfill and $this->reject. * Using the executor is optional. */ - public function __construct(callable $executor = null) - { + function __construct(callable $executor = null) { + if ($executor) { $executor( [$this, 'fulfill'], [$this, 'reject'] ); } + } /** @@ -85,32 +84,32 @@ class Promise * If either of the callbacks throw an exception, the returned promise will * be rejected and the exception will be passed back. */ - public function then(callable $onFulfilled = null, callable $onRejected = null): Promise - { + function then(callable $onFulfilled = null, callable $onRejected = null) : Promise { + // This new subPromise will be returned from this function, and will // be fulfilled with the result of the onFulfilled or onRejected event // handlers. $subPromise = new self(); switch ($this->state) { - case self::PENDING: + case self::PENDING : // The operation is pending, so we keep a reference to the // event handlers so we can call them later. $this->subscribers[] = [$subPromise, $onFulfilled, $onRejected]; break; - case self::FULFILLED: + case self::FULFILLED : // The async operation is already fulfilled, so we trigger the // onFulfilled callback asap. $this->invokeCallback($subPromise, $onFulfilled); break; - case self::REJECTED: - // The async operation failed, so we call the onRejected + case self::REJECTED : + // The async operation failed, so we call teh onRejected // callback asap. $this->invokeCallback($subPromise, $onRejected); break; } - return $subPromise; + } /** @@ -119,19 +118,20 @@ class Promise * Its usage is identical to then(). However, the otherwise() function is * preferred. */ - public function otherwise(callable $onRejected): Promise - { + function otherwise(callable $onRejected) : Promise { + return $this->then(null, $onRejected); + } /** * Marks this promise as fulfilled and sets its return value. * * @param mixed $value + * @return void */ - public function fulfill($value = null) - { - if (self::PENDING !== $this->state) { + function fulfill($value = null) { + if ($this->state !== self::PENDING) { throw new PromiseAlreadyResolvedException('This promise is already resolved, and you\'re not allowed to resolve a promise more than once'); } $this->state = self::FULFILLED; @@ -143,10 +143,11 @@ class Promise /** * Marks this promise as rejected, and set it's rejection reason. + * + * @return void */ - public function reject(Throwable $reason) - { - if (self::PENDING !== $this->state) { + function reject(Throwable $reason) { + if ($this->state !== self::PENDING) { throw new PromiseAlreadyResolvedException('This promise is already resolved, and you\'re not allowed to resolve a promise more than once'); } $this->state = self::REJECTED; @@ -154,12 +155,13 @@ class Promise foreach ($this->subscribers as $subscriber) { $this->invokeCallback($subscriber[0], $subscriber[2]); } + } /** * Stops execution until this promise is resolved. * - * This method stops execution completely. If the promise is successful with + * This method stops exection completely. If the promise is successful with * a value, this method will return this value. If the promise was * rejected, this method will throw an exception. * @@ -169,10 +171,11 @@ class Promise * * @return mixed */ - public function wait() - { + function wait() { + $hasEvents = true; - while (self::PENDING === $this->state) { + while ($this->state === self::PENDING) { + if (!$hasEvents) { throw new \LogicException('There were no more events in the loop. This promise will never be fulfilled.'); } @@ -180,9 +183,10 @@ class Promise // As long as the promise is not fulfilled, we tell the event loop // to handle events, and to block. $hasEvents = Loop\tick(true); + } - if (self::FULFILLED === $this->state) { + if ($this->state === self::FULFILLED) { // If the state of this promise is fulfilled, we can return the value. return $this->value; } else { @@ -190,8 +194,11 @@ class Promise // errored. Therefore we need to throw an exception. throw $this->value; } + + } + /** * A list of subscribers. Subscribers are the callbacks that want us to let * them know if the callback was fulfilled or rejected. @@ -217,18 +224,21 @@ class Promise * correctly, and any chained promises are also correctly fulfilled or * rejected. * + * @param Promise $subPromise * @param callable $callBack + * @return void */ - private function invokeCallback(Promise $subPromise, callable $callBack = null) - { + private function invokeCallback(Promise $subPromise, callable $callBack = null) { + // We use 'nextTick' to ensure that the event handlers are always // triggered outside of the calling stack in which they were originally // passed to 'then'. // // This makes the order of execution more predictable. - Loop\nextTick(function () use ($callBack, $subPromise) { + Loop\nextTick(function() use ($callBack, $subPromise) { if (is_callable($callBack)) { try { + $result = $callBack($this->value); if ($result instanceof self) { // If the callback (onRejected or onFulfilled) @@ -247,7 +257,7 @@ class Promise $subPromise->reject($e); } } else { - if (self::FULFILLED === $this->state) { + if ($this->state === self::FULFILLED) { $subPromise->fulfill($this->value); } else { $subPromise->reject($this->value); @@ -255,4 +265,5 @@ class Promise } }); } + } diff --git a/vendor/sabre/event/lib/Promise/functions.php b/vendor/sabre/event/lib/Promise/functions.php index 986fe2b00..275492cbc 100644 --- a/vendor/sabre/event/lib/Promise/functions.php +++ b/vendor/sabre/event/lib/Promise/functions.php @@ -1,6 +1,4 @@ - $subPromise) { + $subPromise->then( - function ($result) use ($promiseIndex, &$completeResult, &$successCount, $success, $promises) { + function($result) use ($promiseIndex, &$completeResult, &$successCount, $success, $promises) { $completeResult[$promiseIndex] = $result; - ++$successCount; + $successCount++; if ($successCount === count($promises)) { $success($completeResult); } - return $result; } )->otherwise( - function ($reason) use ($fail) { + function($reason) use ($fail) { $fail($reason); } ); + } }); + } /** @@ -71,20 +72,22 @@ function all(array $promises): Promise * * @param Promise[] $promises */ -function race(array $promises): Promise -{ - return new Promise(function ($success, $fail) use ($promises) { +function race(array $promises) : Promise { + + return new Promise(function($success, $fail) use ($promises) { + $alreadyDone = false; foreach ($promises as $promise) { + $promise->then( - function ($result) use ($success, &$alreadyDone) { + function($result) use ($success, &$alreadyDone) { if ($alreadyDone) { return; } $alreadyDone = true; $success($result); }, - function ($reason) use ($fail, &$alreadyDone) { + function($reason) use ($fail, &$alreadyDone) { if ($alreadyDone) { return; } @@ -92,10 +95,14 @@ function race(array $promises): Promise $fail($reason); } ); + } + }); + } + /** * Returns a Promise that resolves with the given value. * @@ -104,25 +111,25 @@ function race(array $promises): Promise * * @param mixed $value */ -function resolve($value): Promise -{ +function resolve($value) : Promise { + if ($value instanceof Promise) { return $value->then(); } else { $promise = new Promise(); $promise->fulfill($value); - return $promise; } + } /** * Returns a Promise that will reject with the given reason. */ -function reject(Throwable $reason): Promise -{ +function reject(Throwable $reason) : Promise { + $promise = new Promise(); $promise->reject($reason); - return $promise; + } diff --git a/vendor/sabre/event/lib/PromiseAlreadyResolvedException.php b/vendor/sabre/event/lib/PromiseAlreadyResolvedException.php index abb6c108e..534a3d494 100644 --- a/vendor/sabre/event/lib/PromiseAlreadyResolvedException.php +++ b/vendor/sabre/event/lib/PromiseAlreadyResolvedException.php @@ -1,6 +1,4 @@ -wildcardListeners; + $listeners = & $this->wildcardListeners; } else { - $listeners = &$this->listeners; + $listeners = & $this->listeners; } // Always fully reset the listener index. This is fairly sane for most @@ -44,27 +44,32 @@ trait WildcardEmitterTrait $listeners[$eventName] = []; } $listeners[$eventName][] = [$priority, $callBack]; + } /** * Subscribe to an event exactly once. + * + * @return void */ - public function once(string $eventName, callable $callBack, int $priority = 100) - { + function once(string $eventName, callable $callBack, int $priority = 100) { + $wrapper = null; - $wrapper = function () use ($eventName, $callBack, &$wrapper) { - $this->removeListener($eventName, $wrapper); + $wrapper = function() use ($eventName, $callBack, &$wrapper) { + $this->removeListener($eventName, $wrapper); return \call_user_func_array($callBack, \func_get_args()); + }; $this->on($eventName, $wrapper, $priority); + } /** * Emits an event. * - * This method will return true if 0 or more listeners were successfully + * This method will return true if 0 or more listeners were succesfully * handled. false is returned if one of the events broke the event chain. * * If the continueCallBack is specified, this callback will be called every @@ -82,35 +87,42 @@ trait WildcardEmitterTrait * Lastly, if there are 5 event handlers for an event. The continueCallback * will be called at most 4 times. */ - public function emit(string $eventName, array $arguments = [], callable $continueCallBack = null): bool - { + function emit(string $eventName, array $arguments = [], callable $continueCallBack = null) : bool { + if (\is_null($continueCallBack)) { + foreach ($this->listeners($eventName) as $listener) { + $result = \call_user_func_array($listener, $arguments); - if (false === $result) { + if ($result === false) { return false; } } + } else { + $listeners = $this->listeners($eventName); $counter = \count($listeners); foreach ($listeners as $listener) { - --$counter; + + $counter--; $result = \call_user_func_array($listener, $arguments); - if (false === $result) { + if ($result === false) { return false; } if ($counter > 0) { - if (!$continueCallBack()) { - break; - } + if (!$continueCallBack()) break; } + } + } return true; + + } /** @@ -121,27 +133,34 @@ trait WildcardEmitterTrait * * @return callable[] */ - public function listeners(string $eventName): array - { + function listeners(string $eventName) : array { + if (!\array_key_exists($eventName, $this->listenerIndex)) { + // Create a new index. $listeners = []; $listenersPriority = []; - if (isset($this->listeners[$eventName])) { - foreach ($this->listeners[$eventName] as $listener) { - $listenersPriority[] = $listener[0]; - $listeners[] = $listener[1]; - } + if (isset($this->listeners[$eventName])) foreach ($this->listeners[$eventName] as $listener) { + + $listenersPriority[] = $listener[0]; + $listeners[] = $listener[1]; + } foreach ($this->wildcardListeners as $wcEvent => $wcListeners) { + // Wildcard match if (\substr($eventName, 0, \strlen($wcEvent)) === $wcEvent) { + foreach ($wcListeners as $listener) { + $listenersPriority[] = $listener[0]; $listeners[] = $listener[1]; + } + } + } // Sorting by priority @@ -149,9 +168,11 @@ trait WildcardEmitterTrait // Creating index $this->listenerIndex[$eventName] = $listeners; + } return $this->listenerIndex[$eventName]; + } /** @@ -160,14 +181,14 @@ trait WildcardEmitterTrait * If the listener could not be found, this method will return false. If it * was removed it will return true. */ - public function removeListener(string $eventName, callable $listener): bool - { - // If it ends with a wildcard, we use the wildcardListeners array - if ('*' === $eventName[\strlen($eventName) - 1]) { + function removeListener(string $eventName, callable $listener) : bool { + + // If it ends with a wildcard, we use the wildcardListeners array + if ($eventName[\strlen($eventName) - 1] === '*') { $eventName = \substr($eventName, 0, -1); - $listeners = &$this->wildcardListeners; + $listeners = & $this->wildcardListeners; } else { - $listeners = &$this->listeners; + $listeners = & $this->listeners; } if (!isset($listeners[$eventName])) { @@ -175,17 +196,21 @@ trait WildcardEmitterTrait } foreach ($listeners[$eventName] as $index => $check) { + if ($check[1] === $listener) { + // Remove listener unset($listeners[$eventName][$index]); // Reset index $this->listenerIndex = []; - return true; + } + } return false; + } /** @@ -194,32 +219,38 @@ trait WildcardEmitterTrait * If the eventName argument is specified, all listeners for that event are * removed. If it is not specified, every listener for every event is * removed. + * + * @return void */ - public function removeAllListeners(string $eventName = null) - { + function removeAllListeners(string $eventName = null) { + if (\is_null($eventName)) { $this->listeners = []; $this->wildcardListeners = []; + } else { - if ('*' === $eventName[\strlen($eventName) - 1]) { + + if ($eventName[\strlen($eventName) - 1] === '*') { // Wildcard event unset($this->wildcardListeners[\substr($eventName, 0, -1)]); } else { unset($this->listeners[$eventName]); } + } // Reset index $this->listenerIndex = []; + } /** - * The list of listeners. + * The list of listeners */ protected $listeners = []; /** - * The list of "wildcard listeners". + * The list of "wildcard listeners". */ protected $wildcardListeners = []; diff --git a/vendor/sabre/event/lib/coroutine.php b/vendor/sabre/event/lib/coroutine.php index a6a2baf41..750e8ab52 100644 --- a/vendor/sabre/event/lib/coroutine.php +++ b/vendor/sabre/event/lib/coroutine.php @@ -1,6 +1,4 @@ -valid()) { + $yieldedValue = $generator->current(); if ($yieldedValue instanceof Promise) { $yieldedValue->then( - function ($value) use ($generator, &$advanceGenerator) { + function($value) use ($generator, &$advanceGenerator, &$lastYieldResult) { $generator->send($value); $advanceGenerator(); }, - function (Throwable $reason) use ($generator, $advanceGenerator) { + function(Throwable $reason) use ($generator, $advanceGenerator) { $generator->throw($reason); $advanceGenerator(); } - )->otherwise(function (Throwable $reason) use ($promise) { + )->otherwise(function(Throwable $reason) use ($promise) { // This error handler would be called, if something in the // generator throws an exception, and it's not caught // locally. @@ -88,25 +87,31 @@ function coroutine(callable $gen): Promise // If the value was not a promise, we'll just let it pass through. $generator->send($yieldedValue); } + } // If the generator is at the end, and we didn't run into an exception, // We're grabbing the "return" value and fulfilling our top-level // promise with its value. - if (!$generator->valid() && Promise::PENDING === $promise->state) { - $returnValue = $generator->getReturn(); - - // The return value is a promise. - if ($returnValue instanceof Promise) { - $returnValue->then(function ($value) use ($promise) { - $promise->fulfill($value); - }, function (Throwable $reason) use ($promise) { - $promise->reject($reason); - }); - } else { - $promise->fulfill($returnValue); - } + if (!$generator->valid() && $promise->state === Promise::PENDING) { + $returnValue = $generator->getReturn(); + + // The return value is a promise. + if ($returnValue instanceof Promise) { + $returnValue->then(function($value) use ($promise) { + $promise->fulfill($value); + }, function(Throwable $reason) { + $promise->reject($reason); + }); + } else { + + $promise->fulfill($returnValue); + + } + + } + }; try { @@ -116,4 +121,5 @@ function coroutine(callable $gen): Promise } return $promise; + } -- cgit v1.2.3