nusait/nuldap

There is no license information available for the latest version (2.1.4) of this package.

2.1.4 2016-05-11 17:39 UTC

This package is not auto-updated.

Last update: 2024-12-21 16:10:19 UTC


README

This is a LDAP package meant for Northwestern University. (But can be extended for other entities)

Installation via Composer

composer require nusait/nuldap

Then update composer

composer update

New Instance:

$ldap = new Nusait\Nuldap\NuLdap($rdn, $password, $host, $port);

(all parameters are optional); if you do not put $rdn or $password, you can still validate, but cannot searchNetid. After instantiating, you can still set the rdn and password with setRdn and setPassword respectively.

Validate:

$ldap->validate($netid, $password);

returns a boolean

Searching:

You can search by netid, email, emplid, or studentid.

$ldap->search('netid', $netid);
$ldap->search('email', $email);
$ldap->search('emplid', $emplid);
$ldap->search('studentid', $studentid);

This returns the raw ldap metadata.

You can also search using the magic methods:

$ldap->searchNetid($netid);
$ldap->searchEmail($email);
$ldap->searchEmplid($emplid);
$ldap->searchStudentid($studentid);

Parsing User

$ldap->parseUser($ldapUser [, $transformer ]);

You can parse the raw metadata of a user to create an associative array of the user. You can pass your own transformer into the function. The transformer must implement the TransformerInterface in the Contracts folder.

The default transforms maps the following keys and value:

return [
    'netid'       => $this->getSetValueOrNull($ldapUser, 'uid'),
    'phone'       => $this->getSetValueOrNull($ldapUser, 'telephonenumber'),
    'email'       => $this->getSetValueOrNull($ldapUser, 'mail'),
    'title'       => $this->getSetValueOrNull($ldapUser, 'title'),
    'first_name'  => $this->getSetValueOrNull($ldapUser, 'givenname'),
    'last_name'   => $this->getSetValueOrNull($ldapUser, 'sn'),
    'displayname' => $this->getSetValueOrNull($ldapUser, 'displayname'),
    'emplid'      => (int)$this->getSetValueOrNull($ldapUser, 'employeenumber'),
    'studentid'   => (int)$this->getSetValueOrNull($ldapUser, 'nustudentnumber')
];