Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement pagination #17

Open
bilfeldt opened this issue Jun 7, 2020 · 0 comments
Open

Implement pagination #17

bilfeldt opened this issue Jun 7, 2020 · 0 comments

Comments

@bilfeldt
Copy link
Member

bilfeldt commented Jun 7, 2020

General

Paginated responses should implement the PaginatedApiResponseInterface and they can be used like so for a concrete API:

$apiResponse = $api->examples()->get(); // PaginatedExampleApiResponseInterface which extends the PaginatedApiResponseInterface

Interface

A PaginatedApiResponseInterface has a bunch of methods which are used to traverse the results and return the same response type.

Note that the return typehint for the pagination should be self since we require the same response type to be returned when traversing and not just a new PaginatedApiResponseInterface. This is covariance which is only implemented in PHP 7.4 as can be seen here hence to support pre PHP 7.4 versions we leave out the return typehint for the traversing methods.

The methods of the interface are:

$apiResponse->hasPrev(); // bool
$apiResponse->hasNext(); // bool
// These traversing methods should all return the same type as the $apiResponse itself
$apiResponse->prev(); // PaginatedExampleApiResponseInterface - Note return type 'self' left out for pre PHP7.4 compatibility
$apiResponse->next(); // PaginatedExampleApiResponseInterface - Note return type 'self' left out for pre PHP7.4 compatibility
$apiResponse->last(); // PaginatedExampleApiResponseInterface - Note return type 'self' left out for pre PHP7.4 compatibility

Note that prev() and next() can throw an OutOfRangeException if the pages are not there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant