forked from zendesk/zendesk_api_client_php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPagination.php
43 lines (37 loc) · 1.12 KB
/
Pagination.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
namespace Zendesk\API\Traits\Resource;
use Zendesk\API\Traits\Utility\Pagination\CbpStrategy;
use Zendesk\API\Traits\Utility\Pagination\PaginationIterator;
trait Pagination {
/**
* Usage:
* $ticketsIterator = $client->tickets()->iterator();
* foreach ($ticketsIterator as $ticket) {
* process($ticket);
* }
*
* @return PaginationIterator to fetch all pages.
*/
public function iterator($params = [], $method = 'findAll')
{
$strategyClass = $this->paginationStrategyClass();
$strategy = new $strategyClass($this->resourcesKey(), $params);
return new PaginationIterator($this, $strategy, $method);
}
/**
* Override this method in your resources
*
* @return string subclass of AbstractStrategy used for fetching pages
*/
protected function paginationStrategyClass() {
return CbpStrategy::class;
}
/**
* The key in the API responses where the resources are returned
*
* @return string eg: "job_statuses"
*/
protected function resourcesKey() {
return $this->objectNamePlural;
}
}