alaneor/ldap

This package is abandoned and no longer maintained. The author suggests using the dreamscapes/ldap-core package instead.

A simple class encapsulation of php's ldap functions

0.4.1 2013-10-28 17:29 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:26:54 UTC


README

This library provides a class encapsulation of php's ldap functions. This might be very useful for mocking during unit testing or if you simply prefer the beauty of OOP.

DEPRECATION NOTICE

This library is no longer maintained and its usage is discouraged. As a replacement, please take a look at Dreamscapes/Ldap-Core which offers similar functionality.

Features

  • Class Ldap\Ldap provides function encapsulation of all important php ldap_* functions
  • Class Ldap\Option provides you with a known ldap options as class constants
  • Class Ldap\Response provides a nice way to handle server responses
  • Class Ldap\ResponseCode defines most of the known server response codes for you to use in your implementations

Installation

Requirements

Via Composer

composer require alaneor/ldap:dev-master
( visit Packagist for list of all available versions )

Documentation

You use the Ldap\Ldap class to connect to an ldap server. Simply construct the instance with the proper server hostname/IP address and optional port ( default is 389 ) and then use any of the below described functions to work with the connection.

Example code

// Include Composer's autoloader
include 'vendor/autoload.php';

// Open the ldap connection
$link = new Ldap\Ldap( 'example.com', 389 );

// Authenticate the connection with the Admin account
$link->bind( 'CN=Admin,DC=example,DC=com', 'MySecretPwd!' );

// List the items that are in the baseDN
$response = $link->ldap_list( 'DC=example,DC=com', 'objectclass=*', ['name', 'objectclass'] );

// Take a look at the structure of the Ldap\Response instance
print_r( $response );

Method naming

There are a few rules that generally apply to the method names and their parameters.

  1. A method's name is the function's name, stripped of the leading ldap_ prefix. Where a syntax error would occur ( e.g. ldap_list -> list or ldap_8859_to_t61 -> 8859_to_t61 ) the prefix is kept.
  2. The resource $link_identifier parameter is omitted in all situations ( the link identifier is stored in the instance of Ldap\Ldap class ).
  3. Where a resource $result_identifier is expected, you pass an instance of Ldap\Response class ( e.g. in the Ldap\Ldap::sort() method ) that is returned for all ldap method calls.
  4. For all other function parameters and its default values, standard php documentation applies.

There are two exceptions to the above naming rules:

The pagination control request is even shorter, for your convenience:
ldap_control_paged_result -> Ldap\Ldap::paged_result()

Since list cannot be used as method name, all lookup functions are defined with their prefixes to keep them consistent:
ldap_search -> Ldap\Ldap::ldap_search()
ldap_list -> Ldap\Ldap::ldap_list()
ldap_read -> Ldap\Ldap::ldap_read()

Defined methods:

Here's a list of methods you can use.

Class methods

Class methods do not return an instance of Ldap\Response but directly the output of the mapped function.

  • Ldap\Ldap::dn2ufn()
  • Ldap\Ldap::err2str()
  • Ldap\Ldap::explode_dn()
  • Ldap\Ldap::ldap_8859_to_t61()
  • Ldap\Ldap::t61_to_8859()
Instance methods
  • Ldap\Ldap::resource() -> get the ldap resource identifier
  • Ldap\Ldap::rootDSE() -> read the rootDSE entry of the ldap server
  • Ldap\Ldap::add()
  • Ldap\Ldap::bind()
  • Ldap\Ldap::compare()
  • Ldap\Ldap::delete()
  • Ldap\Ldap::get_option()
  • Ldap\Ldap::ldap_list()
  • Ldap\Ldap::ldap_read()
  • Ldap\Ldap::ldap_search()
  • Ldap\Ldap::mod_add()
  • Ldap\Ldap::mod_del()
  • Ldap\Ldap::mod_replace()
  • Ldap\Ldap::modify()
  • Ldap\Ldap::paged_result()
  • Ldap\Ldap::rename()
  • Ldap\Ldap::sasl_bind()
  • Ldap\Ldap::set_option()
  • Ldap\Ldap::set_rebind_proc()
  • Ldap\Ldap::sort()
  • Ldap\Ldap::start_tls()
  • Ldap\Ldap::unbind()

Response structure

Each method call returns new instance of the Ldap\Response class.

The structure of the response is as follows:

  • Ldap\Response::result - Whatever the ldap function returned, either a boolean, a resource or anything else
  • Ldap\Response::data - If a function returned a resource, the actual ldap data will be already extracted here
  • Ldap\Response::code - The ldap response code of the operation performed
  • Ldap\Response::message - The ldap response message that corresponds to the response code
  • Ldap\Response::referrals - If the server responds with referrals, you will find them here
  • Ldap\Response::cookie - For paged result responses, a cookie will be here, if returned from server
  • Ldap\Response::estimated - The estimated number of objects remaining to return from server when doing paged searches ( not all ldap implementations return this value )
  • Ldap\Response::matchedDN - Not much is known here; read php's documentation about ldap_parse_result()

Not all properties have values in all situations - some of them are only present when doing specific actions, like the cookie - it will only be present when pagination is enabled, a lookup operation has been executed and the server returned a cookie.

License

This software is licensed under the BSD (3-Clause) License. See the LICENSE file for more information.