dev-master
9999999-dev
MIT
The Requires
- php >=5.4
The Development Requires
by Maxime Macameau
ldap_orm
Wallogit.com
2017 © Pedro Peláez
LDAP ORM is a simple PHP Library that makes searching for records in LDAP and saving or updating easier. It is inspired by CakePHP/Rails and supports both 'hasMany' and 'belongsTo' associations. It also supports 'findBy{Attribute}' and 'findAllBy{Attribute}' functions for quick retrieval of records., (*1)
Find All Records with cn=TestGroup, (*2)
require('LDAP_ORM.php');
$ldap = new LDAP_ORM('example.com');
$ldap->bind('cn=admin,dc=example,dc=com', 'password');
$res = $ldap->find('all', array('conditions' => "cn=testGroup"), 'ou=Groups,dc=example,dc=com');
Alternatively the above query can be written using the findAllBy magic method:, (*3)
require('LDAP_ORM.php');
$ldap = new LDAP_ORM('example.com');
$ldap->bind('cn=admin,dc=example,dc=com', 'password');
$res = $ldap->findAllByCn("testGroup", 'ou=Groups,dc=example,dc=com');
The results above both examples will return as, (*4)
(
[0] => Array
(
[Groups] => Array
(
[cn] => testGroup
[objectclass] => Array
(
[0] => groupOfNames
[1] => top
)
[member] => Array
(
[0] => cn=TestUser,ou=People,dc=example,dc=com
[1] => cn=Test3,ou=People,dc=example,dc=com
)
[dn] => cn=testGroup,ou=Groups,dc=example,dc=com
)
)
)
)
To search using the hasMany association such as finding a Group where cn=testGroup and find all the People that are listed in the members multi-attribute use the following format:, (*5)
require('LDAP_ORM.php');
$ldap = new LDAP_ORM('example.com');
$ldap->bind('cn=admin,dc=example,dc=com', 'password');
$res = $ldap->find('first', array('conditions' => "cn=testGroup"
'hasMany' => array(
'on' => array('member' => 'dn'),
'fields' => array(),
'base' => 'ou=People,dc=example,dc=com')
), 'ou=Groups,dc=example,dc=com');
the 'on' array uses the format array('{FoundResultAttribute}' => '{AttributeToSearchForInJoinedResults}'), (*6)
the Result of this would look like:, (*7)
Array
(
[0] => Array
(
[Groups] => Array
(
[cn] => testGroup
[objectclass] => Array
(
[0] => groupOfNames
[1] => top
)
[member] => Array
(
[0] => cn=TestUser,ou=People,dc=example,dc=com
[1] => cn=Test3,ou=People,dc=example,dc=com
)
[dn] => cn=testGroup,ou=Groups,dc=example,dc=com
)
[People] => Array
(
[0] => Array
(
[sn] => Test
[cn] => TestUser
[objectclass] => Array
(
[0] => person
[1] => top
)
[dn] => cn=TestUser,ou=People,dc=example,dc=com
)
[1] => Array
(
[cn] => Test3
[objectclass] => Array
(
[0] => person
[1] => top
)
[sn] => dsfsdfsd
[dn] => cn=Test3,ou=People,dc=example,dc=com
)
)
)
)
to use the BelongsTo option:, (*8)
require('LDAP_ORM.php');
$ldap = new LDAP_ORM('example.com');
$ldap->bind('cn=admin,dc=example,dc=com', 'password');
$g = $ldap->find('all', array('conditions' => "cn=Test2",
'belongsTo' => array(
'on' => array('groupdn' => 'dn'),
'base' => 'ou=Groups,dc=example,dc=com')
), 'ou=People,dc=example,dc=com');
See Examples.md, (*9)
LDAP ORM is Licensed under the Creative Commons Attribution 3.0 license http://creativecommons.org/licenses/by/3.0/us/, (*10)
Please use GitHub Issues to submit any problems found, (*11)
MIT
ldap_orm