From de070a9ce3a83d73681b7f11af5649119c021a3e Mon Sep 17 00:00:00 2001 From: Andrea Marco Sartori Date: Fri, 6 Sep 2024 14:12:34 -0300 Subject: [PATCH] Update instantiation vectors --- README.md | 19 +++++++++++++------ bootstrap.php | 8 ++++++++ composer.json | 1 + helpers.php | 11 ++--------- 4 files changed, 24 insertions(+), 15 deletions(-) create mode 100644 bootstrap.php diff --git a/README.md b/README.md index 8eaead6..7133291 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,12 @@ [![Total Downloads][ico-downloads]][link-downloads] ```php -$lazyCollection = LazyJsonPages::from($source) +use Illuminate\Support\LazyCollection; + +LazyCollection::fromJsonPages($source) ->totalPages('pagination.total_pages') ->async(requests: 5) + ->throttle(requests: 60, perMinute: 1) ->collect('data.*'); ``` @@ -51,21 +54,25 @@ composer require cerbero/lazy-json-pages ### 👣 Basics -Depending on our coding style, we can initialize Lazy JSON Pages in 3 different ways: +Depending on our coding style, we can initialize Lazy JSON Pages in 4 different ways: ```php use Cerbero\LazyJsonPages\LazyJsonPages; +use Illuminate\Support\LazyCollection; use function Cerbero\LazyJsonPages\lazyJsonPages; +// lazy collection macro +LazyCollection::fromJsonPages($source); + // classic instantiation -$lazyJsonPages = new LazyJsonPages($source); +new LazyJsonPages($source); -// static method (easier methods chaining) -$lazyJsonPages = LazyJsonPages::from($source); +// static method +LazyJsonPages::from($source); // namespaced helper -$lazyJsonPages = lazyJsonPages($source); +lazyJsonPages($source); ``` The variable `$source` in our examples represents any [source](#-sources) that points to a paginated JSON API. Once we define the source, we can then chain methods to define how the API is paginated: diff --git a/bootstrap.php b/bootstrap.php new file mode 100644 index 0000000..5e9e82e --- /dev/null +++ b/bootstrap.php @@ -0,0 +1,8 @@ +