-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLdapWrapper.php
More file actions
103 lines (94 loc) · 1.87 KB
/
Copy pathLdapWrapper.php
File metadata and controls
103 lines (94 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
namespace LdapWrapper;
/**
* Class LdapWrapper
* @package LdapWrapper
*/
class LdapWrapper
{
/**
* Ldap port
*
* @var int
*/
private $_port;
/**
* Ldap protocol version to be used
*
* @var int
*/
private $_protocolVersion;
/**
* bind link
*
* @var resource
*/
private $_link;
/**
* Connect Ldap server using (or not) binding user
*
* @param string $hostname
* @param int $port
* @param array $bindParams
* @param int $protocolVersion
*/
public function __construct($hostname, $port = 389, $bindParams = [], $protocolVersion = 3)
{
$this->setPort($port);
$this->setProtocolVersion($protocolVersion);
$this->connect($hostname, $bindParams);
}
/**
* Port setter
*
* @param int $port
*/
private function setPort($port)
{
$this->_port = $port;
}
/**
* Protocol version setter
*
* @param int $version
*/
private function setProtocolVersion($version)
{
$this->_protocolVersion = $version;
}
/**
* Connect Ldap
*
* @param array $bindParams
*/
private function connect($hostname, array $bindParams)
{
$params = $bindParams + [
'bindDn' => null,
'bindPassword' => null
];
$this->_link = ldap_connect($hostname, $this->_port);
ldap_set_option($this->_link, LDAP_OPT_PROTOCOL_VERSION, $this->_protocolVersion);
ldap_bind($this->_link, $params['bindDn'], $params['bindPassword']);
}
/**
* Ldap search method
*
* @param string $baseDn
* @param string $filter
* @param array $options
* @return array
*/
public function search($baseDn, $filter, array $options = [])
{
extract($options + [
'attributes' => [],
'attrsonly' => null,
'sizelimit' => null,
'timelimit' => null,
'deref' => null,
]);
$query = ldap_search($this->_link, $baseDn, $filter, $attributes, $attrsonly, $sizelimit, $timelimit, $deref);
return ldap_get_entries($this->_link, $query);
}
}