Matthias Andreas Benkard | 7b2a3a1 | 2021-08-16 10:57:25 +0200 | [diff] [blame^] | 1 | <?php |
| 2 | |
| 3 | namespace Adldap\Connections; |
| 4 | |
| 5 | /** |
| 6 | * The Connection interface used for making connections. Implementing |
| 7 | * this interface on connection classes helps unit and functional |
| 8 | * test classes that require a connection. |
| 9 | * |
| 10 | * Interface ConnectionInterface |
| 11 | */ |
| 12 | interface ConnectionInterface |
| 13 | { |
| 14 | /** |
| 15 | * The SSL LDAP protocol string. |
| 16 | * |
| 17 | * @var string |
| 18 | */ |
| 19 | const PROTOCOL_SSL = 'ldaps://'; |
| 20 | |
| 21 | /** |
| 22 | * The standard LDAP protocol string. |
| 23 | * |
| 24 | * @var string |
| 25 | */ |
| 26 | const PROTOCOL = 'ldap://'; |
| 27 | |
| 28 | /** |
| 29 | * The LDAP SSL port number. |
| 30 | * |
| 31 | * @var string |
| 32 | */ |
| 33 | const PORT_SSL = 636; |
| 34 | |
| 35 | /** |
| 36 | * The standard LDAP port number. |
| 37 | * |
| 38 | * @var string |
| 39 | */ |
| 40 | const PORT = 389; |
| 41 | |
| 42 | /** |
| 43 | * Constructor. |
| 44 | * |
| 45 | * @param string|null $name The connection name. |
| 46 | */ |
| 47 | public function __construct($name = null); |
| 48 | |
| 49 | /** |
| 50 | * Returns true / false if the current connection instance is using SSL. |
| 51 | * |
| 52 | * @return bool |
| 53 | */ |
| 54 | public function isUsingSSL(); |
| 55 | |
| 56 | /** |
| 57 | * Returns true / false if the current connection instance is using TLS. |
| 58 | * |
| 59 | * @return bool |
| 60 | */ |
| 61 | public function isUsingTLS(); |
| 62 | |
| 63 | /** |
| 64 | * Returns true / false if the current connection is able to modify passwords. |
| 65 | * |
| 66 | * @return bool |
| 67 | */ |
| 68 | public function canChangePasswords(); |
| 69 | |
| 70 | /** |
| 71 | * Returns true / false if the current connection is bound. |
| 72 | * |
| 73 | * @return bool |
| 74 | */ |
| 75 | public function isBound(); |
| 76 | |
| 77 | /** |
| 78 | * Sets the current connection to use SSL. |
| 79 | * |
| 80 | * @param bool $enabled |
| 81 | * |
| 82 | * @return ConnectionInterface |
| 83 | */ |
| 84 | public function ssl($enabled = true); |
| 85 | |
| 86 | /** |
| 87 | * Sets the current connection to use TLS. |
| 88 | * |
| 89 | * @param bool $enabled |
| 90 | * |
| 91 | * @return ConnectionInterface |
| 92 | */ |
| 93 | public function tls($enabled = true); |
| 94 | |
| 95 | /** |
| 96 | * Returns the full LDAP host URL. |
| 97 | * |
| 98 | * Ex: ldap://192.168.1.1:386 |
| 99 | * |
| 100 | * @return string|null |
| 101 | */ |
| 102 | public function getHost(); |
| 103 | |
| 104 | /** |
| 105 | * Returns the connections name. |
| 106 | * |
| 107 | * @return string|null |
| 108 | */ |
| 109 | public function getName(); |
| 110 | |
| 111 | /** |
| 112 | * Get the current connection. |
| 113 | * |
| 114 | * @return mixed |
| 115 | */ |
| 116 | public function getConnection(); |
| 117 | |
| 118 | /** |
| 119 | * Retrieve the entries from a search result. |
| 120 | * |
| 121 | * @link http://php.net/manual/en/function.ldap-get-entries.php |
| 122 | * |
| 123 | * @param $searchResult |
| 124 | * |
| 125 | * @return mixed |
| 126 | */ |
| 127 | public function getEntries($searchResult); |
| 128 | |
| 129 | /** |
| 130 | * Returns the number of entries from a search result. |
| 131 | * |
| 132 | * @link http://php.net/manual/en/function.ldap-count-entries.php |
| 133 | * |
| 134 | * @param $searchResult |
| 135 | * |
| 136 | * @return int |
| 137 | */ |
| 138 | public function countEntries($searchResult); |
| 139 | |
| 140 | /** |
| 141 | * Compare value of attribute found in entry specified with DN. |
| 142 | * |
| 143 | * @link http://php.net/manual/en/function.ldap-compare.php |
| 144 | * |
| 145 | * @param string $dn |
| 146 | * @param string $attribute |
| 147 | * @param string $value |
| 148 | * |
| 149 | * @return mixed |
| 150 | */ |
| 151 | public function compare($dn, $attribute, $value); |
| 152 | |
| 153 | /** |
| 154 | * Retrieves the first entry from a search result. |
| 155 | * |
| 156 | * @link http://php.net/manual/en/function.ldap-first-entry.php |
| 157 | * |
| 158 | * @param $searchResult |
| 159 | * |
| 160 | * @return mixed |
| 161 | */ |
| 162 | public function getFirstEntry($searchResult); |
| 163 | |
| 164 | /** |
| 165 | * Retrieves the next entry from a search result. |
| 166 | * |
| 167 | * @link http://php.net/manual/en/function.ldap-next-entry.php |
| 168 | * |
| 169 | * @param $entry |
| 170 | * |
| 171 | * @return mixed |
| 172 | */ |
| 173 | public function getNextEntry($entry); |
| 174 | |
| 175 | /** |
| 176 | * Retrieves the ldap entry's attributes. |
| 177 | * |
| 178 | * @link http://php.net/manual/en/function.ldap-get-attributes.php |
| 179 | * |
| 180 | * @param $entry |
| 181 | * |
| 182 | * @return mixed |
| 183 | */ |
| 184 | public function getAttributes($entry); |
| 185 | |
| 186 | /** |
| 187 | * Retrieve the last error on the current connection. |
| 188 | * |
| 189 | * @link http://php.net/manual/en/function.ldap-error.php |
| 190 | * |
| 191 | * @return string |
| 192 | */ |
| 193 | public function getLastError(); |
| 194 | |
| 195 | /** |
| 196 | * Return detailed information about an error. |
| 197 | * |
| 198 | * Returns false when there was a successful last request. |
| 199 | * |
| 200 | * Returns DetailedError when there was an error. |
| 201 | * |
| 202 | * @return DetailedError|null |
| 203 | */ |
| 204 | public function getDetailedError(); |
| 205 | |
| 206 | /** |
| 207 | * Get all binary values from the specified result entry. |
| 208 | * |
| 209 | * @link http://php.net/manual/en/function.ldap-get-values-len.php |
| 210 | * |
| 211 | * @param $entry |
| 212 | * @param $attribute |
| 213 | * |
| 214 | * @return array |
| 215 | */ |
| 216 | public function getValuesLen($entry, $attribute); |
| 217 | |
| 218 | /** |
| 219 | * Sets an option on the current connection. |
| 220 | * |
| 221 | * @link http://php.net/manual/en/function.ldap-set-option.php |
| 222 | * |
| 223 | * @param int $option |
| 224 | * @param mixed $value |
| 225 | * |
| 226 | * @return mixed |
| 227 | */ |
| 228 | public function setOption($option, $value); |
| 229 | |
| 230 | /** |
| 231 | * Sets options on the current connection. |
| 232 | * |
| 233 | * @param array $options |
| 234 | * |
| 235 | * @return mixed |
| 236 | */ |
| 237 | public function setOptions(array $options = []); |
| 238 | |
| 239 | /** |
| 240 | * Set a callback function to do re-binds on referral chasing. |
| 241 | * |
| 242 | * @link http://php.net/manual/en/function.ldap-set-rebind-proc.php |
| 243 | * |
| 244 | * @param callable $callback |
| 245 | * |
| 246 | * @return bool |
| 247 | */ |
| 248 | public function setRebindCallback(callable $callback); |
| 249 | |
| 250 | /** |
| 251 | * Connects to the specified hostname using the specified port. |
| 252 | * |
| 253 | * @link http://php.net/manual/en/function.ldap-start-tls.php |
| 254 | * |
| 255 | * @param string|array $hostname |
| 256 | * @param int $port |
| 257 | * |
| 258 | * @return mixed |
| 259 | */ |
| 260 | public function connect($hostname = [], $port = 389); |
| 261 | |
| 262 | /** |
| 263 | * Starts a connection using TLS. |
| 264 | * |
| 265 | * @link http://php.net/manual/en/function.ldap-start-tls.php |
| 266 | * |
| 267 | * @throws ConnectionException If starting TLS fails. |
| 268 | * |
| 269 | * @return mixed |
| 270 | */ |
| 271 | public function startTLS(); |
| 272 | |
| 273 | /** |
| 274 | * Binds to the current connection using the specified username and password. |
| 275 | * If sasl is true, the current connection is bound using SASL. |
| 276 | * |
| 277 | * @link http://php.net/manual/en/function.ldap-bind.php |
| 278 | * |
| 279 | * @param string $username |
| 280 | * @param string $password |
| 281 | * @param bool $sasl |
| 282 | * |
| 283 | * @throws ConnectionException If starting TLS fails. |
| 284 | * |
| 285 | * @return bool |
| 286 | */ |
| 287 | public function bind($username, $password, $sasl = false); |
| 288 | |
| 289 | /** |
| 290 | * Closes the current connection. |
| 291 | * |
| 292 | * Returns false if no connection is present. |
| 293 | * |
| 294 | * @link http://php.net/manual/en/function.ldap-close.php |
| 295 | * |
| 296 | * @return bool |
| 297 | */ |
| 298 | public function close(); |
| 299 | |
| 300 | /** |
| 301 | * Performs a search on the current connection. |
| 302 | * |
| 303 | * @link http://php.net/manual/en/function.ldap-search.php |
| 304 | * |
| 305 | * @param string $dn |
| 306 | * @param string $filter |
| 307 | * @param array $fields |
| 308 | * @param bool $onlyAttributes |
| 309 | * @param int $size |
| 310 | * @param int $time |
| 311 | * |
| 312 | * @return mixed |
| 313 | */ |
| 314 | public function search($dn, $filter, array $fields, $onlyAttributes = false, $size = 0, $time = 0); |
| 315 | |
| 316 | /** |
| 317 | * Reads an entry on the current connection. |
| 318 | * |
| 319 | * @link http://php.net/manual/en/function.ldap-read.php |
| 320 | * |
| 321 | * @param string $dn |
| 322 | * @param $filter |
| 323 | * @param array $fields |
| 324 | * @param bool $onlyAttributes |
| 325 | * @param int $size |
| 326 | * @param int $time |
| 327 | * |
| 328 | * @return mixed |
| 329 | */ |
| 330 | public function read($dn, $filter, array $fields, $onlyAttributes = false, $size = 0, $time = 0); |
| 331 | |
| 332 | /** |
| 333 | * Performs a single level search on the current connection. |
| 334 | * |
| 335 | * @link http://php.net/manual/en/function.ldap-list.php |
| 336 | * |
| 337 | * @param string $dn |
| 338 | * @param string $filter |
| 339 | * @param array $attributes |
| 340 | * @param bool $onlyAttributes |
| 341 | * @param int $size |
| 342 | * @param int $time |
| 343 | * |
| 344 | * @return mixed |
| 345 | */ |
| 346 | public function listing($dn, $filter, array $attributes, $onlyAttributes = false, $size = 0, $time = 0); |
| 347 | |
| 348 | /** |
| 349 | * Adds an entry to the current connection. |
| 350 | * |
| 351 | * @link http://php.net/manual/en/function.ldap-add.php |
| 352 | * |
| 353 | * @param string $dn |
| 354 | * @param array $entry |
| 355 | * |
| 356 | * @return bool |
| 357 | */ |
| 358 | public function add($dn, array $entry); |
| 359 | |
| 360 | /** |
| 361 | * Deletes an entry on the current connection. |
| 362 | * |
| 363 | * @link http://php.net/manual/en/function.ldap-delete.php |
| 364 | * |
| 365 | * @param string $dn |
| 366 | * |
| 367 | * @return bool |
| 368 | */ |
| 369 | public function delete($dn); |
| 370 | |
| 371 | /** |
| 372 | * Modify the name of an entry on the current connection. |
| 373 | * |
| 374 | * @link http://php.net/manual/en/function.ldap-rename.php |
| 375 | * |
| 376 | * @param string $dn |
| 377 | * @param string $newRdn |
| 378 | * @param string $newParent |
| 379 | * @param bool $deleteOldRdn |
| 380 | * |
| 381 | * @return bool |
| 382 | */ |
| 383 | public function rename($dn, $newRdn, $newParent, $deleteOldRdn = false); |
| 384 | |
| 385 | /** |
| 386 | * Modifies an existing entry on the current connection. |
| 387 | * |
| 388 | * @link http://php.net/manual/en/function.ldap-modify.php |
| 389 | * |
| 390 | * @param string $dn |
| 391 | * @param array $entry |
| 392 | * |
| 393 | * @return bool |
| 394 | */ |
| 395 | public function modify($dn, array $entry); |
| 396 | |
| 397 | /** |
| 398 | * Batch modifies an existing entry on the current connection. |
| 399 | * |
| 400 | * @link http://php.net/manual/en/function.ldap-modify-batch.php |
| 401 | * |
| 402 | * @param string $dn |
| 403 | * @param array $values |
| 404 | * |
| 405 | * @return mixed |
| 406 | */ |
| 407 | public function modifyBatch($dn, array $values); |
| 408 | |
| 409 | /** |
| 410 | * Add attribute values to current attributes. |
| 411 | * |
| 412 | * @link http://php.net/manual/en/function.ldap-mod-add.php |
| 413 | * |
| 414 | * @param string $dn |
| 415 | * @param array $entry |
| 416 | * |
| 417 | * @return mixed |
| 418 | */ |
| 419 | public function modAdd($dn, array $entry); |
| 420 | |
| 421 | /** |
| 422 | * Replaces attribute values with new ones. |
| 423 | * |
| 424 | * @link http://php.net/manual/en/function.ldap-mod-replace.php |
| 425 | * |
| 426 | * @param string $dn |
| 427 | * @param array $entry |
| 428 | * |
| 429 | * @return mixed |
| 430 | */ |
| 431 | public function modReplace($dn, array $entry); |
| 432 | |
| 433 | /** |
| 434 | * Delete attribute values from current attributes. |
| 435 | * |
| 436 | * @link http://php.net/manual/en/function.ldap-mod-del.php |
| 437 | * |
| 438 | * @param string $dn |
| 439 | * @param array $entry |
| 440 | * |
| 441 | * @return mixed |
| 442 | */ |
| 443 | public function modDelete($dn, array $entry); |
| 444 | |
| 445 | /** |
| 446 | * Send LDAP pagination control. |
| 447 | * |
| 448 | * @link http://php.net/manual/en/function.ldap-control-paged-result.php |
| 449 | * |
| 450 | * @param int $pageSize |
| 451 | * @param bool $isCritical |
| 452 | * @param string $cookie |
| 453 | * |
| 454 | * @return mixed |
| 455 | */ |
| 456 | public function controlPagedResult($pageSize = 1000, $isCritical = false, $cookie = ''); |
| 457 | |
| 458 | /** |
| 459 | * Retrieve the LDAP pagination cookie. |
| 460 | * |
| 461 | * @link http://php.net/manual/en/function.ldap-control-paged-result-response.php |
| 462 | * |
| 463 | * @param $result |
| 464 | * @param string $cookie |
| 465 | * |
| 466 | * @return mixed |
| 467 | */ |
| 468 | public function controlPagedResultResponse($result, &$cookie); |
| 469 | |
| 470 | /** |
| 471 | * Frees up the memory allocated internally to store the result. |
| 472 | * |
| 473 | * @link https://www.php.net/manual/en/function.ldap-free-result.php |
| 474 | * |
| 475 | * @param resource $result |
| 476 | * |
| 477 | * @return bool |
| 478 | */ |
| 479 | public function freeResult($result); |
| 480 | |
| 481 | /** |
| 482 | * Returns the error number of the last command |
| 483 | * executed on the current connection. |
| 484 | * |
| 485 | * @link http://php.net/manual/en/function.ldap-errno.php |
| 486 | * |
| 487 | * @return int |
| 488 | */ |
| 489 | public function errNo(); |
| 490 | |
| 491 | /** |
| 492 | * Returns the extended error string of the last command. |
| 493 | * |
| 494 | * @return string |
| 495 | */ |
| 496 | public function getExtendedError(); |
| 497 | |
| 498 | /** |
| 499 | * Returns the extended error hex code of the last command. |
| 500 | * |
| 501 | * @return string|null |
| 502 | */ |
| 503 | public function getExtendedErrorHex(); |
| 504 | |
| 505 | /** |
| 506 | * Returns the extended error code of the last command. |
| 507 | * |
| 508 | * @return string |
| 509 | */ |
| 510 | public function getExtendedErrorCode(); |
| 511 | |
| 512 | /** |
| 513 | * Returns the error string of the specified |
| 514 | * error number. |
| 515 | * |
| 516 | * @link http://php.net/manual/en/function.ldap-err2str.php |
| 517 | * |
| 518 | * @param int $number |
| 519 | * |
| 520 | * @return string |
| 521 | */ |
| 522 | public function err2Str($number); |
| 523 | |
| 524 | /** |
| 525 | * Return the diagnostic Message. |
| 526 | * |
| 527 | * @return string |
| 528 | */ |
| 529 | public function getDiagnosticMessage(); |
| 530 | |
| 531 | /** |
| 532 | * Extract the diagnostic code from the message. |
| 533 | * |
| 534 | * @param string $message |
| 535 | * |
| 536 | * @return string|bool |
| 537 | */ |
| 538 | public function extractDiagnosticCode($message); |
| 539 | } |