Appearance
PaginatedResult
php
class Zairakai\LaravelTwitch\Dto\PaginatedResultGeneric wrapper for paginated Twitch API responses.
Usage:
php
$raw = Twitch::getStreams();
$result = PaginatedResult::fromRaw($raw, Stream::class);
foreach ($result->items as $stream) {
echo $stream->userName; // Stream instance
}
if ($result->hasMore()) {
$next = Twitch::getStreams(after: $result->cursor);
}Source: src/Dto/PaginatedResult.php
Methods
__construct()
php
public function __construct(array $items, string $cursor, int $total = null)| Parameter | Description |
|---|---|
$items | Hydrated DTO instances |
$cursor | Cursor for the next page (null = no more pages) |
$total | Total count (if provided by the API) |
fromRaw()
php
public static function fromRaw(array $raw, string $dtoClass): selfBuild a PaginatedResult from a raw Twitch API response array.
| Parameter | Description |
|---|---|
$raw | Raw response from makeRequest() |
$dtoClass | DTO class to hydrate each item |
Returns self<TItem>
count()
php
public function count(): intNumber of items in the current page.
hasMore()
php
public function hasMore(): boolWhether more pages are available.