Skip to content

Commit de070a9

Browse files
committed
Update instantiation vectors
1 parent d40a669 commit de070a9

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

README.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212
[![Total Downloads][ico-downloads]][link-downloads]
1313

1414
```php
15-
$lazyCollection = LazyJsonPages::from($source)
15+
use Illuminate\Support\LazyCollection;
16+
17+
LazyCollection::fromJsonPages($source)
1618
->totalPages('pagination.total_pages')
1719
->async(requests: 5)
20+
->throttle(requests: 60, perMinute: 1)
1821
->collect('data.*');
1922
```
2023

@@ -51,21 +54,25 @@ composer require cerbero/lazy-json-pages
5154

5255
### 👣 Basics
5356

54-
Depending on our coding style, we can initialize Lazy JSON Pages in 3 different ways:
57+
Depending on our coding style, we can initialize Lazy JSON Pages in 4 different ways:
5558

5659
```php
5760
use Cerbero\LazyJsonPages\LazyJsonPages;
61+
use Illuminate\Support\LazyCollection;
5862

5963
use function Cerbero\LazyJsonPages\lazyJsonPages;
6064

65+
// lazy collection macro
66+
LazyCollection::fromJsonPages($source);
67+
6168
// classic instantiation
62-
$lazyJsonPages = new LazyJsonPages($source);
69+
new LazyJsonPages($source);
6370

64-
// static method (easier methods chaining)
65-
$lazyJsonPages = LazyJsonPages::from($source);
71+
// static method
72+
LazyJsonPages::from($source);
6673

6774
// namespaced helper
68-
$lazyJsonPages = lazyJsonPages($source);
75+
lazyJsonPages($source);
6976
```
7077

7178
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:

bootstrap.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
use Cerbero\LazyJsonPages\LazyJsonPages;
4+
use Illuminate\Support\LazyCollection;
5+
6+
(static function() {
7+
LazyCollection::macro('fromJsonPages', [LazyJsonPages::class, 'from']);
8+
})();

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"Cerbero\\LazyJsonPages\\": "src"
4141
},
4242
"files": [
43+
"bootstrap.php",
4344
"helpers.php"
4445
]
4546
},

helpers.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,10 @@
22

33
namespace Cerbero\LazyJsonPages;
44

5-
use Closure;
6-
use Illuminate\Support\LazyCollection;
7-
85
/**
96
* Load items from any paginated JSON API into a lazy collection.
10-
*
11-
* @param mixed $source
12-
* @param Closure $config
13-
* @return LazyCollection
147
*/
15-
function lazyJsonPages(mixed $source, Closure $config): LazyCollection
8+
function lazyJsonPages(mixed $source): LazyJsonPages
169
{
17-
return LazyCollection::fromJsonPages($source, $config);
10+
return LazyJsonPages::from($source);
1811
}

0 commit comments

Comments
 (0)