@@ -20,10 +20,10 @@ You can install the component in 2 different ways:
2020Usage
2121-----
2222
23- The :class: `Symfony\\ Component\\ Ldap\\ LdapClient ` class provides methods
23+ The :class: `Symfony\\ Component\\ Ldap\\ Ldap ` class provides methods
2424to authenticate and query against an LDAP server.
2525
26- The :class: `Symfony\\ Component\\ Ldap\\ LdapClient ` class can be configured
26+ The :class: `Symfony\\ Component\\ Ldap\\ Ldap ` class can be configured
2727using the following options:
2828
2929``host ``
@@ -35,38 +35,95 @@ using the following options:
3535``version ``
3636 The version of the LDAP protocol to use
3737
38- ``useSsl ``
39- Whether or not to secure the connection using SSL
38+ ``encryption ``
39+ Your encryption mechanism (`` ssl ``, `` tls `` or `` none ``)
4040
41- ``useStartTls ``
42- Whether or not to secure the connection using StartTLS
41+ ``connection_string ``
42+ You may use this option instead of
4343
4444``optReferrals ``
4545 Specifies whether to automatically follow referrals
4646 returned by the LDAP server
4747
4848For example, to connect to a start-TLS secured LDAP server::
4949
50- use Symfony\Component\Ldap\LdapClient ;
50+ use Symfony\Component\Ldap\Ldap ;
5151
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+ ));
5356
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
5564authenticates a previously configured connection using both the
5665distinguished name (DN) and the password of a user::
5766
58- use Symfony\Component\Ldap\LdapClient ;
67+ use Symfony\Component\Ldap\Ldap ;
5968 // ...
6069
6170 $ldap->bind($dn, $password);
6271
6372Once bound (or if you enabled anonymous authentication on your
6473LDAP 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::
66104
67- use Symfony\Component\Ldap\LdapClient;
105+ use Symfony\Component\Ldap\Ldap;
106+ use Symfony\Component\Ldap\Entry;
68107 // ...
69108
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('fabpot@symfony.com'));
124+ $em->update($entry);
125+
126+ // Removing an existing entry
127+ $em->remove(new Entry('cn=Test User,dc=symfony,dc=com'));
71128
72129.. _Packagist : https://packagist.org/packages/symfony/ldap
0 commit comments