blob: 9ab6e6704baa3027091b2983326f2a87c0bb2611 [file] [log] [blame]
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +02001<?php
2
3namespace LdapRecord\Query\Pagination;
4
5use LdapRecord\LdapInterface;
6
7class Paginator extends AbstractPaginator
8{
9 /**
10 * @inheritdoc
11 */
12 protected function fetchCookie()
13 {
14 return $this->query->controls[LDAP_CONTROL_PAGEDRESULTS]['value']['cookie'] ?? null;
15 }
16
17 /**
18 * @inheritdoc
19 */
20 protected function prepareServerControls()
21 {
22 $this->query->addControl(LDAP_CONTROL_PAGEDRESULTS, $this->isCritical, [
23 'size' => $this->perPage, 'cookie' => '',
24 ]);
25 }
26
27 /**
28 * @inheritdoc
29 */
30 protected function applyServerControls(LdapInterface $ldap)
31 {
32 $ldap->setOption(LDAP_OPT_SERVER_CONTROLS, $this->query->controls);
33 }
34
35 /**
36 * @inheritdoc
37 */
38 protected function updateServerControls(LdapInterface $ldap, $resource)
39 {
40 $errorCode = $dn = $errorMessage = $refs = null;
41
42 $ldap->parseResult(
43 $resource,
44 $errorCode,
45 $dn,
46 $errorMessage,
47 $refs,
48 $this->query->controls
49 );
50
51 $this->resetPageSize();
52 }
53
54 /**
55 * Reset the page control page size.
56 *
57 * @return void
58 */
59 protected function resetPageSize()
60 {
61 $this->query->controls[LDAP_CONTROL_PAGEDRESULTS]['value']['size'] = $this->perPage;
62 }
63
64 /**
65 * @inheritdoc
66 */
67 protected function resetServerControls(LdapInterface $ldap)
68 {
69 $this->query->controls = [];
70 }
71}