@@ -114,14 +114,29 @@ private function fetchPagedResult(): bool
114
114
$ baseDn = $ ldap ->getBaseDn ();
115
115
}
116
116
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
+ }
120
127
} 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 );
125
140
}
126
141
127
142
$ entries = ldap_get_entries ($ resource , $ resultResource );
@@ -130,9 +145,18 @@ private function fetchPagedResult(): bool
130
145
}
131
146
$ entries = $ this ->getConvertedEntries ($ entries );
132
147
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
+ }
136
160
137
161
if ($ response !== true ) {
138
162
throw new LdapException ($ ldap , 'Paged result was empty ' );
0 commit comments