Skip to content

Commit 65664c0

Browse files
committed
Add method to get all results from all pages to PaginatedList
1 parent fe4ebae commit 65664c0

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

lib/Client/List/PaginatedList.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,25 @@ public function getPreviousPage(): ?static
114114
return $this->getOffset($this->getPreviousOffset());
115115
}
116116

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

119137
/**
120138
* @inheritDoc

0 commit comments

Comments
 (0)