Skip to content

Commit 4328c0f

Browse files
committed
Add OffsetPaginator and align CursorPaginator on an immutable page API
1 parent 62ab9bd commit 4328c0f

20 files changed

Lines changed: 1514 additions & 457 deletions

UPGRADE.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,38 @@ and directly start using native lazy objects.
2929

3030
# Upgrade to 3.7
3131

32+
## Deprecated `Doctrine\ORM\Tools\Pagination\Paginator`
33+
34+
Use `Doctrine\ORM\Tools\Pagination\OffsetPaginator` instead. The offset is no
35+
longer read implicitly from the query: it is passed as an `Offset` value object
36+
to `paginate()`, which returns an immutable, iterable `OffsetPage`.
37+
38+
```diff
39+
-use Doctrine\ORM\Tools\Pagination\Paginator;
40+
+use Doctrine\ORM\Tools\Pagination\Offset;
41+
+use Doctrine\ORM\Tools\Pagination\OffsetPaginator;
42+
43+
-$query = $entityManager->createQuery($dql)
44+
- ->setFirstResult(0)
45+
- ->setMaxResults(25);
46+
+$query = $entityManager->createQuery($dql);
47+
48+
-$paginator = new Paginator($query, fetchJoinCollection: true);
49+
+$page = (new OffsetPaginator(fetchJoinCollection: true))
50+
+ ->paginate($query, new Offset(0, 25));
51+
52+
-$total = count($paginator);
53+
+$total = $page->getTotalCount();
54+
55+
-foreach ($paginator as $post) {
56+
+foreach ($page as $post) {
57+
// ...
58+
}
59+
```
60+
61+
`Paginator::setUseOutputWalkers()` becomes the `useOutputWalkers` constructor
62+
argument of `OffsetPaginator`.
63+
3264
## Deprecated `Doctrine\ORM\Query\AST\TypedExpression`
3365

3466
Implement `Doctrine\ORM\Query\AST\ExpressionWithReturnType` instead, which exposes

0 commit comments

Comments
 (0)