Skip to content

Furgas/Ldap-Core

 
 

Repository files navigation

Ldap Core

Build Status Built with GNU Make

Object-oriented implementation of PHP's native ldap functions

About

This small library provides access to ldap functions in a nice, object-oriented implementation. Additionally, you can use some mocking library to actually test your ldap interactions.

Installation

Requirements

Support for ldap_modify_batch and ldap_escape are also available as long as they are present in your current PHP version.

  • ldap_modify_batch - available in PHP 5.4 branch since 5.4.26 and in higher versions of PHP since 5.5.10
  • ldap_escape - available since PHP 5.6.0

Via Composer

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

Installing on Travis-CI

Since Composer will not allow you to install a library on a system which does not meet the system requirements listed in composer.json, it is necessary that you enable the ldap extension before invoking composer install, i.e. in the before_install build lifecycle:

echo "extension=ldap.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini

See the Travis docs for detailed information.

Usage

There are two classes - Dreamscapes\Ldap\Core\Ldap and Dreamscapes\Ldap\Core\Result, each of which implement part of the native ldap functions as instance methods (some functions which do not operate on the resource objects are static). The differentiating principle is simple - if the function deals with the state of the ldap connection, it is implemented in the first, whereas functions dealing with the data returned from ldap server (the result resource) are implemented in the latter class.

Deviations

All methods are named as close to the original functions as possible, although with some improvements:

  1. Ldap v3 protocol is used by default
  2. The ldap_ prefix is removed from all method names
  3. The method names are camelCased instead of underscore_based
  4. All methods return data by returning them and not by populating variables passed as references
  5. Some functions are not implemented (usually because they are redundant)
  6. Exceptions are thrown if the ldap protocol encounters an error, and standard PHP warnings and errors are suppressed in most cases

Example

// Load Composer's autoload script...
include 'vendor/autoload.php';

// Import the class into current namespace
use Dreamscapes\Ldap\Core\Ldap;

// If ldap URI is provided, the Ldap instance will also open the connection
// via ldap_connect()
$con = new Ldap('ldap:https://example.com');
$con->bind('[email protected]', 'my pass'); // Example AD credentials

// Read the rootDSE entry
$res = $con->read('', 'objectclass=*', ['*']);

// $res is now instance of Result class
echo "Number of entries in resultset: " . $res->countEntries();
print_r($res->getEntries());

Documentation

Online API documentation is available here. To generate API documentation offline:

git clone https://github.com/Dreamscapes/Ldap-Core.git
cd Ldap-Core
composer install
make docs

Documentation is now available at ./docs/index.html

License

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

About

Object encapsulation of PHP's native ldap functions

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 90.7%
  • Makefile 9.3%