blob: c0a31afd9f32b63815fcfbd69937e225884e5c47 [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 {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010040 $errorCode = 0;
41 $dn = $errorMessage = $refs = null;
42 $controls = $this->query->controls;
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020043
44 $ldap->parseResult(
45 $resource,
46 $errorCode,
47 $dn,
48 $errorMessage,
49 $refs,
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010050 $controls
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020051 );
52
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010053 $cookie = $controls[LDAP_CONTROL_PAGEDRESULTS]['value']['cookie'] ?? '';
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020054
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010055 $this->query->controls[LDAP_CONTROL_PAGEDRESULTS]['value'] = [
56 'size' => $this->perPage,
57 'cookie' => $cookie,
58 ];
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020059 }
60
61 /**
62 * @inheritdoc
63 */
64 protected function resetServerControls(LdapInterface $ldap)
65 {
Matthias Andreas Benkard1ba53812022-12-27 17:32:58 +010066 unset($this->query->controls[LDAP_CONTROL_PAGEDRESULTS]);
Matthias Andreas Benkard7b2a3a12021-08-16 10:57:25 +020067 }
68}