From d428f8d7c6f1782a8ebbe163dc8c1495b4a15b43 Mon Sep 17 00:00:00 2001 From: Charles Sarrazin Date: Mon, 19 Sep 2016 19:54:27 +0200 Subject: [PATCH] Updated LDAP documentation for Symfony 3.1 --- components/ldap.rst | 48 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/components/ldap.rst b/components/ldap.rst index 355f49914ef..ceeaab78f0d 100644 --- a/components/ldap.rst +++ b/components/ldap.rst @@ -73,6 +73,52 @@ LDAP server), you may query the LDAP server using the // ... - $ldap->query('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))'); + $query = $ldap->query('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))'); + $results = $query->execute(); + + foreach ($results as $entry) { + // Do something with the results + } + +By default, LDAP entries are lazy-loaded. If you wish to fetch +all entries in a single call and do something with the results' +array, you may use the +:method:`Symfony\\Component\\Ldap\\Adapter\\ExtLdap\\Collection::toArray` method:: + + // ... + + $query = $ldap->query('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))'); + $results = $query->execute()->toArray(); + + // Do something with the results array + +Creating or updating entries +---------------------------- + +Since version 3.1, The Ldap component provides means to create +new LDAP entries, update or even delete existing ones:: + + use Symfony\Component\Ldap\Entry; + // ... + + $entry = new Entry('cn=Fabien Potencier,dc=symfony,dc=com', array( + 'sn' => array('fabpot'), + 'objectClass' => array('inetOrgPerson'), + )); + + $em = $ldap->getEntryManager(); + + // Creating a new entry + $em->add($entry); + + // Finding and updating an existing entry + $query = $ldap->query('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))'); + $result = $query->execute(); + $entry = $result[0]; + $entry->addAttribute('email', array('fabpot@symfony.com')); + $em->update($entry); + + // Removing an existing entry + $em->remove(new Entry('cn=Test User,dc=symfony,dc=com')); .. _Packagist: https://packagist.org/packages/symfony/ldap