Skip to content

Commit 2090e26

Browse files
committed
Add method to get all results from all pages to PaginatedList
1 parent b2f7add commit 2090e26

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

lib/Client/List/PaginatedList.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,26 @@ public function getPreviousPage(): ?static
113113
return $this->getOffset($this->getPreviousOffset());
114114
}
115115

116+
/**
117+
* Get all results from this page and all following pages.
118+
* This will request each page from the api one by one.
119+
*
120+
* When called on the first page this will return all results.
121+
*
122+
* @throws ApiException
123+
* @return T[]
124+
*/
125+
public function getResultsFromFollowingPages(): array
126+
{
127+
$results = $this->getResults();
128+
$nextPage = $this->getNextPage();
129+
while ($nextPage !== null) {
130+
array_push($results, ...$nextPage->getResults());
131+
$nextPage = $nextPage->getNextPage();
132+
}
133+
return $results;
134+
}
135+
116136
/**
117137
* @inheritDoc
118138
* @return T

0 commit comments

Comments
 (0)