@@ -20,10 +20,10 @@ You can install the component in 2 different ways:
20
20
Usage
21
21
-----
22
22
23
- The :class: `Symfony\\ Component\\ Ldap\\ LdapClient ` class provides methods
23
+ The :class: `Symfony\\ Component\\ Ldap\\ Ldap ` class provides methods
24
24
to authenticate and query against an LDAP server.
25
25
26
- The :class: `Symfony\\ Component\\ Ldap\\ LdapClient ` class can be configured
26
+ The :class: `Symfony\\ Component\\ Ldap\\ Ldap ` class can be configured
27
27
using the following options:
28
28
29
29
``host ``
@@ -35,38 +35,95 @@ using the following options:
35
35
``version ``
36
36
The version of the LDAP protocol to use
37
37
38
- ``useSsl ``
39
- Whether or not to secure the connection using SSL
38
+ ``encryption ``
39
+ Your encryption mechanism (`` ssl ``, `` tls `` or `` none ``)
40
40
41
- ``useStartTls ``
42
- Whether or not to secure the connection using StartTLS
41
+ ``connection_string ``
42
+ You may use this option instead of
43
43
44
44
``optReferrals ``
45
45
Specifies whether to automatically follow referrals
46
46
returned by the LDAP server
47
47
48
48
For example, to connect to a start-TLS secured LDAP server::
49
49
50
- use Symfony\Component\Ldap\LdapClient ;
50
+ use Symfony\Component\Ldap\Ldap ;
51
51
52
- $ldap = new LdapClient('my-server', 389, 3, false, true);
52
+ $ldap = Ldap::create('ext_ldap', array(
53
+ 'host' => 'my-server',
54
+ 'encryption' => 'ssl',
55
+ ));
53
56
54
- The :method: `Symfony\\ Component\\ Ldap\\ LdapClient::bind ` method
57
+ Or you could directly specify a connection string::
58
+
59
+ use Symfony\Component\Ldap\Ldap;
60
+
61
+ $ldap = Ldap::create('ext_ldap', array('connection_string' => 'ldaps://my-server:636'));
62
+
63
+ The :method: `Symfony\\ Component\\ Ldap\\ Ldap::bind ` method
55
64
authenticates a previously configured connection using both the
56
65
distinguished name (DN) and the password of a user::
57
66
58
- use Symfony\Component\Ldap\LdapClient ;
67
+ use Symfony\Component\Ldap\Ldap ;
59
68
// ...
60
69
61
70
$ldap->bind($dn, $password);
62
71
63
72
Once bound (or if you enabled anonymous authentication on your
64
73
LDAP server), you may query the LDAP server using the
65
- :method: `Symfony\\ Component\\ Ldap\\ LdapClient::find ` method::
74
+ :method: `Symfony\\ Component\\ Ldap\\ Ldap::query ` method::
75
+
76
+ use Symfony\Component\Ldap\Ldap;
77
+ // ...
78
+
79
+ $query = $ldap->query('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))');
80
+ $results = $query->execute();
81
+
82
+ foreach ($results as $entry) {
83
+ // Do something with the results
84
+ }
85
+
86
+ By default, LDAP entries are lazy-loaded. If you wish to fetch
87
+ all entries in a single call and do something with the results'
88
+ array, you may use the
89
+ :method: `Symfony\\ Component\\ Ldap\\ Adapter\\ ExtLdap\\ Collection::toArray ` method::
90
+
91
+ use Symfony\Component\Ldap\Ldap;
92
+ // ...
93
+
94
+ $query = $ldap->query('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))');
95
+ $results = $query->execute()->toArray();
96
+
97
+ // Do something with the results array
98
+
99
+ Creating or updating entries
100
+ ----------------------------
101
+
102
+ Since version 3.1, The Ldap component provides means to create
103
+ new LDAP entries, update or even delete existing ones::
66
104
67
- use Symfony\Component\Ldap\LdapClient;
105
+ use Symfony\Component\Ldap\Ldap;
106
+ use Symfony\Component\Ldap\Entry;
68
107
// ...
69
108
70
- $ldap->find('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))');
109
+ $entry = new Entry('cn=Fabien Potencier,dc=symfony,dc=com', array(
110
+ 'sn' => array('fabpot'),
111
+ 'objectClass' => array('inetOrgPerson'),
112
+ ));
113
+
114
+ $em = $ldap->getEntryManager();
115
+
116
+ // Creating a new entry
117
+ $em->add($entry);
118
+
119
+ // Finding and updating an existing entry
120
+ $query = $ldap->query('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))');
121
+ $result = $query->execute();
122
+ $entry = $result[0];
123
+ $entry->addAttribute('email', array('[email protected] '));
124
+ $em->update($entry);
125
+
126
+ // Removing an existing entry
127
+ $em->remove(new Entry('cn=Test User,dc=symfony,dc=com'));
71
128
72
129
.. _Packagist : https://packagist.org/packages/symfony/ldap
0 commit comments