Skip to content

Commit 6161975

Browse files
Merge branch '2.3' into 2
2 parents 997e92c + c61cd3c commit 6161975

File tree

2 files changed

+38
-12
lines changed

2 files changed

+38
-12
lines changed

src/Iterators/LDAPIterator.php

+34-10
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,29 @@ private function fetchPagedResult(): bool
114114
$baseDn = $ldap->getBaseDn();
115115
}
116116

117-
ldap_control_paged_result($resource, $this->getPageSize(), true, $this->cookie);
118-
if ($this->getReturnAttributes() !== null) {
119-
$resultResource = ldap_search($resource, $baseDn ?? '', $this->getFilter() ?? '', $this->getReturnAttributes() ?? []);
117+
if (version_compare(PHP_VERSION, '8.0.0') < 0) {
118+
ldap_control_paged_result($resource, $this->getPageSize(), true, $this->cookie);
119+
if ($this->getReturnAttributes() !== null) {
120+
$resultResource = ldap_search($resource, $baseDn ?? '', $this->getFilter() ?? '', $this->getReturnAttributes() ?? []);
121+
} else {
122+
$resultResource = ldap_search($resource, $baseDn ?? '', $this->getFilter() ?? '');
123+
}
124+
if (! is_resource($resultResource)) {
125+
throw new \Exception('ldap_search returned a non-resource type value' . ldap_error($resource));
126+
}
120127
} else {
121-
$resultResource = ldap_search($resource, $baseDn ?? '', $this->getFilter() ?? '');
122-
}
123-
if (! is_resource($resultResource)) {
124-
throw new \Exception('ldap_search returned a non-resource type value' . ldap_error($resource));
128+
if ($this->getReturnAttributes() !== null) {
129+
$resultResource = ldap_search($resource, $baseDn ?? '', $this->getFilter() ?? '', $this->getReturnAttributes() ?? [],
130+
0, 0, 0, LDAP_DEREF_NEVER,
131+
[['oid' => LDAP_CONTROL_PAGEDRESULTS, 'value' => ['size' => $this->getPageSize(), 'cookie' => $this->cookie]]]
132+
);
133+
} else {
134+
$resultResource = ldap_search($resource, $baseDn ?? '', $this->getFilter() ?? '', [],
135+
0, 0, 0, LDAP_DEREF_NEVER,
136+
[['oid' => LDAP_CONTROL_PAGEDRESULTS, 'value' => ['size' => $this->getPageSize(), 'cookie' => $this->cookie]]]
137+
);
138+
}
139+
$response = ldap_parse_result($resource, $resultResource, $errcode , $matcheddn , $errmsg , $referrals, $controls);
125140
}
126141

127142
$entries = ldap_get_entries($resource, $resultResource);
@@ -130,9 +145,18 @@ private function fetchPagedResult(): bool
130145
}
131146
$entries = $this->getConvertedEntries($entries);
132147

133-
ErrorHandler::start();
134-
$response = ldap_control_paged_result_response($resource, $resultResource, $this->cookie);
135-
ErrorHandler::stop();
148+
if (version_compare(PHP_VERSION, '8.0.0') < 0) {
149+
ErrorHandler::start();
150+
$response = ldap_control_paged_result_response($resource, $resultResource, $this->cookie);
151+
ErrorHandler::stop();
152+
} else {
153+
if (isset($controls[LDAP_CONTROL_PAGEDRESULTS]['value']['cookie'])) {
154+
// You need to pass the cookie from the last call to the next one
155+
$this->cookie = $controls[LDAP_CONTROL_PAGEDRESULTS]['value']['cookie'];
156+
} else {
157+
$this->cookie = '';
158+
}
159+
}
136160

137161
if ($response !== true) {
138162
throw new LdapException($ldap, 'Paged result was empty');

src/Model/LDAPGateway.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ protected function searchWithIterator($filter, $baseDn = null, $attributes = [])
6262
$records = new LDAPIterator($this->getLdap(), $filter, $baseDn, $attributes, $pageSize);
6363
$results = $this->processSearchResults($records);
6464

65-
// Reset the LDAP pagination control back to the original, otherwise all further LDAP read queries fail
66-
ldap_control_paged_result($this->getLdap()->getResource(), 1000);
65+
if (version_compare(PHP_VERSION, '8.0.0') < 0) {
66+
// Reset the LDAP pagination control back to the original, otherwise all further LDAP read queries fail
67+
ldap_control_paged_result($this->getLdap()->getResource(), 1000);
68+
}
6769

6870
return $results;
6971
}

0 commit comments

Comments
 (0)