PHPackages                             alaneor/ldap - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. alaneor/ldap

Abandoned → [dreamscapes/ldap-core](/?search=dreamscapes%2Fldap-core)ArchivedLibrary[Testing &amp; Quality](/categories/testing)

alaneor/ldap
============

A simple class encapsulation of php's ldap functions

0.4.1(12y ago)461BSD-3-ClausePHPPHP &gt;=5.4.0

Since Aug 30Pushed 11y ago1 watchersCompare

[ Source](https://github.com/Alaneor/Ldap)[ Packagist](https://packagist.org/packages/alaneor/ldap)[ RSS](/packages/alaneor-ldap/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (7)Dependencies (1)Versions (9)Used By (0)

Ldap :: Object encapsulation of php's ldap functions
====================================================

[](#ldap--object-encapsulation-of-phps-ldap-functions)

> 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
------------------

[](#deprecation-notice)

This library is no longer maintained and its usage is discouraged. As a replacement, please take a look at [Dreamscapes/Ldap-Core](https://github.com/Dreamscapes/Ldap-Core) which offers similar functionality.

Features
--------

[](#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
------------

[](#installation)

### Requirements

[](#requirements)

- PHP 5.4.0 and newer with LDAP support ( [setup instructions](http://www.php.net/manual/en/ldap.installation.php) )
- OpenSSL module for SSL / TLS connections ( [setup instructions](http://www.php.net/manual/en/openssl.installation.php) )

#### Via Composer

[](#via-composer)

`composer require alaneor/ldap:dev-master`
( visit [Packagist](https://packagist.org/packages/alaneor/ldap) for list of all available versions )

Documentation
-------------

[](#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

[](#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

[](#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* -&gt; *list* or *ldap\_8859\_to\_t61* -&gt; *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` -&gt; `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` -&gt; `Ldap\Ldap::ldap_search()`
`ldap_list` -&gt; `Ldap\Ldap::ldap_list()`
`ldap_read` -&gt; `Ldap\Ldap::ldap_read()`

#### Defined methods:

[](#defined-methods)

Here's a list of methods you can use.

##### Class methods

[](#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

[](#instance-methods)

- `Ldap\Ldap::resource()` -&gt; get the ldap resource identifier
- `Ldap\Ldap::rootDSE()` -&gt; 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

[](#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()](http://www.php.net/manual/en/function.ldap-parse-result.php)

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
-------

[](#license)

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

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~9 days

Total

7

Last Release

4581d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4300d8bf145f9d0db6e15c90199842aad7541376402c2fc2ee86539631100bc4?d=identicon)[Alaneor](/maintainers/Alaneor)

---

Top Contributors

[![robertrossmann](https://avatars.githubusercontent.com/u/3058150?v=4)](https://github.com/robertrossmann "robertrossmann (48 commits)")

---

Tags

mockobjectldapactive directoryopenldapOOP

### Embed Badge

![Health badge](/badges/alaneor-ldap/health.svg)

```
[![Health](https://phpackages.com/badges/alaneor-ldap/health.svg)](https://phpackages.com/packages/alaneor-ldap)
```

###  Alternatives

[mockery/mockery

Mockery is a simple yet flexible PHP mock object framework

10.7k497.0M23.6k](/packages/mockery-mockery)[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/packages/phpspec-prophecy)[php-mock/php-mock

PHP-Mock can mock built-in PHP functions (e.g. time()). PHP-Mock relies on PHP's namespace fallback policy. No further extension is needed.

36918.1M98](/packages/php-mock-php-mock)[brain/monkey

Mocking utility for PHP functions and WordPress plugin API

33412.5M350](/packages/brain-monkey)[ldaptools/ldaptools

LdapTools is a feature-rich LDAP library for PHP 5.6+.

204263.9k1](/packages/ldaptools-ldaptools)[colinodell/psr-testlogger

PSR-3 compliant test logger based on psr/log v1's, but compatible with v2 and v3 too!

1712.1M47](/packages/colinodell-psr-testlogger)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
