aboutsummaryrefslogtreecommitdiffhomepage
path: root/assets/php/vendor/react/promise/src
diff options
context:
space:
mode:
authormarvin-borner@live.com2018-04-10 21:50:16 +0200
committermarvin-borner@live.com2018-04-10 21:54:48 +0200
commitfc9401f04a3aca5abb22f87ebc210de8afe11d32 (patch)
treeb0b310f3581764ec3955f4e496a05137a32951c3 /assets/php/vendor/react/promise/src
parent286d643180672f20526f3dc3bd19d7b751e2fa97 (diff)
Initial Commit
Diffstat (limited to 'assets/php/vendor/react/promise/src')
-rw-r--r--assets/php/vendor/react/promise/src/CancellablePromiseInterface.php11
-rw-r--r--assets/php/vendor/react/promise/src/CancellationQueue.php55
-rw-r--r--assets/php/vendor/react/promise/src/Deferred.php60
-rw-r--r--assets/php/vendor/react/promise/src/Exception/LengthException.php7
-rw-r--r--assets/php/vendor/react/promise/src/ExtendedPromiseInterface.php26
-rw-r--r--assets/php/vendor/react/promise/src/FulfilledPromise.php68
-rw-r--r--assets/php/vendor/react/promise/src/LazyPromise.php63
-rw-r--r--assets/php/vendor/react/promise/src/Promise.php216
-rw-r--r--assets/php/vendor/react/promise/src/PromiseInterface.php11
-rw-r--r--assets/php/vendor/react/promise/src/PromisorInterface.php11
-rw-r--r--assets/php/vendor/react/promise/src/RejectedPromise.php76
-rw-r--r--assets/php/vendor/react/promise/src/UnhandledRejectionException.php31
-rw-r--r--assets/php/vendor/react/promise/src/functions.php244
-rw-r--r--assets/php/vendor/react/promise/src/functions_include.php5
14 files changed, 884 insertions, 0 deletions
diff --git a/assets/php/vendor/react/promise/src/CancellablePromiseInterface.php b/assets/php/vendor/react/promise/src/CancellablePromiseInterface.php
new file mode 100644
index 0000000..896db2d
--- /dev/null
+++ b/assets/php/vendor/react/promise/src/CancellablePromiseInterface.php
@@ -0,0 +1,11 @@
+<?php
+
+namespace React\Promise;
+
+interface CancellablePromiseInterface extends PromiseInterface
+{
+ /**
+ * @return void
+ */
+ public function cancel();
+}
diff --git a/assets/php/vendor/react/promise/src/CancellationQueue.php b/assets/php/vendor/react/promise/src/CancellationQueue.php
new file mode 100644
index 0000000..a366994
--- /dev/null
+++ b/assets/php/vendor/react/promise/src/CancellationQueue.php
@@ -0,0 +1,55 @@
+<?php
+
+namespace React\Promise;
+
+class CancellationQueue
+{
+ private $started = false;
+ private $queue = [];
+
+ public function __invoke()
+ {
+ if ($this->started) {
+ return;
+ }
+
+ $this->started = true;
+ $this->drain();
+ }
+
+ public function enqueue($cancellable)
+ {
+ if (!method_exists($cancellable, 'then') || !method_exists($cancellable, 'cancel')) {
+ return;
+ }
+
+ $length = array_push($this->queue, $cancellable);
+
+ if ($this->started && 1 === $length) {
+ $this->drain();
+ }
+ }
+
+ private function drain()
+ {
+ for ($i = key($this->queue); isset($this->queue[$i]); $i++) {
+ $cancellable = $this->queue[$i];
+
+ $exception = null;
+
+ try {
+ $cancellable->cancel();
+ } catch (\Throwable $exception) {
+ } catch (\Exception $exception) {
+ }
+
+ unset($this->queue[$i]);
+
+ if ($exception) {
+ throw $exception;
+ }
+ }
+
+ $this->queue = [];
+ }
+}
diff --git a/assets/php/vendor/react/promise/src/Deferred.php b/assets/php/vendor/react/promise/src/Deferred.php
new file mode 100644
index 0000000..f23980c
--- /dev/null
+++ b/assets/php/vendor/react/promise/src/Deferred.php
@@ -0,0 +1,60 @@
+<?php
+
+namespace React\Promise;
+
+class Deferred implements PromisorInterface
+{
+ private $promise;
+ private $resolveCallback;
+ private $rejectCallback;
+ private $notifyCallback;
+ private $canceller;
+
+ public function __construct(callable $canceller = null)
+ {
+ $this->canceller = $canceller;
+ }
+
+ public function promise()
+ {
+ if (null === $this->promise) {
+ $this->promise = new Promise(function ($resolve, $reject, $notify) {
+ $this->resolveCallback = $resolve;
+ $this->rejectCallback = $reject;
+ $this->notifyCallback = $notify;
+ }, $this->canceller);
+ }
+
+ return $this->promise;
+ }
+
+ public function resolve($value = null)
+ {
+ $this->promise();
+
+ call_user_func($this->resolveCallback, $value);
+ }
+
+ public function reject($reason = null)
+ {
+ $this->promise();
+
+ call_user_func($this->rejectCallback, $reason);
+ }
+
+ public function notify($update = null)
+ {
+ $this->promise();
+
+ call_user_func($this->notifyCallback, $update);
+ }
+
+ /**
+ * @deprecated 2.2.0
+ * @see Deferred::notify()
+ */
+ public function progress($update = null)
+ {
+ $this->notify($update);
+ }
+}
diff --git a/assets/php/vendor/react/promise/src/Exception/LengthException.php b/assets/php/vendor/react/promise/src/Exception/LengthException.php
new file mode 100644
index 0000000..775c48d
--- /dev/null
+++ b/assets/php/vendor/react/promise/src/Exception/LengthException.php
@@ -0,0 +1,7 @@
+<?php
+
+namespace React\Promise\Exception;
+
+class LengthException extends \LengthException
+{
+}
diff --git a/assets/php/vendor/react/promise/src/ExtendedPromiseInterface.php b/assets/php/vendor/react/promise/src/ExtendedPromiseInterface.php
new file mode 100644
index 0000000..9cb6435
--- /dev/null
+++ b/assets/php/vendor/react/promise/src/ExtendedPromiseInterface.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace React\Promise;
+
+interface ExtendedPromiseInterface extends PromiseInterface
+{
+ /**
+ * @return void
+ */
+ public function done(callable $onFulfilled = null, callable $onRejected = null, callable $onProgress = null);
+
+ /**
+ * @return ExtendedPromiseInterface
+ */
+ public function otherwise(callable $onRejected);
+
+ /**
+ * @return ExtendedPromiseInterface
+ */
+ public function always(callable $onFulfilledOrRejected);
+
+ /**
+ * @return ExtendedPromiseInterface
+ */
+ public function progress(callable $onProgress);
+}
diff --git a/assets/php/vendor/react/promise/src/FulfilledPromise.php b/assets/php/vendor/react/promise/src/FulfilledPromise.php
new file mode 100644
index 0000000..914bb5c
--- /dev/null
+++ b/assets/php/vendor/react/promise/src/FulfilledPromise.php
@@ -0,0 +1,68 @@
+<?php
+
+namespace React\Promise;
+
+class FulfilledPromise implements ExtendedPromiseInterface, CancellablePromiseInterface
+{
+ private $value;
+
+ public function __construct($value = null)
+ {
+ if ($value instanceof PromiseInterface) {
+ throw new \InvalidArgumentException('You cannot create React\Promise\FulfilledPromise with a promise. Use React\Promise\resolve($promiseOrValue) instead.');
+ }
+
+ $this->value = $value;
+ }
+
+ public function then(callable $onFulfilled = null, callable $onRejected = null, callable $onProgress = null)
+ {
+ if (null === $onFulfilled) {
+ return $this;
+ }
+
+ try {
+ return resolve($onFulfilled($this->value));
+ } catch (\Throwable $exception) {
+ return new RejectedPromise($exception);
+ } catch (\Exception $exception) {
+ return new RejectedPromise($exception);
+ }
+ }
+
+ public function done(callable $onFulfilled = null, callable $onRejected = null, callable $onProgress = null)
+ {
+ if (null === $onFulfilled) {
+ return;
+ }
+
+ $result = $onFulfilled($this->value);
+
+ if ($result instanceof ExtendedPromiseInterface) {
+ $result->done();
+ }
+ }
+
+ public function otherwise(callable $onRejected)
+ {
+ return $this;
+ }
+
+ public function always(callable $onFulfilledOrRejected)
+ {
+ return $this->then(function ($value) use ($onFulfilledOrRejected) {
+ return resolve($onFulfilledOrRejected())->then(function () use ($value) {
+ return $value;
+ });
+ });
+ }
+
+ public function progress(callable $onProgress)
+ {
+ return $this;
+ }
+
+ public function cancel()
+ {
+ }
+}
diff --git a/assets/php/vendor/react/promise/src/LazyPromise.php b/assets/php/vendor/react/promise/src/LazyPromise.php
new file mode 100644
index 0000000..7e3a3d3
--- /dev/null
+++ b/assets/php/vendor/react/promise/src/LazyPromise.php
@@ -0,0 +1,63 @@
+<?php
+
+namespace React\Promise;
+
+class LazyPromise implements ExtendedPromiseInterface, CancellablePromiseInterface
+{
+ private $factory;
+ private $promise;
+
+ public function __construct(callable $factory)
+ {
+ $this->factory = $factory;
+ }
+
+ public function then(callable $onFulfilled = null, callable $onRejected = null, callable $onProgress = null)
+ {
+ return $this->promise()->then($onFulfilled, $onRejected, $onProgress);
+ }
+
+ public function done(callable $onFulfilled = null, callable $onRejected = null, callable $onProgress = null)
+ {
+ return $this->promise()->done($onFulfilled, $onRejected, $onProgress);
+ }
+
+ public function otherwise(callable $onRejected)
+ {
+ return $this->promise()->otherwise($onRejected);
+ }
+
+ public function always(callable $onFulfilledOrRejected)
+ {
+ return $this->promise()->always($onFulfilledOrRejected);
+ }
+
+ public function progress(callable $onProgress)
+ {
+ return $this->promise()->progress($onProgress);
+ }
+
+ public function cancel()
+ {
+ return $this->promise()->cancel();
+ }
+
+ /**
+ * @internal
+ * @see Promise::settle()
+ */
+ public function promise()
+ {
+ if (null === $this->promise) {
+ try {
+ $this->promise = resolve(call_user_func($this->factory));
+ } catch (\Throwable $exception) {
+ $this->promise = new RejectedPromise($exception);
+ } catch (\Exception $exception) {
+ $this->promise = new RejectedPromise($exception);
+ }
+ }
+
+ return $this->promise;
+ }
+}
diff --git a/assets/php/vendor/react/promise/src/Promise.php b/assets/php/vendor/react/promise/src/Promise.php
new file mode 100644
index 0000000..0261eb3
--- /dev/null
+++ b/assets/php/vendor/react/promise/src/Promise.php
@@ -0,0 +1,216 @@
+<?php
+
+namespace React\Promise;
+
+class Promise implements ExtendedPromiseInterface, CancellablePromiseInterface
+{
+ private $canceller;
+ private $result;
+
+ private $handlers = [];
+ private $progressHandlers = [];
+
+ private $requiredCancelRequests = 0;
+ private $cancelRequests = 0;
+
+ public function __construct(callable $resolver, callable $canceller = null)
+ {
+ $this->canceller = $canceller;
+ $this->call($resolver);
+ }
+
+ public function then(callable $onFulfilled = null, callable $onRejected = null, callable $onProgress = null)
+ {
+ if (null !== $this->result) {
+ return $this->result->then($onFulfilled, $onRejected, $onProgress);
+ }
+
+ if (null === $this->canceller) {
+ return new static($this->resolver($onFulfilled, $onRejected, $onProgress));
+ }
+
+ $this->requiredCancelRequests++;
+
+ return new static($this->resolver($onFulfilled, $onRejected, $onProgress), function () {
+ if (++$this->cancelRequests < $this->requiredCancelRequests) {
+ return;
+ }
+
+ $this->cancel();
+ });
+ }
+
+ public function done(callable $onFulfilled = null, callable $onRejected = null, callable $onProgress = null)
+ {
+ if (null !== $this->result) {
+ return $this->result->done($onFulfilled, $onRejected, $onProgress);
+ }
+
+ $this->handlers[] = function (ExtendedPromiseInterface $promise) use ($onFulfilled, $onRejected) {
+ $promise
+ ->done($onFulfilled, $onRejected);
+ };
+
+ if ($onProgress) {
+ $this->progressHandlers[] = $onProgress;
+ }
+ }
+
+ public function otherwise(callable $onRejected)
+ {
+ return $this->then(null, function ($reason) use ($onRejected) {
+ if (!_checkTypehint($onRejected, $reason)) {
+ return new RejectedPromise($reason);
+ }
+
+ return $onRejected($reason);
+ });
+ }
+
+ public function always(callable $onFulfilledOrRejected)
+ {
+ return $this->then(function ($value) use ($onFulfilledOrRejected) {
+ return resolve($onFulfilledOrRejected())->then(function () use ($value) {
+ return $value;
+ });
+ }, function ($reason) use ($onFulfilledOrRejected) {
+ return resolve($onFulfilledOrRejected())->then(function () use ($reason) {
+ return new RejectedPromise($reason);
+ });
+ });
+ }
+
+ public function progress(callable $onProgress)
+ {
+ return $this->then(null, null, $onProgress);
+ }
+
+ public function cancel()
+ {
+ if (null === $this->canceller || null !== $this->result) {
+ return;
+ }
+
+ $canceller = $this->canceller;
+ $this->canceller = null;
+
+ $this->call($canceller);
+ }
+
+ private function resolver(callable $onFulfilled = null, callable $onRejected = null, callable $onProgress = null)
+ {
+ return function ($resolve, $reject, $notify) use ($onFulfilled, $onRejected, $onProgress) {
+ if ($onProgress) {
+ $progressHandler = function ($update) use ($notify, $onProgress) {
+ try {
+ $notify($onProgress($update));
+ } catch (\Throwable $e) {
+ $notify($e);
+ } catch (\Exception $e) {
+ $notify($e);
+ }
+ };
+ } else {
+ $progressHandler = $notify;
+ }
+
+ $this->handlers[] = function (ExtendedPromiseInterface $promise) use ($onFulfilled, $onRejected, $resolve, $reject, $progressHandler) {
+ $promise
+ ->then($onFulfilled, $onRejected)
+ ->done($resolve, $reject, $progressHandler);
+ };
+
+ $this->progressHandlers[] = $progressHandler;
+ };
+ }
+
+ private function resolve($value = null)
+ {
+ if (null !== $this->result) {
+ return;
+ }
+
+ $this->settle(resolve($value));
+ }
+
+ private function reject($reason = null)
+ {
+ if (null !== $this->result) {
+ return;
+ }
+
+ $this->settle(reject($reason));
+ }
+
+ private function notify($update = null)
+ {
+ if (null !== $this->result) {
+ return;
+ }
+
+ foreach ($this->progressHandlers as $handler) {
+ $handler($update);
+ }
+ }
+
+ private function settle(ExtendedPromiseInterface $promise)
+ {
+ $promise = $this->unwrap($promise);
+
+ $handlers = $this->handlers;
+
+ $this->progressHandlers = $this->handlers = [];
+ $this->result = $promise;
+
+ foreach ($handlers as $handler) {
+ $handler($promise);
+ }
+ }
+
+ private function unwrap($promise)
+ {
+ $promise = $this->extract($promise);
+
+ while ($promise instanceof self && null !== $promise->result) {
+ $promise = $this->extract($promise->result);
+ }
+
+ return $promise;
+ }
+
+ private function extract($promise)
+ {
+ if ($promise instanceof LazyPromise) {
+ $promise = $promise->promise();
+ }
+
+ if ($promise === $this) {
+ return new RejectedPromise(
+ new \LogicException('Cannot resolve a promise with itself.')
+ );
+ }
+
+ return $promise;
+ }
+
+ private function call(callable $callback)
+ {
+ try {
+ $callback(
+ function ($value = null) {
+ $this->resolve($value);
+ },
+ function ($reason = null) {
+ $this->reject($reason);
+ },
+ function ($update = null) {
+ $this->notify($update);
+ }
+ );
+ } catch (\Throwable $e) {
+ $this->reject($e);
+ } catch (\Exception $e) {
+ $this->reject($e);
+ }
+ }
+}
diff --git a/assets/php/vendor/react/promise/src/PromiseInterface.php b/assets/php/vendor/react/promise/src/PromiseInterface.php
new file mode 100644
index 0000000..d80d114
--- /dev/null
+++ b/assets/php/vendor/react/promise/src/PromiseInterface.php
@@ -0,0 +1,11 @@
+<?php
+
+namespace React\Promise;
+
+interface PromiseInterface
+{
+ /**
+ * @return PromiseInterface
+ */
+ public function then(callable $onFulfilled = null, callable $onRejected = null, callable $onProgress = null);
+}
diff --git a/assets/php/vendor/react/promise/src/PromisorInterface.php b/assets/php/vendor/react/promise/src/PromisorInterface.php
new file mode 100644
index 0000000..9341a4f
--- /dev/null
+++ b/assets/php/vendor/react/promise/src/PromisorInterface.php
@@ -0,0 +1,11 @@
+<?php
+
+namespace React\Promise;
+
+interface PromisorInterface
+{
+ /**
+ * @return PromiseInterface
+ */
+ public function promise();
+}
diff --git a/assets/php/vendor/react/promise/src/RejectedPromise.php b/assets/php/vendor/react/promise/src/RejectedPromise.php
new file mode 100644
index 0000000..479a746
--- /dev/null
+++ b/assets/php/vendor/react/promise/src/RejectedPromise.php
@@ -0,0 +1,76 @@
+<?php
+
+namespace React\Promise;
+
+class RejectedPromise implements ExtendedPromiseInterface, CancellablePromiseInterface
+{
+ private $reason;
+
+ public function __construct($reason = null)
+ {
+ if ($reason instanceof PromiseInterface) {
+ throw new \InvalidArgumentException('You cannot create React\Promise\RejectedPromise with a promise. Use React\Promise\reject($promiseOrValue) instead.');
+ }
+
+ $this->reason = $reason;
+ }
+
+ public function then(callable $onFulfilled = null, callable $onRejected = null, callable $onProgress = null)
+ {
+ if (null === $onRejected) {
+ return $this;
+ }
+
+ try {
+ return resolve($onRejected($this->reason));
+ } catch (\Throwable $exception) {
+ return new RejectedPromise($exception);
+ } catch (\Exception $exception) {
+ return new RejectedPromise($exception);
+ }
+ }
+
+ public function done(callable $onFulfilled = null, callable $onRejected = null, callable $onProgress = null)
+ {
+ if (null === $onRejected) {
+ throw UnhandledRejectionException::resolve($this->reason);
+ }
+
+ $result = $onRejected($this->reason);
+
+ if ($result instanceof self) {
+ throw UnhandledRejectionException::resolve($result->reason);
+ }
+
+ if ($result instanceof ExtendedPromiseInterface) {
+ $result->done();
+ }
+ }
+
+ public function otherwise(callable $onRejected)
+ {
+ if (!_checkTypehint($onRejected, $this->reason)) {
+ return $this;
+ }
+
+ return $this->then(null, $onRejected);
+ }
+
+ public function always(callable $onFulfilledOrRejected)
+ {
+ return $this->then(null, function ($reason) use ($onFulfilledOrRejected) {
+ return resolve($onFulfilledOrRejected())->then(function () use ($reason) {
+ return new RejectedPromise($reason);
+ });
+ });
+ }
+
+ public function progress(callable $onProgress)
+ {
+ return $this;
+ }
+
+ public function cancel()
+ {
+ }
+}
diff --git a/assets/php/vendor/react/promise/src/UnhandledRejectionException.php b/assets/php/vendor/react/promise/src/UnhandledRejectionException.php
new file mode 100644
index 0000000..a44b7a1
--- /dev/null
+++ b/assets/php/vendor/react/promise/src/UnhandledRejectionException.php
@@ -0,0 +1,31 @@
+<?php
+
+namespace React\Promise;
+
+class UnhandledRejectionException extends \RuntimeException
+{
+ private $reason;
+
+ public static function resolve($reason)
+ {
+ if ($reason instanceof \Exception || $reason instanceof \Throwable) {
+ return $reason;
+ }
+
+ return new static($reason);
+ }
+
+ public function __construct($reason)
+ {
+ $this->reason = $reason;
+
+ $message = sprintf('Unhandled Rejection: %s', json_encode($reason));
+
+ parent::__construct($message, 0);
+ }
+
+ public function getReason()
+ {
+ return $this->reason;
+ }
+}
diff --git a/assets/php/vendor/react/promise/src/functions.php b/assets/php/vendor/react/promise/src/functions.php
new file mode 100644
index 0000000..70c0eb7
--- /dev/null
+++ b/assets/php/vendor/react/promise/src/functions.php
@@ -0,0 +1,244 @@
+<?php
+
+namespace React\Promise;
+
+function resolve($promiseOrValue = null)
+{
+ if ($promiseOrValue instanceof ExtendedPromiseInterface) {
+ return $promiseOrValue;
+ }
+
+ if (method_exists($promiseOrValue, 'then')) {
+ $canceller = null;
+
+ if (method_exists($promiseOrValue, 'cancel')) {
+ $canceller = [$promiseOrValue, 'cancel'];
+ }
+
+ return new Promise(function ($resolve, $reject, $notify) use ($promiseOrValue) {
+ $promiseOrValue->then($resolve, $reject, $notify);
+ }, $canceller);
+ }
+
+ return new FulfilledPromise($promiseOrValue);
+}
+
+function reject($promiseOrValue = null)
+{
+ if ($promiseOrValue instanceof PromiseInterface) {
+ return resolve($promiseOrValue)->then(function ($value) {
+ return new RejectedPromise($value);
+ });
+ }
+
+ return new RejectedPromise($promiseOrValue);
+}
+
+function all($promisesOrValues)
+{
+ return map($promisesOrValues, function ($val) {
+ return $val;
+ });
+}
+
+function race($promisesOrValues)
+{
+ $cancellationQueue = new CancellationQueue();
+ $cancellationQueue->enqueue($promisesOrValues);
+
+ return new Promise(function ($resolve, $reject, $notify) use ($promisesOrValues, $cancellationQueue) {
+ resolve($promisesOrValues)
+ ->done(function ($array) use ($cancellationQueue, $resolve, $reject, $notify) {
+ if (!is_array($array) || !$array) {
+ $resolve();
+ return;
+ }
+
+ foreach ($array as $promiseOrValue) {
+ $cancellationQueue->enqueue($promiseOrValue);
+
+ resolve($promiseOrValue)
+ ->done($resolve, $reject, $notify);
+ }
+ }, $reject, $notify);
+ }, $cancellationQueue);
+}
+
+function any($promisesOrValues)
+{
+ return some($promisesOrValues, 1)
+ ->then(function ($val) {
+ return array_shift($val);
+ });
+}
+
+function some($promisesOrValues, $howMany)
+{
+ $cancellationQueue = new CancellationQueue();
+ $cancellationQueue->enqueue($promisesOrValues);
+
+ return new Promise(function ($resolve, $reject, $notify) use ($promisesOrValues, $howMany, $cancellationQueue) {
+ resolve($promisesOrValues)
+ ->done(function ($array) use ($howMany, $cancellationQueue, $resolve, $reject, $notify) {
+ if (!is_array($array) || $howMany < 1) {
+ $resolve([]);
+ return;
+ }
+
+ $len = count($array);
+
+ if ($len < $howMany) {
+ throw new Exception\LengthException(
+ sprintf(
+ 'Input array must contain at least %d item%s but contains only %s item%s.',
+ $howMany,
+ 1 === $howMany ? '' : 's',
+ $len,
+ 1 === $len ? '' : 's'
+ )
+ );
+ }
+
+ $toResolve = $howMany;
+ $toReject = ($len - $toResolve) + 1;
+ $values = [];
+ $reasons = [];
+
+ foreach ($array as $i => $promiseOrValue) {
+ $fulfiller = function ($val) use ($i, &$values, &$toResolve, $toReject, $resolve) {
+ if ($toResolve < 1 || $toReject < 1) {
+ return;
+ }
+
+ $values[$i] = $val;
+
+ if (0 === --$toResolve) {
+ $resolve($values);
+ }
+ };
+
+ $rejecter = function ($reason) use ($i, &$reasons, &$toReject, $toResolve, $reject) {
+ if ($toResolve < 1 || $toReject < 1) {
+ return;
+ }
+
+ $reasons[$i] = $reason;
+
+ if (0 === --$toReject) {
+ $reject($reasons);
+ }
+ };
+
+ $cancellationQueue->enqueue($promiseOrValue);
+
+ resolve($promiseOrValue)
+ ->done($fulfiller, $rejecter, $notify);
+ }
+ }, $reject, $notify);
+ }, $cancellationQueue);
+}
+
+function map($promisesOrValues, callable $mapFunc)
+{
+ $cancellationQueue = new CancellationQueue();
+ $cancellationQueue->enqueue($promisesOrValues);
+
+ return new Promise(function ($resolve, $reject, $notify) use ($promisesOrValues, $mapFunc, $cancellationQueue) {
+ resolve($promisesOrValues)
+ ->done(function ($array) use ($mapFunc, $cancellationQueue, $resolve, $reject, $notify) {
+ if (!is_array($array) || !$array) {
+ $resolve([]);
+ return;
+ }
+
+ $toResolve = count($array);
+ $values = [];
+
+ foreach ($array as $i => $promiseOrValue) {
+ $cancellationQueue->enqueue($promiseOrValue);
+ $values[$i] = null;
+
+ resolve($promiseOrValue)
+ ->then($mapFunc)
+ ->done(
+ function ($mapped) use ($i, &$values, &$toResolve, $resolve) {
+ $values[$i] = $mapped;
+
+ if (0 === --$toResolve) {
+ $resolve($values);
+ }
+ },
+ $reject,
+ $notify
+ );
+ }
+ }, $reject, $notify);
+ }, $cancellationQueue);
+}
+
+function reduce($promisesOrValues, callable $reduceFunc, $initialValue = null)
+{
+ $cancellationQueue = new CancellationQueue();
+ $cancellationQueue->enqueue($promisesOrValues);
+
+ return new Promise(function ($resolve, $reject, $notify) use ($promisesOrValues, $reduceFunc, $initialValue, $cancellationQueue) {
+ resolve($promisesOrValues)
+ ->done(function ($array) use ($reduceFunc, $initialValue, $cancellationQueue, $resolve, $reject, $notify) {
+ if (!is_array($array)) {
+ $array = [];
+ }
+
+ $total = count($array);
+ $i = 0;
+
+ // Wrap the supplied $reduceFunc with one that handles promises and then
+ // delegates to the supplied.
+ $wrappedReduceFunc = function ($current, $val) use ($reduceFunc, $cancellationQueue, $total, &$i) {
+ $cancellationQueue->enqueue($val);
+
+ return $current
+ ->then(function ($c) use ($reduceFunc, $total, &$i, $val) {
+ return resolve($val)
+ ->then(function ($value) use ($reduceFunc, $total, &$i, $c) {
+ return $reduceFunc($c, $value, $i++, $total);
+ });
+ });
+ };
+
+ $cancellationQueue->enqueue($initialValue);
+
+ array_reduce($array, $wrappedReduceFunc, resolve($initialValue))
+ ->done($resolve, $reject, $notify);
+ }, $reject, $notify);
+ }, $cancellationQueue);
+}
+
+// Internal functions
+function _checkTypehint(callable $callback, $object)
+{
+ if (!is_object($object)) {
+ return true;
+ }
+
+ if (is_array($callback)) {
+ $callbackReflection = new \ReflectionMethod($callback[0], $callback[1]);
+ } elseif (is_object($callback) && !$callback instanceof \Closure) {
+ $callbackReflection = new \ReflectionMethod($callback, '__invoke');
+ } else {
+ $callbackReflection = new \ReflectionFunction($callback);
+ }
+
+ $parameters = $callbackReflection->getParameters();
+
+ if (!isset($parameters[0])) {
+ return true;
+ }
+
+ $expectedException = $parameters[0];
+
+ if (!$expectedException->getClass()) {
+ return true;
+ }
+
+ return $expectedException->getClass()->isInstance($object);
+}
diff --git a/assets/php/vendor/react/promise/src/functions_include.php b/assets/php/vendor/react/promise/src/functions_include.php
new file mode 100644
index 0000000..c71decb
--- /dev/null
+++ b/assets/php/vendor/react/promise/src/functions_include.php
@@ -0,0 +1,5 @@
+<?php
+
+if (!function_exists('React\Promise\resolve')) {
+ require __DIR__.'/functions.php';
+}