-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from ASAPIRL/post-for-query-request
Add support for getting data via POST
- Loading branch information
Showing
4 changed files
with
44 additions
and
15 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 |
---|---|---|
|
@@ -20,19 +20,24 @@ class {{ entityName.singular }}Paginator | |
/** @var PageEntity Page data transfer object. */ | ||
protected PageEntity $page; | ||
/** @var array Search params for POST /query request */ | ||
protected $postParams; | ||
/** | ||
* Sets up the paginator. | ||
* | ||
* @param HttpClient $client Http client for retrieving pages. | ||
* @param Response $response Response from Http client. | ||
* @param array $postParams Search params for POST /query request | ||
* | ||
* @author Aidan Casey <[email protected]> | ||
*/ | ||
public function __construct(HttpClient $client, $response) | ||
public function __construct(HttpClient $client, $response, $postParams = null) | ||
{ | ||
$this->client = $client; | ||
$this->collection = {{ entityName.singular }}Collection::fromResponse($response); | ||
$this->page = PageEntity::fromResponse($response); | ||
$this->postParams = $postParams; | ||
} | ||
/** | ||
|
@@ -70,7 +75,12 @@ class {{ entityName.singular }}Paginator | |
*/ | ||
public function nextPage(): {{ entityName.singular }}Paginator | ||
{ | ||
$response = $this->client->getClient()->get($this->page->nextPageUrl); | ||
if(is_null($this->postParams)){ | ||
$response = $this->client->getClient()->get($this->page->nextPageUrl); | ||
}else{ | ||
$response = $this->client->getClient()->post($this->page->nextPageUrl, ['json' => $this->postParams]); | ||
} | ||
return new static($this->client, $response); | ||
} | ||
|
@@ -81,7 +91,12 @@ class {{ entityName.singular }}Paginator | |
*/ | ||
public function prevPage (): {{ entityName.singular }}Paginator | ||
{ | ||
$response = $this->client->getClient()->get($this->page->prevPageUrl); | ||
if(is_null($this->postParams)){ | ||
$response = $this->client->getClient()->get($this->page->prevPageUrl); | ||
}else{ | ||
$response = $this->client->getClient()->post($this->page->prevPageUrl, ['json' => $this->postParams]); | ||
} | ||
return new static($this->client, $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