aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/event/lib
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2020-05-07 23:35:02 +0200
committerMario <mario@mariovavti.com>2020-05-07 23:35:02 +0200
commitfae70bf0a7f1b566d25e30064f60d58ab150951a (patch)
tree1714511edb85ed0e28034ed9371d5fc515504fd6 /vendor/sabre/event/lib
parentffd2faf8a09a870e8dbecb3ad168e0a9b25941d3 (diff)
downloadvolse-hubzilla-fae70bf0a7f1b566d25e30064f60d58ab150951a.tar.gz
volse-hubzilla-fae70bf0a7f1b566d25e30064f60d58ab150951a.tar.bz2
volse-hubzilla-fae70bf0a7f1b566d25e30064f60d58ab150951a.zip
Revert "composer updates"
This reverts commit dbfe748d274f6843fc91a3071df7be45c4ab5b00
Diffstat (limited to 'vendor/sabre/event/lib')
-rw-r--r--vendor/sabre/event/lib/Emitter.php9
-rw-r--r--vendor/sabre/event/lib/EmitterInterface.php31
-rw-r--r--vendor/sabre/event/lib/EmitterTrait.php79
-rw-r--r--vendor/sabre/event/lib/EventEmitter.php9
-rw-r--r--vendor/sabre/event/lib/Loop/Loop.php147
-rw-r--r--vendor/sabre/event/lib/Loop/functions.php85
-rw-r--r--vendor/sabre/event/lib/Promise.php73
-rw-r--r--vendor/sabre/event/lib/Promise/functions.php53
-rw-r--r--vendor/sabre/event/lib/PromiseAlreadyResolvedException.php8
-rw-r--r--vendor/sabre/event/lib/Version.php13
-rw-r--r--vendor/sabre/event/lib/WildcardEmitter.php13
-rw-r--r--vendor/sabre/event/lib/WildcardEmitterTrait.php119
-rw-r--r--vendor/sabre/event/lib/coroutine.php52
13 files changed, 412 insertions, 279 deletions
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 @@
-<?php
-
-declare(strict_types=1);
+<?php declare (strict_types=1);
namespace Sabre\Event;
@@ -13,7 +11,8 @@ namespace Sabre\Event;
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
-class Emitter implements EmitterInterface
-{
+class Emitter implements EmitterInterface {
+
use EmitterTrait;
+
}
diff --git a/vendor/sabre/event/lib/EmitterInterface.php b/vendor/sabre/event/lib/EmitterInterface.php
index 6ce0f34db..a7e4b6132 100644
--- a/vendor/sabre/event/lib/EmitterInterface.php
+++ b/vendor/sabre/event/lib/EmitterInterface.php
@@ -1,11 +1,9 @@
-<?php
-
-declare(strict_types=1);
+<?php declare (strict_types=1);
namespace Sabre\Event;
/**
- * Event Emitter Interface.
+ * Event Emitter Interface
*
* Anything that accepts listeners and emits events should implement this
* interface.
@@ -14,22 +12,26 @@ namespace Sabre\Event;
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
-interface EmitterInterface
-{
+interface EmitterInterface {
+
/**
* Subscribe to an event.
+ *
+ * @return void
*/
- public function on(string $eventName, callable $callBack, int $priority = 100);
+ function on(string $eventName, callable $callBack, int $priority = 100);
/**
* 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);
/**
* 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
@@ -47,7 +49,7 @@ interface EmitterInterface
* 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;
/**
* Returns the list of listeners for an event.
@@ -57,7 +59,7 @@ interface EmitterInterface
*
* @return callable[]
*/
- public function listeners(string $eventName): array;
+ function listeners(string $eventName) : array;
/**
* Removes a specific listener from an event.
@@ -65,7 +67,7 @@ interface EmitterInterface
* 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;
/**
* Removes all listeners.
@@ -73,6 +75,9 @@ interface EmitterInterface
* 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);
+
}
diff --git a/vendor/sabre/event/lib/EmitterTrait.php b/vendor/sabre/event/lib/EmitterTrait.php
index 5502ef9f3..dafae362f 100644
--- a/vendor/sabre/event/lib/EmitterTrait.php
+++ b/vendor/sabre/event/lib/EmitterTrait.php
@@ -1,11 +1,9 @@
-<?php
-
-declare(strict_types=1);
+<?php declare (strict_types=1);
namespace Sabre\Event;
/**
- * Event Emitter Trait.
+ * Event Emitter Trait
*
* This trait contains all the basic functions to implement an
* EventEmitterInterface.
@@ -17,45 +15,53 @@ namespace Sabre\Event;
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
-trait EmitterTrait
-{
+trait EmitterTrait {
+
+
/**
* Subscribe to an event.
+ *
+ * @return void
*/
- public function on(string $eventName, callable $callBack, int $priority = 100)
- {
+ function on(string $eventName, callable $callBack, int $priority = 100) {
+
if (!isset($this->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 @@
-<?php
-
-declare(strict_types=1);
+<?php declare (strict_types=1);
namespace Sabre\Event;
@@ -14,7 +12,8 @@ namespace Sabre\Event;
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
-class EventEmitter implements EmitterInterface
-{
+class EventEmitter implements EmitterInterface {
+
use EmitterTrait;
+
}
diff --git a/vendor/sabre/event/lib/Loop/Loop.php b/vendor/sabre/event/lib/Loop/Loop.php
index ec09be921..301fe8920 100644
--- a/vendor/sabre/event/lib/Loop/Loop.php
+++ b/vendor/sabre/event/lib/Loop/Loop.php
@@ -1,6 +1,4 @@
-<?php
-
-declare(strict_types=1);
+<?php declare (strict_types=1);
namespace Sabre\Event\Loop;
@@ -17,19 +15,20 @@ namespace Sabre\Event\Loop;
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
-class Loop
-{
+class Loop {
+
/**
* Executes a function after x seconds.
+ *
+ * @return void
*/
- public function setTimeout(callable $cb, float $timeout)
- {
+ function setTimeout(callable $cb, float $timeout) {
+
$triggerTime = microtime(true) + ($timeout);
if (!$this->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 @@
-<?php
-
-declare(strict_types=1);
+<?php declare (strict_types=1);
namespace Sabre\Event\Loop;
/**
* Executes a function after x seconds.
+ *
+ * @return void
*/
-function setTimeout(callable $cb, float $timeout)
-{
+function setTimeout(callable $cb, float $timeout) {
+
instance()->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 @@
-<?php
-
-declare(strict_types=1);
+<?php declare (strict_types=1);
namespace Sabre\Event;
@@ -23,8 +21,8 @@ use Throwable;
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
-class Promise
-{
+class Promise {
+
/**
* The asynchronous operation is pending.
*/
@@ -56,14 +54,15 @@ class Promise
* Each are callbacks that map to $this->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 @@
-<?php
-
-declare(strict_types=1);
+<?php declare (strict_types=1);
namespace Sabre\Event\Promise;
@@ -16,6 +14,7 @@ use Throwable;
* @license http://sabre.io/license/ Modified BSD License
*/
+
/**
* This function takes an array of Promises, and returns a Promise that
* resolves when all of the given arguments have resolved.
@@ -25,17 +24,17 @@ use Throwable;
*
* This array will be in the exact same order as the array of input promises.
*
- * If any of the given Promises fails, the returned promise will immediately
+ * If any of the given Promises fails, the returned promise will immidiately
* fail with the first Promise that fails, and its reason.
*
* @param Promise[] $promises
*/
-function all(array $promises): Promise
-{
- return new Promise(function ($success, $fail) use ($promises) {
+function all(array $promises) : Promise {
+
+ return new Promise(function($success, $fail) use ($promises) {
+
if (empty($promises)) {
$success([]);
-
return;
}
@@ -43,23 +42,25 @@ function all(array $promises): Promise
$completeResult = [];
foreach ($promises as $promiseIndex => $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 @@
-<?php
-
-declare(strict_types=1);
+<?php declare (strict_types=1);
namespace Sabre\Event;
@@ -12,6 +10,6 @@ namespace Sabre\Event;
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
-class PromiseAlreadyResolvedException extends \LogicException
-{
+class PromiseAlreadyResolvedException extends \LogicException {
+
}
diff --git a/vendor/sabre/event/lib/Version.php b/vendor/sabre/event/lib/Version.php
index e98e2e3ff..9aee4b3ab 100644
--- a/vendor/sabre/event/lib/Version.php
+++ b/vendor/sabre/event/lib/Version.php
@@ -1,6 +1,4 @@
-<?php
-
-declare(strict_types=1);
+<?php declare (strict_types=1);
namespace Sabre\Event;
@@ -11,10 +9,11 @@ namespace Sabre\Event;
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
-class Version
-{
+class Version {
+
/**
- * Full version number.
+ * Full version number
*/
- const VERSION = '5.1.0';
+ const VERSION = '5.0.3';
+
}
diff --git a/vendor/sabre/event/lib/WildcardEmitter.php b/vendor/sabre/event/lib/WildcardEmitter.php
index 1b7c248b2..2ef15fe83 100644
--- a/vendor/sabre/event/lib/WildcardEmitter.php
+++ b/vendor/sabre/event/lib/WildcardEmitter.php
@@ -1,6 +1,4 @@
-<?php
-
-declare(strict_types=1);
+<?php declare (strict_types=1);
namespace Sabre\Event;
@@ -16,7 +14,7 @@ namespace Sabre\Event;
* on('change:*')
*
* A few notes:
- *
+ *
* - Wildcards only work at the end of an event name.
* - Currently you can only use 1 wildcard.
* - Using ":" as a separator is optional, but it's highly recommended to use
@@ -30,7 +28,10 @@ namespace Sabre\Event;
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
-class WildcardEmitter implements EmitterInterface
-{
+class WildcardEmitter implements EmitterInterface {
+
use WildcardEmitterTrait;
+
+
+
}
diff --git a/vendor/sabre/event/lib/WildcardEmitterTrait.php b/vendor/sabre/event/lib/WildcardEmitterTrait.php
index 206a8f3c5..7d8d62c26 100644
--- a/vendor/sabre/event/lib/WildcardEmitterTrait.php
+++ b/vendor/sabre/event/lib/WildcardEmitterTrait.php
@@ -1,11 +1,9 @@
-<?php
-
-declare(strict_types=1);
+<?php declare (strict_types=1);
namespace Sabre\Event;
/**
- * Wildcard Emitter Trait.
+ * Wildcard Emitter Trait
*
* This trait provides the implementation for WildCardEmitter
* Refer to that class for the full documentation about this
@@ -19,19 +17,21 @@ namespace Sabre\Event;
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
-trait WildcardEmitterTrait
-{
+trait WildcardEmitterTrait {
+
/**
* Subscribe to an event.
+ *
+ * @return void
*/
- public function on(string $eventName, callable $callBack, int $priority = 100)
- {
- // If it ends with a wildcard, we use the wildcardListeners array
- if ('*' === $eventName[\strlen($eventName) - 1]) {
+ function on(string $eventName, callable $callBack, int $priority = 100) {
+
+ // 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;
}
// 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 @@
-<?php
-
-declare(strict_types=1);
+<?php declare (strict_types=1);
namespace Sabre\Event;
@@ -43,13 +41,12 @@ use Throwable;
* });
*
* @return \Sabre\Event\Promise
- *
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
-function coroutine(callable $gen): Promise
-{
+function coroutine(callable $gen) : Promise {
+
$generator = $gen();
if (!$generator instanceof Generator) {
throw new \InvalidArgumentException('You must pass a generator function');
@@ -62,20 +59,22 @@ function coroutine(callable $gen): Promise
* So tempted to use the mythical y-combinator here, but it's not needed in
* PHP.
*/
- $advanceGenerator = function () use (&$advanceGenerator, $generator, $promise) {
+ $advanceGenerator = function() use (&$advanceGenerator, $generator, $promise, &$lastYieldResult) {
+
while ($generator->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;
+
}