@@ -73,6 +73,52 @@ LDAP server), you may query the LDAP server using the
73
73
74
74
// ...
75
75
76
- $ldap->query('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))');
76
+ $query = $ldap->query('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))');
77
+ $results = $query->execute();
78
+
79
+ foreach ($results as $entry) {
80
+ // Do something with the results
81
+ }
82
+
83
+ By default, LDAP entries are lazy-loaded. If you wish to fetch
84
+ all entries in a single call and do something with the results'
85
+ array, you may use the
86
+ :method: `Symfony\\ Component\\ Ldap\\ Adapter\\ ExtLdap\\ Collection::toArray ` method::
87
+
88
+ // ...
89
+
90
+ $query = $ldap->query('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))');
91
+ $results = $query->execute()->toArray();
92
+
93
+ // Do something with the results array
94
+
95
+ Creating or updating entries
96
+ ----------------------------
97
+
98
+ Since version 3.1, The Ldap component provides means to create
99
+ new LDAP entries, update or even delete existing ones::
100
+
101
+ use Symfony\Component\Ldap\Entry;
102
+ // ...
103
+
104
+ $entry = new Entry('cn=Fabien Potencier,dc=symfony,dc=com', array(
105
+ 'sn' => array('fabpot'),
106
+ 'objectClass' => array('inetOrgPerson'),
107
+ ));
108
+
109
+ $em = $ldap->getEntryManager();
110
+
111
+ // Creating a new entry
112
+ $em->add($entry);
113
+
114
+ // Finding and updating an existing entry
115
+ $query = $ldap->query('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))');
116
+ $result = $query->execute();
117
+ $entry = $result[0];
118
+ $entry->addAttribute('email', array('fabpot@symfony.com'));
119
+ $em->update($entry);
120
+
121
+ // Removing an existing entry
122
+ $em->remove(new Entry('cn=Test User,dc=symfony,dc=com'));
77
123
78
124
.. _Packagist : https://packagist.org/packages/symfony/ldap
0 commit comments