generated from cerbero90/skeleton
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
89 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Cerbero\LazyJsonPages\Concerns; | ||
|
||
use Cerbero\LazyJsonPages\Services\Client; | ||
use Closure; | ||
use Generator; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
/** | ||
* The trait to yield items from cursor-aware paginations. | ||
*/ | ||
trait YieldsItemsByCursor | ||
{ | ||
/** | ||
* Yield the paginated items by following the cursor of each page. | ||
* | ||
* @param (Closure(ResponseInterface): Generator<int, mixed>) $callback | ||
* @return Generator<int, mixed> | ||
*/ | ||
protected function yieldItemsByCursor(Closure $callback): Generator | ||
{ | ||
yield from $generator = $callback($this->source->pullResponse()); | ||
|
||
$request = clone $this->source->request(); | ||
|
||
while ($cursor = $this->toPage($generator->getReturn(), onlyNumerics: false)) { | ||
$uri = $this->uriForPage($request->getUri(), (string) $cursor); | ||
$response = Client::instance()->send($request->withUri($uri)); | ||
|
||
yield from $generator = $callback($response); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters