Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame^] | 1 | <?php |
| 2 | |
| 3 | namespace LdapRecord\Query\Pagination; |
| 4 | |
| 5 | use LdapRecord\LdapInterface; |
| 6 | |
| 7 | class 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 | } |