From dbfe748d274f6843fc91a3071df7be45c4ab5b00 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 7 May 2020 15:22:25 +0000 Subject: composer updates --- 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, 279 insertions(+), 412 deletions(-) (limited to 'vendor/sabre/event/lib') diff --git a/vendor/sabre/event/lib/Emitter.php b/vendor/sabre/event/lib/Emitter.php index ab5e8c90e..e1f23fc87 100644 --- a/vendor/sabre/event/lib/Emitter.php +++ b/vendor/sabre/event/lib/Emitter.php @@ -1,4 +1,6 @@ -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 */ - function once(string $eventName, callable $callBack, int $priority = 100) { - + public function once(string $eventName, callable $callBack, int $priority = 100) + { $wrapper = null; - $wrapper = function() use ($eventName, $callBack, &$wrapper) { - + $wrapper = function () use ($eventName, $callBack, &$wrapper) { $this->removeListener($eventName, $wrapper); - return \call_user_func_array($callBack, \func_get_args()); + 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 succesfully + * This method will return true if 0 or more listeners were successfully * handled. false is returned if one of the events broke the event chain. * * If the continueCallBack is specified, this callback will be called every @@ -79,41 +73,35 @@ trait EmitterTrait { * Lastly, if there are 5 event handlers for an event. The continueCallback * will be called at most 4 times. */ - function emit(string $eventName, array $arguments = [], callable $continueCallBack = null) : bool { - + public 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 ($result === false) { + if (false === $result) { return false; } } - } else { - $listeners = $this->listeners($eventName); $counter = \count($listeners); foreach ($listeners as $listener) { - - $counter--; + --$counter; $result = \call_user_func_array($listener, $arguments); - if ($result === false) { + if (false === $result) { return false; } if ($counter > 0) { - if (!$continueCallBack()) break; + if (!$continueCallBack()) { + break; + } } - } - } return true; - } /** @@ -124,15 +112,14 @@ trait EmitterTrait { * * @return callable[] */ - function listeners(string $eventName) : array { - + public 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]); @@ -141,7 +128,6 @@ trait EmitterTrait { } return $this->listeners[$eventName][2]; - } /** @@ -150,8 +136,8 @@ trait EmitterTrait { * If the listener could not be found, this method will return false. If it * was removed it will return true. */ - function removeListener(string $eventName, callable $listener) : bool { - + public function removeListener(string $eventName, callable $listener): bool + { if (!isset($this->listeners[$eventName])) { return false; } @@ -159,11 +145,12 @@ trait EmitterTrait { if ($check === $listener) { unset($this->listeners[$eventName][1][$index]); unset($this->listeners[$eventName][2][$index]); + return true; } } - return false; + return false; } /** @@ -172,24 +159,20 @@ 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 */ - function removeAllListeners(string $eventName = null) { - + public 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 cae6ac2a6..18971e3ee 100644 --- a/vendor/sabre/event/lib/EventEmitter.php +++ b/vendor/sabre/event/lib/EventEmitter.php @@ -1,4 +1,6 @@ -timers) { // Special case when the timers array was empty. $this->timers[] = [$triggerTime, $cb]; + return; } @@ -46,14 +47,12 @@ class Loop { [[$triggerTime, $cb]] ); break; - } elseif ($index === 0) { + } elseif (0 === $index) { array_unshift($this->timers, [$triggerTime, $cb]); break; } - $index--; - + --$index; } - } /** @@ -62,12 +61,12 @@ class Loop { * The value this function returns can be used to stop the interval with * clearInterval. */ - function setInterval(callable $cb, float $timeout) : array { - + public 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); @@ -82,32 +81,24 @@ 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 */ - function clearInterval(array $intervalId) { - + public function clearInterval(array $intervalId) + { $intervalId[1] = false; - } /** * Runs a function immediately at the next iteration of the loop. - * - * @return void */ - function nextTick(callable $cb) { - + public function nextTick(callable $cb) + { $this->nextTick[] = $cb; - } - /** * Adds a read stream. * @@ -118,13 +109,11 @@ class Loop { * prevent the eventloop from never stopping. * * @param resource $stream - * @return void */ - function addReadStream($stream, callable $cb) { - - $this->readStreams[(int)$stream] = $stream; - $this->readCallbacks[(int)$stream] = $cb; - + public function addReadStream($stream, callable $cb) + { + $this->readStreams[(int) $stream] = $stream; + $this->readCallbacks[(int) $stream] = $cb; } /** @@ -137,65 +126,53 @@ class Loop { * prevent the eventloop from never stopping. * * @param resource $stream - * @return void */ - function addWriteStream($stream, callable $cb) { - - $this->writeStreams[(int)$stream] = $stream; - $this->writeCallbacks[(int)$stream] = $cb; - + public 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 */ - function removeReadStream($stream) { - + public 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 */ - function removeWriteStream($stream) { - + public 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 continiously, until there's no more events to + * This function will run continuously, until there's no more events to * handle. - * - * @return void */ - function run() { - + public function run() + { $this->running = true; do { - $hasEvents = $this->tick(true); - } while ($this->running && $hasEvents); $this->running = false; - } /** @@ -210,8 +187,8 @@ class Loop { * This function will return true if there are _any_ events left in the * loop after the tick. */ - function tick(bool $block = false) : bool { - + public function tick(bool $block = false): bool + { $this->runNextTicks(); $nextTimeout = $this->runTimers(); @@ -232,19 +209,15 @@ 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 - * - * @return void + * Stops a running eventloop. */ - function stop() { - + public function stop() + { $this->running = false; - } /** @@ -252,15 +225,14 @@ class Loop { * * return void */ - protected function runNextTicks() { - + protected function runNextTicks() + { $nextTick = $this->nextTick; $this->nextTick = []; foreach ($nextTick as $cb) { $cb(); } - } /** @@ -273,8 +245,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](); @@ -282,9 +254,9 @@ class Loop { // Add the last timer back to the array. if ($timer) { $this->timers[] = $timer; + return max(0, $timer[0] - microtime(true)); } - } /** @@ -295,36 +267,31 @@ 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, ($timeout === null) ? null : 0, $timeout ? (int)($timeout * 1000000) : 0)) { - + if (stream_select($read, $write, $except, (null === $timeout) ? 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($timeout !== null ? intval($timeout * 1000000) : 200000); + usleep(null !== $timeout ? intval($timeout * 1000000) : 200000); } - } /** - * Is the main loop active + * Is the main loop active. * * @var bool */ @@ -361,16 +328,14 @@ class Loop { /** * List of read callbacks, indexed by stream id. * - * @var callback[] + * @var callable[] */ protected $readCallbacks = []; /** * List of write callbacks, indexed by stream id. * - * @var callback[] + * @var callable[] */ protected $writeCallbacks = []; - - } diff --git a/vendor/sabre/event/lib/Loop/functions.php b/vendor/sabre/event/lib/Loop/functions.php index b5884b2b6..bf4d933f2 100644 --- a/vendor/sabre/event/lib/Loop/functions.php +++ b/vendor/sabre/event/lib/Loop/functions.php @@ -1,16 +1,15 @@ -setTimeout($cb, $timeout); - } /** @@ -19,35 +18,27 @@ 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. * @@ -58,12 +49,10 @@ 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); - } /** @@ -76,51 +65,41 @@ 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 continiously, until there's no more events to + * This function will run continuously, until there's no more events to * handle. - * - * @return void */ -function run() { - +function run() +{ instance()->run(); - } /** @@ -135,34 +114,30 @@ 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 - * - * @return void + * Stops a running eventloop. */ -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; + return $loop; } diff --git a/vendor/sabre/event/lib/Promise.php b/vendor/sabre/event/lib/Promise.php index 1d04bd4d4..1d4ddd74a 100644 --- a/vendor/sabre/event/lib/Promise.php +++ b/vendor/sabre/event/lib/Promise.php @@ -1,4 +1,6 @@ -fulfill and $this->reject. * Using the executor is optional. */ - function __construct(callable $executor = null) { - + public function __construct(callable $executor = null) + { if ($executor) { $executor( [$this, 'fulfill'], [$this, 'reject'] ); } - } /** @@ -84,32 +85,32 @@ class Promise { * If either of the callbacks throw an exception, the returned promise will * be rejected and the exception will be passed back. */ - function then(callable $onFulfilled = null, callable $onRejected = null) : Promise { - + public 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 teh onRejected + case self::REJECTED: + // The async operation failed, so we call the onRejected // callback asap. $this->invokeCallback($subPromise, $onRejected); break; } - return $subPromise; + return $subPromise; } /** @@ -118,20 +119,19 @@ class Promise { * Its usage is identical to then(). However, the otherwise() function is * preferred. */ - function otherwise(callable $onRejected) : Promise { - + public 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 */ - function fulfill($value = null) { - if ($this->state !== self::PENDING) { + public function fulfill($value = null) + { + if (self::PENDING !== $this->state) { 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,11 +143,10 @@ class Promise { /** * Marks this promise as rejected, and set it's rejection reason. - * - * @return void */ - function reject(Throwable $reason) { - if ($this->state !== self::PENDING) { + public function reject(Throwable $reason) + { + if (self::PENDING !== $this->state) { throw new PromiseAlreadyResolvedException('This promise is already resolved, and you\'re not allowed to resolve a promise more than once'); } $this->state = self::REJECTED; @@ -155,13 +154,12 @@ class Promise { foreach ($this->subscribers as $subscriber) { $this->invokeCallback($subscriber[0], $subscriber[2]); } - } /** * Stops execution until this promise is resolved. * - * This method stops exection completely. If the promise is successful with + * This method stops execution 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. * @@ -171,11 +169,10 @@ class Promise { * * @return mixed */ - function wait() { - + public function wait() + { $hasEvents = true; - while ($this->state === self::PENDING) { - + while (self::PENDING === $this->state) { if (!$hasEvents) { throw new \LogicException('There were no more events in the loop. This promise will never be fulfilled.'); } @@ -183,10 +180,9 @@ 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 ($this->state === self::FULFILLED) { + if (self::FULFILLED === $this->state) { // If the state of this promise is fulfilled, we can return the value. return $this->value; } else { @@ -194,11 +190,8 @@ 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. @@ -224,21 +217,18 @@ 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) @@ -257,7 +247,7 @@ class Promise { $subPromise->reject($e); } } else { - if ($this->state === self::FULFILLED) { + if (self::FULFILLED === $this->state) { $subPromise->fulfill($this->value); } else { $subPromise->reject($this->value); @@ -265,5 +255,4 @@ class Promise { } }); } - } diff --git a/vendor/sabre/event/lib/Promise/functions.php b/vendor/sabre/event/lib/Promise/functions.php index 275492cbc..986fe2b00 100644 --- a/vendor/sabre/event/lib/Promise/functions.php +++ b/vendor/sabre/event/lib/Promise/functions.php @@ -1,4 +1,6 @@ - $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); } ); - } }); - } /** @@ -72,22 +71,20 @@ 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; } @@ -95,14 +92,10 @@ function race(array $promises) : Promise { $fail($reason); } ); - } - }); - } - /** * Returns a Promise that resolves with the given value. * @@ -111,25 +104,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; + return $promise; } diff --git a/vendor/sabre/event/lib/PromiseAlreadyResolvedException.php b/vendor/sabre/event/lib/PromiseAlreadyResolvedException.php index 534a3d494..abb6c108e 100644 --- a/vendor/sabre/event/lib/PromiseAlreadyResolvedException.php +++ b/vendor/sabre/event/lib/PromiseAlreadyResolvedException.php @@ -1,4 +1,6 @@ -wildcardListeners; + $listeners = &$this->wildcardListeners; } else { - $listeners = & $this->listeners; + $listeners = &$this->listeners; } // Always fully reset the listener index. This is fairly sane for most @@ -44,32 +44,27 @@ trait WildcardEmitterTrait { $listeners[$eventName] = []; } $listeners[$eventName][] = [$priority, $callBack]; - } /** * Subscribe to an event exactly once. - * - * @return void */ - function once(string $eventName, callable $callBack, int $priority = 100) { - + public function once(string $eventName, callable $callBack, int $priority = 100) + { $wrapper = null; - $wrapper = function() use ($eventName, $callBack, &$wrapper) { - + $wrapper = function () use ($eventName, $callBack, &$wrapper) { $this->removeListener($eventName, $wrapper); - return \call_user_func_array($callBack, \func_get_args()); + 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 succesfully + * This method will return true if 0 or more listeners were successfully * handled. false is returned if one of the events broke the event chain. * * If the continueCallBack is specified, this callback will be called every @@ -87,42 +82,35 @@ trait WildcardEmitterTrait { * Lastly, if there are 5 event handlers for an event. The continueCallback * will be called at most 4 times. */ - function emit(string $eventName, array $arguments = [], callable $continueCallBack = null) : bool { - + public 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 ($result === false) { + if (false === $result) { return false; } } - } else { - $listeners = $this->listeners($eventName); $counter = \count($listeners); foreach ($listeners as $listener) { - - $counter--; + --$counter; $result = \call_user_func_array($listener, $arguments); - if ($result === false) { + if (false === $result) { return false; } if ($counter > 0) { - if (!$continueCallBack()) break; + if (!$continueCallBack()) { + break; + } } - } - } return true; - - } /** @@ -133,34 +121,27 @@ trait WildcardEmitterTrait { * * @return callable[] */ - function listeners(string $eventName) : array { - + public 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 @@ -168,11 +149,9 @@ trait WildcardEmitterTrait { // Creating index $this->listenerIndex[$eventName] = $listeners; - } return $this->listenerIndex[$eventName]; - } /** @@ -181,14 +160,14 @@ trait WildcardEmitterTrait { * If the listener could not be found, this method will return false. If it * was removed it will return true. */ - function removeListener(string $eventName, callable $listener) : bool { - - // If it ends with a wildcard, we use the wildcardListeners array - if ($eventName[\strlen($eventName) - 1] === '*') { + public 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])) { @@ -196,21 +175,17 @@ 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 true; } - } return false; - } /** @@ -219,38 +194,32 @@ 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 */ - function removeAllListeners(string $eventName = null) { - + public 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 750e8ab52..a6a2baf41 100644 --- a/vendor/sabre/event/lib/coroutine.php +++ b/vendor/sabre/event/lib/coroutine.php @@ -1,4 +1,6 @@ -valid()) { - $yieldedValue = $generator->current(); if ($yieldedValue instanceof Promise) { $yieldedValue->then( - function($value) use ($generator, &$advanceGenerator, &$lastYieldResult) { + function ($value) use ($generator, &$advanceGenerator) { $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. @@ -87,31 +88,25 @@ 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->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); - - } - - + 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); + } } - }; try { @@ -121,5 +116,4 @@ function coroutine(callable $gen) : Promise { } return $promise; - } -- cgit v1.2.3