https://github.com/robertrossmann/ldap
DEPRECATED - use https://github.com/Dreamscapes/Ldap-Core instead
https://github.com/robertrossmann/ldap
Last synced: 8 months ago
JSON representation
DEPRECATED - use https://github.com/Dreamscapes/Ldap-Core instead
- Host: GitHub
- URL: https://github.com/robertrossmann/ldap
- Owner: robertrossmann
- License: bsd-3-clause
- Archived: true
- Created: 2013-08-30T22:56:09.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2014-08-31T13:04:59.000Z (almost 12 years ago)
- Last Synced: 2025-02-10T04:43:55.757Z (over 1 year ago)
- Language: PHP
- Homepage:
- Size: 318 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Ldap :: Object encapsulation of php's 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
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
- 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
- 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
`composer require alaneor/ldap:dev-master`
( visit [Packagist](https://packagist.org/packages/alaneor/ldap) 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
```php
// 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.
1. The `resource $link_identifier` parameter is omitted in all situations ( the link identifier is stored in the instance of `Ldap\Ldap` class ).
1. 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.
1. 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()](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
This software is licensed under the **BSD (3-Clause) License**.
See the [LICENSE](LICENSE) file for more information.