diff options
author | marvin-borner@live.com | 2018-04-10 21:50:16 +0200 |
---|---|---|
committer | marvin-borner@live.com | 2018-04-10 21:54:48 +0200 |
commit | fc9401f04a3aca5abb22f87ebc210de8afe11d32 (patch) | |
tree | b0b310f3581764ec3955f4e496a05137a32951c3 /assets/php/vendor/react/cache | |
parent | 286d643180672f20526f3dc3bd19d7b751e2fa97 (diff) |
Initial Commit
Diffstat (limited to 'assets/php/vendor/react/cache')
-rw-r--r-- | assets/php/vendor/react/cache/.gitignore | 2 | ||||
-rw-r--r-- | assets/php/vendor/react/cache/.travis.yml | 25 | ||||
-rw-r--r-- | assets/php/vendor/react/cache/CHANGELOG.md | 35 | ||||
-rw-r--r-- | assets/php/vendor/react/cache/LICENSE | 19 | ||||
-rw-r--r-- | assets/php/vendor/react/cache/README.md | 171 | ||||
-rw-r--r-- | assets/php/vendor/react/cache/composer.json | 19 | ||||
-rw-r--r-- | assets/php/vendor/react/cache/phpunit.xml.dist | 20 | ||||
-rw-r--r-- | assets/php/vendor/react/cache/src/ArrayCache.php | 29 | ||||
-rw-r--r-- | assets/php/vendor/react/cache/src/CacheInterface.php | 13 | ||||
-rw-r--r-- | assets/php/vendor/react/cache/tests/ArrayCacheTest.php | 60 | ||||
-rw-r--r-- | assets/php/vendor/react/cache/tests/CallableStub.php | 10 | ||||
-rw-r--r-- | assets/php/vendor/react/cache/tests/TestCase.php | 43 |
12 files changed, 446 insertions, 0 deletions
diff --git a/assets/php/vendor/react/cache/.gitignore b/assets/php/vendor/react/cache/.gitignore new file mode 100644 index 0000000..987e2a2 --- /dev/null +++ b/assets/php/vendor/react/cache/.gitignore @@ -0,0 +1,2 @@ +composer.lock +vendor diff --git a/assets/php/vendor/react/cache/.travis.yml b/assets/php/vendor/react/cache/.travis.yml new file mode 100644 index 0000000..290df75 --- /dev/null +++ b/assets/php/vendor/react/cache/.travis.yml @@ -0,0 +1,25 @@ +language: php + +php: +# - 5.3 # requires old distro, see below + - 5.4 + - 5.5 + - 5.6 + - 7 + - hhvm + +# lock distro so new future defaults will not break the build +dist: trusty + +matrix: + include: + - php: 5.3 + dist: precise + +sudo: false + +install: + - composer install --no-interaction + +script: + - ./vendor/bin/phpunit --coverage-text diff --git a/assets/php/vendor/react/cache/CHANGELOG.md b/assets/php/vendor/react/cache/CHANGELOG.md new file mode 100644 index 0000000..19d1801 --- /dev/null +++ b/assets/php/vendor/react/cache/CHANGELOG.md @@ -0,0 +1,35 @@ +# Changelog + +## 0.4.2 (2017-12-20) + +* Improve documentation with usage and installation instructions + (#10 by @clue) + +* Improve test suite by adding PHPUnit to `require-dev` and + add forward compatibility with PHPUnit 5 and PHPUnit 6 and + sanitize Composer autoload paths + (#14 by @shaunbramley and #12 and #18 by @clue) + +## 0.4.1 (2016-02-25) + +* Repository maintenance, split off from main repo, improve test suite and documentation +* First class support for PHP7 and HHVM (#9 by @clue) +* Adjust compatibility to 5.3 (#7 by @clue) + +## 0.4.0 (2014-02-02) + +* BC break: Bump minimum PHP version to PHP 5.4, remove 5.3 specific hacks +* BC break: Update to React/Promise 2.0 +* Dependency: Autoloading and filesystem structure now PSR-4 instead of PSR-0 + +## 0.3.2 (2013-05-10) + +* Version bump + +## 0.3.0 (2013-04-14) + +* Version bump + +## 0.2.6 (2012-12-26) + +* Feature: New cache component, used by DNS diff --git a/assets/php/vendor/react/cache/LICENSE b/assets/php/vendor/react/cache/LICENSE new file mode 100644 index 0000000..a808108 --- /dev/null +++ b/assets/php/vendor/react/cache/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2012 Igor Wiedler, Chris Boden + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/assets/php/vendor/react/cache/README.md b/assets/php/vendor/react/cache/README.md new file mode 100644 index 0000000..70ad40a --- /dev/null +++ b/assets/php/vendor/react/cache/README.md @@ -0,0 +1,171 @@ +# Cache Component + +[](http://travis-ci.org/reactphp/cache) [](https://codeclimate.com/github/reactphp/cache) + +Async, [Promise](https://github.com/reactphp/promise)-based cache interface +for [ReactPHP](https://reactphp.org/). + +The cache component provides a +[Promise](https://github.com/reactphp/promise)-based +[`CacheInterface`](#cacheinterface) and an in-memory [`ArrayCache`](#arraycache) +implementation of that. +This allows consumers to type hint against the interface and third parties to +provide alternate implementations. + +**Table of Contents** + +* [Usage](#usage) + * [CacheInterface](#cacheinterface) + * [get()](#get) + * [set()](#set) + * [remove()](#remove) + * [ArrayCache](#arraycache) +* [Common usage](#common-usage) + * [Fallback get](#fallback-get) + * [Fallback-get-and-set](#fallback-get-and-set) +* [Install](#install) +* [Tests](#tests) +* [License](#license) + +## Usage + +### CacheInterface + +The `CacheInterface` describes the main interface of this component. +This allows consumers to type hint against the interface and third parties to +provide alternate implementations. + +#### get() + +```php +$cache + ->get('foo') + ->then('var_dump'); +``` + +This example fetches the value of the key `foo` and passes it to the +`var_dump` function. You can use any of the composition provided by +[promises](https://github.com/reactphp/promise). + +If the key `foo` does not exist, the promise will be rejected. + +#### set() + +```php +$cache->set('foo', 'bar'); +``` + +This example eventually sets the value of the key `foo` to `bar`. If it +already exists, it is overridden. No guarantees are made as to when the cache +value is set. If the cache implementation has to go over the network to store +it, it may take a while. + +#### remove() + +```php +$cache->remove('foo'); +``` + +This example eventually removes the key `foo` from the cache. As with `set`, +this may not happen instantly. + +### ArrayCache + +The `ArrayCache` provides an in-memory implementation of the +[`CacheInterface`](#cacheinterface). + +```php +$cache = new ArrayCache(); + +$cache->set('foo', 'bar'); +``` + +## Common usage + +### Fallback get + +A common use case of caches is to attempt fetching a cached value and as a +fallback retrieve it from the original data source if not found. Here is an +example of that: + +```php +$cache + ->get('foo') + ->then(null, 'getFooFromDb') + ->then('var_dump'); +``` + +First an attempt is made to retrieve the value of `foo`. A promise rejection +handler of the function `getFooFromDb` is registered. `getFooFromDb` is a +function (can be any PHP callable) that will be called if the key does not +exist in the cache. + +`getFooFromDb` can handle the missing key by returning a promise for the +actual value from the database (or any other data source). As a result, this +chain will correctly fall back, and provide the value in both cases. + +### Fallback get and set + +To expand on the fallback get example, often you want to set the value on the +cache after fetching it from the data source. + +```php +$cache + ->get('foo') + ->then(null, array($this, 'getAndCacheFooFromDb')) + ->then('var_dump'); + +public function getAndCacheFooFromDb() +{ + return $this->db + ->get('foo') + ->then(array($this, 'cacheFooFromDb')); +} + +public function cacheFooFromDb($foo) +{ + $this->cache->set('foo', $foo); + + return $foo; +} +``` + +By using chaining you can easily conditionally cache the value if it is +fetched from the database. + +## Install + +The recommended way to install this library is [through Composer](https://getcomposer.org). +[New to Composer?](https://getcomposer.org/doc/00-intro.md) + +This will install the latest supported version: + +```bash +$ composer require react/cache:^0.4.2 +``` + +See also the [CHANGELOG](CHANGELOG.md) for details about version upgrades. + +This project aims to run on any platform and thus does not require any PHP +extensions and supports running on legacy PHP 5.3 through current PHP 7+ and +HHVM. +It's *highly recommended to use PHP 7+* for this project. + +## Tests + +To run the test suite, you first need to clone this repo and then install all +dependencies [through Composer](https://getcomposer.org): + +```bash +$ composer install +``` + +To run the test suite, go to the project root and run: + +```bash +$ php vendor/bin/phpunit +``` + +## License + +MIT, see [LICENSE file](LICENSE). diff --git a/assets/php/vendor/react/cache/composer.json b/assets/php/vendor/react/cache/composer.json new file mode 100644 index 0000000..51573b6 --- /dev/null +++ b/assets/php/vendor/react/cache/composer.json @@ -0,0 +1,19 @@ +{ + "name": "react/cache", + "description": "Async, Promise-based cache interface for ReactPHP", + "keywords": ["cache", "caching", "promise", "ReactPHP"], + "license": "MIT", + "require": { + "php": ">=5.3.0", + "react/promise": "~2.0|~1.1" + }, + "autoload": { + "psr-4": { "React\\Cache\\": "src/" } + }, + "autoload-dev": { + "psr-4": { "React\\Tests\\Cache\\": "tests/" } + }, + "require-dev": { + "phpunit/phpunit": "^6.4 || ^5.7 || ^4.8.35" + } +} diff --git a/assets/php/vendor/react/cache/phpunit.xml.dist b/assets/php/vendor/react/cache/phpunit.xml.dist new file mode 100644 index 0000000..d02182f --- /dev/null +++ b/assets/php/vendor/react/cache/phpunit.xml.dist @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<phpunit colors="true" + convertErrorsToExceptions="true" + convertNoticesToExceptions="true" + convertWarningsToExceptions="true" + bootstrap="vendor/autoload.php" +> + <testsuites> + <testsuite name="React Test Suite"> + <directory>./tests/</directory> + </testsuite> + </testsuites> + + <filter> + <whitelist> + <directory>./src/</directory> + </whitelist> + </filter> +</phpunit> diff --git a/assets/php/vendor/react/cache/src/ArrayCache.php b/assets/php/vendor/react/cache/src/ArrayCache.php new file mode 100644 index 0000000..03dcc15 --- /dev/null +++ b/assets/php/vendor/react/cache/src/ArrayCache.php @@ -0,0 +1,29 @@ +<?php + +namespace React\Cache; + +use React\Promise; + +class ArrayCache implements CacheInterface +{ + private $data = array(); + + public function get($key) + { + if (!isset($this->data[$key])) { + return Promise\reject(); + } + + return Promise\resolve($this->data[$key]); + } + + public function set($key, $value) + { + $this->data[$key] = $value; + } + + public function remove($key) + { + unset($this->data[$key]); + } +} diff --git a/assets/php/vendor/react/cache/src/CacheInterface.php b/assets/php/vendor/react/cache/src/CacheInterface.php new file mode 100644 index 0000000..fd5f2d5 --- /dev/null +++ b/assets/php/vendor/react/cache/src/CacheInterface.php @@ -0,0 +1,13 @@ +<?php + +namespace React\Cache; + +interface CacheInterface +{ + // @return React\Promise\PromiseInterface + public function get($key); + + public function set($key, $value); + + public function remove($key); +} diff --git a/assets/php/vendor/react/cache/tests/ArrayCacheTest.php b/assets/php/vendor/react/cache/tests/ArrayCacheTest.php new file mode 100644 index 0000000..eec3739 --- /dev/null +++ b/assets/php/vendor/react/cache/tests/ArrayCacheTest.php @@ -0,0 +1,60 @@ +<?php + +namespace React\Tests\Cache; + +use React\Cache\ArrayCache; + +class ArrayCacheTest extends TestCase +{ + private $cache; + + public function setUp() + { + $this->cache = new ArrayCache(); + } + + /** @test */ + public function getShouldRejectPromiseForNonExistentKey() + { + $this->cache + ->get('foo') + ->then( + $this->expectCallableNever(), + $this->expectCallableOnce() + ); + } + + /** @test */ + public function setShouldSetKey() + { + $this->cache + ->set('foo', 'bar'); + + $success = $this->createCallableMock(); + $success + ->expects($this->once()) + ->method('__invoke') + ->with('bar'); + + $this->cache + ->get('foo') + ->then($success); + } + + /** @test */ + public function removeShouldRemoveKey() + { + $this->cache + ->set('foo', 'bar'); + + $this->cache + ->remove('foo'); + + $this->cache + ->get('foo') + ->then( + $this->expectCallableNever(), + $this->expectCallableOnce() + ); + } +} diff --git a/assets/php/vendor/react/cache/tests/CallableStub.php b/assets/php/vendor/react/cache/tests/CallableStub.php new file mode 100644 index 0000000..2f547cd --- /dev/null +++ b/assets/php/vendor/react/cache/tests/CallableStub.php @@ -0,0 +1,10 @@ +<?php + +namespace React\Tests\Cache; + +class CallableStub +{ + public function __invoke() + { + } +} diff --git a/assets/php/vendor/react/cache/tests/TestCase.php b/assets/php/vendor/react/cache/tests/TestCase.php new file mode 100644 index 0000000..aa449f2 --- /dev/null +++ b/assets/php/vendor/react/cache/tests/TestCase.php @@ -0,0 +1,43 @@ +<?php + +namespace React\Tests\Cache; + +use PHPUnit\Framework\TestCase as BaseTestCase; + +class TestCase extends BaseTestCase +{ + protected function expectCallableExactly($amount) + { + $mock = $this->createCallableMock(); + $mock + ->expects($this->exactly($amount)) + ->method('__invoke'); + + return $mock; + } + + protected function expectCallableOnce() + { + $mock = $this->createCallableMock(); + $mock + ->expects($this->once()) + ->method('__invoke'); + + return $mock; + } + + protected function expectCallableNever() + { + $mock = $this->createCallableMock(); + $mock + ->expects($this->never()) + ->method('__invoke'); + + return $mock; + } + + protected function createCallableMock() + { + return $this->getMockBuilder('React\Tests\Cache\CallableStub')->getMock(); + } +} |