Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion components/ldap.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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('[email protected]'));
$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