diff options
Diffstat (limited to 'vendor/sabre/event')
21 files changed, 282 insertions, 644 deletions
diff --git a/vendor/sabre/event/.gitattributes b/vendor/sabre/event/.gitattributes deleted file mode 100644 index 0fdd4b01c..000000000 --- a/vendor/sabre/event/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -/examples export-ignore -/tests export-ignore diff --git a/vendor/sabre/event/.gitignore b/vendor/sabre/event/.gitignore deleted file mode 100644 index d06a78164..000000000 --- a/vendor/sabre/event/.gitignore +++ /dev/null @@ -1,14 +0,0 @@ -#composer -vendor -composer.lock - -#binaries -bin/sabre-cs-fixer -bin/php-cs-fixer -bin/phpunit - -#vim lock files -.*.swp - -#development stuff -tests/cov diff --git a/vendor/sabre/event/.travis.yml b/vendor/sabre/event/.travis.yml deleted file mode 100644 index 020488b79..000000000 --- a/vendor/sabre/event/.travis.yml +++ /dev/null @@ -1,21 +0,0 @@ -language: php -php: - - 7.0 - - 7.1 - - 7.2 - -env: - matrix: - - LOWEST_DEPS="" - - LOWEST_DEPS="--prefer-lowest" - -before_script: - - composer update --prefer-source $LOWEST_DEPS - -script: - - ./bin/phpunit - - ./bin/sabre-cs-fixer fix . --dry-run --diff - -sudo: false - -cache: vendor diff --git a/vendor/sabre/event/CHANGELOG.md b/vendor/sabre/event/CHANGELOG.md deleted file mode 100644 index 5b1fb2e68..000000000 --- a/vendor/sabre/event/CHANGELOG.md +++ /dev/null @@ -1,122 +0,0 @@ -ChangeLog -========= -5.0.3 (2018-05-03) ------------------- - -* Dropped remaining hhvm leftovers. -* #55: Fixed typo in WildcardEmitterTrait (@SamMousa) -* #54: export-ignore examples & tests in distribution (@staabm) - -5.0.2 (2017-04-29) ------------------- - -* #50: Fixed Promise\all to resolve immediately for empty arrays (@MadHed) -* #48, #49: Performance optimisations for EmitterTrait and WildcardEmitterTrait (@lunixyacht). - -5.0.1 (2016-10-29) ------------------- - -* #45: Fixed `Emitter` class to use the correct interface. (@felixfbecker). - - -5.0.0 (2016-10-23) ------------------- - -* #42: The `coroutine` function now supports `return` in the passed generator - function. This allows you to more generally return a value. This is a BC - break as this is a feature that was only made possible with PHP 7, and - before the coroutine function would only ever return the last thing that - was yielded. If you depended on that feature, replace your last `yield` with - a `return`. - - -4.0.0 (2016-09-19) ------------------- - -* sabre/event now requires PHP 7. If you need PHP 5.5 support, just keep - using 3.0.0. -* PHP 7 type hints are now used everywhere. We're also using strict_types. -* Support for a new `WildcardEmitter` which allows you to listen for events - using the `*` wildcard. -* Removed deprecated functions `Promise::error` and `Promise::all`. Instead, - use `Promise::otherwise` and `Promise\all()`. -* `EventEmitter`, `EventEmitterTrait` and `EventEmitterInterface` are now just - called `Emitter`, `EmitterTrait`, and `EmitterInterface`. -* When rejecting Promises, it's now _required_ to use an `Exception` or - `Throwable`. This makes the typical case simpler and reduces special cases. - -3.0.0 (2015-11-05) ------------------- - -* Now requires PHP 5.5! -* `Promise::all()` is moved to `Promise\all()`. -* Aside from the `Promise\all()` function, there's now also `Promise\race()`. -* `Promise\reject()` and `Promise\resolve()` have also been added. -* Now 100% compatible with the Ecmascript 6 Promise. - - -3.0.0-alpha1 (2015-10-23) -------------------------- - -* This package now requires PHP 5.5. -* #26: Added an event loop implementation. Also knows as the Reactor Pattern. -* Renamed `Promise::error` to `Promise::otherwise` to be consistent with - ReactPHP and Guzzle. The `error` method is kept for BC but will be removed - in a future version. -* #27: Support for Promise-based coroutines via the `Sabre\Event\coroutine` - function. -* BC Break: Promises now use the EventLoop to run "then"-events in a separate - execution context. In practise that means you need to run the event loop to - wait for any `then`/`otherwise` callbacks to trigger. -* Promises now have a `wait()` method. Allowing you to make a promise - synchronous and simply wait for a result (or exception) to happen. - - -2.0.2 (2015-05-19) ------------------- - -* This release has no functional changes. It's just been brought up to date - with the latest coding standards. - - -2.0.1 (2014-10-06) ------------------- - -* Fixed: `$priority` was ignored in `EventEmitter::once` method. -* Fixed: Breaking the event chain was not possible in `EventEmitter::once`. - - -2.0.0 (2014-06-21) ------------------- - -* Added: When calling emit, it's now possible to specify a callback that will be - triggered after each method handled. This is dubbed the 'continueCallback' and - can be used to implement strategy patterns. -* Added: Promise object! -* Changed: EventEmitter::listeners now returns just the callbacks for an event, - and no longer returns the list by reference. The list is now automatically - sorted by priority. -* Update: Speed improvements. -* Updated: It's now possible to remove all listeners for every event. -* Changed: Now uses psr-4 autoloading. - - -1.0.1 (2014-06-12) ------------------- - -* hhvm compatible! -* Fixed: Issue #4. Compatiblitiy for PHP < 5.4.14. - - -1.0.0 (2013-07-19) ------------------- - -* Added: removeListener, removeAllListeners -* Added: once, to only listen to an event emitting once. -* Added README.md. - - -0.0.1-alpha (2013-06-29) ------------------------- - -* First version! diff --git a/vendor/sabre/event/README.md b/vendor/sabre/event/README.md deleted file mode 100644 index 9e2bdd042..000000000 --- a/vendor/sabre/event/README.md +++ /dev/null @@ -1,51 +0,0 @@ -sabre/event -=========== - -A lightweight library for event-based development in PHP. - -This library provides the following event-based concepts: - -1. EventEmitter. -2. Promises. -3. An event loop. -4. Co-routines. - -Full documentation can be found on [the website][1]. - -Installation ------------- - -Make sure you have [composer][3] installed, and then run: - - composer require sabre/event "^3.0" - -This package requires PHP 5.5. The 2.0 branch is still maintained as well, and -supports PHP 5.4. - -Build status ------------- - -| branch | status | -| ------ | ------ | -| master | [![Build Status](https://travis-ci.org/sabre-io/event.svg?branch=master)](https://travis-ci.org/sabre-io/event) | -| 3.0 | [![Build Status](https://travis-ci.org/sabre-io/event.svg?branch=2.0)](https://travis-ci.org/sabre-io/event) | -| 2.0 | [![Build Status](https://travis-ci.org/sabre-io/event.svg?branch=2.0)](https://travis-ci.org/sabre-io/event) | -| 1.0 | [![Build Status](https://travis-ci.org/sabre-io/event.svg?branch=1.0)](https://travis-ci.org/sabre-io/event) | -| php53 | [![Build Status](https://travis-ci.org/sabre-io/event.svg?branch=php53)](https://travis-ci.org/sabre-io/event) | - - -Questions? ----------- - -Head over to the [sabre/dav mailinglist][4], or you can also just open a ticket -on [GitHub][5]. - -Made at fruux -------------- - -This library is being developed by [fruux](https://fruux.com/). Drop us a line for commercial services or enterprise support. - -[1]: http://sabre.io/event/ -[3]: http://getcomposer.org/ -[4]: http://groups.google.com/group/sabredav-discuss -[5]: https://github.com/fruux/sabre-event/issues/ diff --git a/vendor/sabre/event/_config.yml b/vendor/sabre/event/_config.yml deleted file mode 100644 index c4192631f..000000000 --- a/vendor/sabre/event/_config.yml +++ /dev/null @@ -1 +0,0 @@ -theme: jekyll-theme-cayman
\ No newline at end of file diff --git a/vendor/sabre/event/composer.json b/vendor/sabre/event/composer.json index d7a13c5ca..144704118 100644 --- a/vendor/sabre/event/composer.json +++ b/vendor/sabre/event/composer.json @@ -16,7 +16,7 @@ "homepage": "http://sabre.io/event/", "license": "BSD-3-Clause", "require": { - "php": ">=7.0" + "php": "^7.1" }, "authors": [ { @@ -41,8 +41,8 @@ ] }, "require-dev": { - "sabre/cs": "~1.0.0", - "phpunit/phpunit" : ">=6" + "friendsofphp/php-cs-fixer": "~2.16.1", + "phpunit/phpunit" : "^7 || ^8" }, "config" : { "bin-dir" : "bin/" 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 @@ -<?php declare (strict_types=1); +<?php + +declare(strict_types=1); namespace Sabre\Event; @@ -11,8 +13,7 @@ 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 a7e4b6132..6ce0f34db 100644 --- a/vendor/sabre/event/lib/EmitterInterface.php +++ b/vendor/sabre/event/lib/EmitterInterface.php @@ -1,9 +1,11 @@ -<?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. @@ -12,26 +14,22 @@ 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 */ - function on(string $eventName, callable $callBack, int $priority = 100); + public function on(string $eventName, callable $callBack, int $priority = 100); /** * 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); /** * 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 @@ -49,7 +47,7 @@ interface EmitterInterface { * 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; /** * Returns the list of listeners for an event. @@ -59,7 +57,7 @@ interface EmitterInterface { * * @return callable[] */ - function listeners(string $eventName) : array; + public function listeners(string $eventName): array; /** * Removes a specific listener from an event. @@ -67,7 +65,7 @@ interface EmitterInterface { * 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; /** * Removes all listeners. @@ -75,9 +73,6 @@ 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 */ - function removeAllListeners(string $eventName = null); - + public function removeAllListeners(string $eventName = null); } diff --git a/vendor/sabre/event/lib/EmitterTrait.php b/vendor/sabre/event/lib/EmitterTrait.php index dafae362f..5502ef9f3 100644 --- a/vendor/sabre/event/lib/EmitterTrait.php +++ b/vendor/sabre/event/lib/EmitterTrait.php @@ -1,9 +1,11 @@ -<?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. @@ -15,53 +17,45 @@ 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 */ - function on(string $eventName, callable $callBack, int $priority = 100) { - + public 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 */ - 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 @@ -<?php declare (strict_types=1); +<?php + +declare(strict_types=1); namespace Sabre\Event; @@ -12,8 +14,7 @@ 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 301fe8920..ec09be921 100644 --- a/vendor/sabre/event/lib/Loop/Loop.php +++ b/vendor/sabre/event/lib/Loop/Loop.php @@ -1,4 +1,6 @@ -<?php declare (strict_types=1); +<?php + +declare(strict_types=1); namespace Sabre\Event\Loop; @@ -15,20 +17,19 @@ 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 */ - function setTimeout(callable $cb, float $timeout) { - + public 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; } @@ -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 @@ -<?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); - } /** @@ -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 @@ -<?php declare (strict_types=1); +<?php + +declare(strict_types=1); namespace Sabre\Event; @@ -21,8 +23,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. */ @@ -54,15 +56,14 @@ class Promise { * Each are callbacks that map to $this->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 @@ -<?php declare (strict_types=1); +<?php + +declare(strict_types=1); namespace Sabre\Event\Promise; @@ -14,7 +16,6 @@ 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. @@ -24,17 +25,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 immidiately + * If any of the given Promises fails, the returned promise will immediately * 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; } @@ -42,25 +43,23 @@ 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); } ); - } }); - } /** @@ -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 @@ -<?php declare (strict_types=1); +<?php + +declare(strict_types=1); namespace Sabre\Event; @@ -10,6 +12,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 9aee4b3ab..e98e2e3ff 100644 --- a/vendor/sabre/event/lib/Version.php +++ b/vendor/sabre/event/lib/Version.php @@ -1,4 +1,6 @@ -<?php declare (strict_types=1); +<?php + +declare(strict_types=1); namespace Sabre\Event; @@ -9,11 +11,10 @@ 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.0.3'; - + const VERSION = '5.1.0'; } diff --git a/vendor/sabre/event/lib/WildcardEmitter.php b/vendor/sabre/event/lib/WildcardEmitter.php index 2ef15fe83..1b7c248b2 100644 --- a/vendor/sabre/event/lib/WildcardEmitter.php +++ b/vendor/sabre/event/lib/WildcardEmitter.php @@ -1,4 +1,6 @@ -<?php declare (strict_types=1); +<?php + +declare(strict_types=1); namespace Sabre\Event; @@ -14,7 +16,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 @@ -28,10 +30,7 @@ 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 7d8d62c26..206a8f3c5 100644 --- a/vendor/sabre/event/lib/WildcardEmitterTrait.php +++ b/vendor/sabre/event/lib/WildcardEmitterTrait.php @@ -1,9 +1,11 @@ -<?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 @@ -17,21 +19,19 @@ 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 */ - 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] === '*') { + 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]) { $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,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 @@ -<?php declare (strict_types=1); +<?php + +declare(strict_types=1); namespace Sabre\Event; @@ -41,12 +43,13 @@ 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'); @@ -59,22 +62,20 @@ 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, &$lastYieldResult) { - + $advanceGenerator = function () use (&$advanceGenerator, $generator, $promise) { while ($generator->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; - } diff --git a/vendor/sabre/event/phpunit.xml.dist b/vendor/sabre/event/phpunit.xml.dist deleted file mode 100644 index ccd59be9c..000000000 --- a/vendor/sabre/event/phpunit.xml.dist +++ /dev/null @@ -1,18 +0,0 @@ -<phpunit - colors="true" - bootstrap="vendor/autoload.php" - convertErrorsToExceptions="true" - convertNoticesToExceptions="true" - convertWarningsToExceptions="true" - strict="true" - > - <testsuite name="sabre-event"> - <directory>tests/</directory> - </testsuite> - - <filter> - <whitelist addUncoveredFilesFromWhitelist="true"> - <directory suffix=".php">./lib/</directory> - </whitelist> - </filter> -</phpunit> |