| 1: | <?php declare(strict_types=1); |
| 2: | |
| 3: | namespace Salient\Contract\Curler; |
| 4: | |
| 5: | use Psr\Http\Message\RequestInterface as PsrRequestInterface; |
| 6: | use Salient\Contract\Http\Message\ResponseInterface; |
| 7: | use Salient\Contract\Http\HasHttpHeader; |
| 8: | |
| 9: | /** |
| 10: | * @api |
| 11: | */ |
| 12: | interface CurlerPagerInterface extends HasHttpHeader |
| 13: | { |
| 14: | /** |
| 15: | * Get a request to retrieve the first page of data from the endpoint |
| 16: | * |
| 17: | * Return `$request` if no special handling is required. |
| 18: | * |
| 19: | * Return a {@see CurlerPageRequestInterface} to propagate `$query` changes |
| 20: | * to {@see CurlerPagerInterface::getPage()} in array form. |
| 21: | * |
| 22: | * @param mixed[]|null $query The query applied to `$request`. |
| 23: | * @return CurlerPageRequestInterface|PsrRequestInterface |
| 24: | */ |
| 25: | public function getFirstRequest( |
| 26: | PsrRequestInterface $request, |
| 27: | CurlerInterface $curler, |
| 28: | ?array $query = null |
| 29: | ); |
| 30: | |
| 31: | /** |
| 32: | * Convert data returned by the endpoint to a new page object |
| 33: | * |
| 34: | * @template TPage of CurlerPageInterface|null |
| 35: | * |
| 36: | * @param mixed $data |
| 37: | * @param TPage $previousPage |
| 38: | * @param int|null $previousEntities The number of entities returned from |
| 39: | * the endpoint via previous pages. |
| 40: | * @param mixed[]|null $query The query applied to `$request` or returned by |
| 41: | * {@see CurlerPageRequestInterface::getQuery()}, if applicable. |
| 42: | * @return (TPage is null ? CurlerPageInterface : TPage) |
| 43: | */ |
| 44: | public function getPage( |
| 45: | $data, |
| 46: | PsrRequestInterface $request, |
| 47: | ResponseInterface $response, |
| 48: | CurlerInterface $curler, |
| 49: | ?CurlerPageInterface $previousPage = null, |
| 50: | ?int $previousEntities = null, |
| 51: | ?array $query = null |
| 52: | ): CurlerPageInterface; |
| 53: | } |
| 54: |