From 5a30d4d8939c98333015d576fe83af6a2eb56661 Mon Sep 17 00:00:00 2001 From: Simon Frings Date: Fri, 11 Mar 2022 13:47:58 +0100 Subject: [PATCH] Update documentation and examples to match version in early access --- .gitignore | 2 ++ README.md | 63 ++++++++++++++++++++++++++++++++++++------- examples/database.php | 38 ++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 9 deletions(-) create mode 100644 .gitignore create mode 100644 examples/database.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c8153b5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/composer.lock +/vendor/ diff --git a/README.md b/README.md index ba57fd4..4226cd6 100644 --- a/README.md +++ b/README.md @@ -5,10 +5,26 @@ built on top of [ReactPHP](https://reactphp.org/). **Table of contents** +* [Support us](#support-us) * [Quickstart example](#quickstart-example) * [Install](#install) * [License](#license) +## Support us + +[![A clue·access project](https://raw.githubusercontent.com/clue-access/clue-access/main/clue-access.png)](https://github.com/clue-access/clue-access) + +*This project is currently under active development, +you're looking at a temporary placeholder repository.* + +The code is available in early access to my sponsors here: https://github.com/clue-access/reactphp-memoize + +Do you sponsor me on GitHub? Thank you for supporting sustainable open-source, you're awesome! ❤️ Have fun with the code! 🎉 + +Seeing a 404 (Not Found)? Sounds like you're not in the early access group. Consider becoming a [sponsor on GitHub](https://github.com/sponsors/clue) for early access. Check out [clue·access](https://github.com/clue-access/clue-access) for more details. + +This way, more people get a chance to take a look at the code before the public release. + ## Quickstart example Once [installed](#install), you can use the following code to decorate a demo @@ -45,24 +61,53 @@ function multiple times. ## Install -[![A clue·access project](https://raw.githubusercontent.com/clue-access/clue-access/main/clue-access.png)](https://github.com/clue-access/clue-access) +The recommended way to install this library is [through Composer](https://getcomposer.org/). +[New to Composer?](https://getcomposer.org/doc/00-intro.md) -*This project is currently under active development, -you're looking at a temporary placeholder repository.* +This project does not yet follow [SemVer](https://semver.org/). +This will install the latest supported version: -The code is available in early access to my sponsors here: https://github.com/clue-access/reactphp-memoize +While in [early access](#support-us), you first have to manually change your +`composer.json` to include these lines to access the supporters-only repository: -Do you sponsor me on GitHub? Thank you for supporting sustainable open-source, you're awesome! ❤️ Have fun with the code! 🎉 +```json +{ + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/clue-access/reactphp-memoize" + } + ] +} +``` -Seeing a 404 (Not Found)? Sounds like you're not in the early access group. Consider becoming a [sponsor on GitHub](https://github.com/sponsors/clue) for early access. Check out [clue·access](https://github.com/clue-access/clue-access) for more details. +Then install this package as usual: -This way, more people get a chance to take a look at the code before the public release. +```bash +$ composer require clue/reactphp-memoize:dev-main +``` -Rock on 🤘 +This project aims to run on any platform and thus does not require any PHP +extensions and supports running on PHP 7.3 through current PHP 8+. + +## 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 +$ vendor/bin/phpunit +``` ## License -This project will be released under the permissive [MIT license](LICENSE). +This project is released under the permissive [MIT license](LICENSE). > Did you know that I offer custom development services and issuing invoices for sponsorships of releases and for contributions? Contact me (@clue) for details. diff --git a/examples/database.php b/examples/database.php new file mode 100644 index 0000000..50ac1a1 --- /dev/null +++ b/examples/database.php @@ -0,0 +1,38 @@ + + */ +function foo(int $id): React\Promise\PromiseInterface +{ + $browser = new React\Http\Browser(); + return $browser->get('http://httpbingo.org/status/' . $id)->then(function (Psr\Http\Message\ResponseInterface $response) { + return $response->getStatusCode(); + }); +} + +//foo(200)->then('var_dump', 'printf'); + +$memoized = memoize('foo'); + +$memoized(200)->then('var_dump', 'printf'); +$memoized(200)->then('var_dump', 'printf'); +$memoized(200)->then('var_dump', 'printf'); +$memoized(200)->then('var_dump', 'printf'); +$memoized(200)->then('var_dump', 'printf'); +$memoized(200)->then('var_dump', 'printf'); + +React\EventLoop\Loop::addTimer(0.01, function () use ($memoized) { + $memoized(200)->then('var_dump', 'printf'); +}); + +$memoized(201)->then('var_dump', 'printf'); +$memoized(201)->then('var_dump', 'printf'); +$memoized(201)->then('var_dump', 'printf'); +$memoized(201)->then('var_dump', 'printf');