Skip to content

allow to set the requested page on all endpoints #586

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

Merged
merged 3 commits into from
Nov 27, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions lib/Github/Api/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ abstract class AbstractApi implements ApiInterface
*/
protected $client;

/**
* The requested page (GitHub pagination).
*
* @var null|int
*/
protected $page;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not private?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same why $perPage isn't private - it should be extendable.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make $perPage private to if it didn't break BC.

It is easier to change from private to protected than the other way around.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @Gummibeer, please change this property to private


/**
* Number of items per page (GitHub pagination).
*
Expand All @@ -38,6 +45,24 @@ public function configure()
{
}

/**
* @return null|int
*/
public function getPage()
{
return $this->page;
}

/**
* @param null|int $page
*/
public function setPage($page)
{
$this->page = (null === $page ? $page : (int) $page);

return $this;
}

/**
* @return null|int
*/
Expand Down Expand Up @@ -67,6 +92,9 @@ public function setPerPage($perPage)
*/
protected function get($path, array $parameters = array(), array $requestHeaders = array())
{
if (null !== $this->page && !isset($parameters['page'])) {
$parameters['page'] = $this->page;
}
if (null !== $this->perPage && !isset($parameters['per_page'])) {
$parameters['per_page'] = $this->perPage;
}
Expand Down