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