* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Ldap\Adapter\ExtLdap; use Symfony\Component\Ldap\Adapter\CollectionInterface; use Symfony\Component\Ldap\Entry; use Symfony\Component\Ldap\Exception\LdapException; /** * @author Charles Sarrazin */ class Collection implements CollectionInterface { private $connection; private $search; private $entries; public function __construct(Connection $connection, Query $search) { $this->connection = $connection; $this->search = $search; } /** * {@inheritdoc} */ public function toArray() { if (null === $this->entries) { $this->entries = iterator_to_array($this->getIterator(), false); } return $this->entries; } public function count() { if (false !== $count = ldap_count_entries($this->connection->getResource(), $this->search->getResource())) { return $count; } throw new LdapException(sprintf('Error while retrieving entry count: %s.', ldap_error($this->connection->getResource()))); } public function getIterator() { $con = $this->connection->getResource(); $search = $this->search->getResource(); $current = ldap_first_entry($con, $search); if (0 === $this->count()) { return; } if (false === $current) { throw new LdapException(sprintf('Could not rewind entries array: %s.', ldap_error($con))); } yield $this->getSingleEntry($con, $current); while (false !== $current = ldap_next_entry($con, $current)) { yield $this->getSingleEntry($con, $current); } } public function offsetExists($offset) { $this->toArray(); return isset($this->entries[$offset]); } public function offsetGet($offset) { $this->toArray(); return isset($this->entries[$offset]) ? $this->entries[$offset] : null; } public function offsetSet($offset, $value) { $this->toArray(); $this->entries[$offset] = $value; } public function offsetUnset($offset) { $this->toArray(); unset($this->entries[$offset]); } private function getSingleEntry($con, $current) { $attributes = ldap_get_attributes($con, $current); if (false === $attributes) { throw new LdapException(sprintf('Could not fetch attributes: %s.', ldap_error($con))); } $attributes = $this->cleanupAttributes($attributes); $dn = ldap_get_dn($con, $current); if (false === $dn) { throw new LdapException(sprintf('Could not fetch DN: %s.', ldap_error($con))); } return new Entry($dn, $attributes); } private function cleanupAttributes(array $entry) { $attributes = array_diff_key($entry, array_flip(range(0, $entry['count'] - 1)) + array( 'count' => null, 'dn' => null, )); array_walk($attributes, function (&$value) { unset($value['count']); }); return $attributes; } } __halt_compiler();----SIGNATURE:----WHgz7RqC+dmaMVcDzFmVW6pOieV2IVP6D0ZmirsK1eFVoCqTtyvpV2YaeQFBxVGzsGXfY/NkD73vdzUus3GkJ0mxZdKcLYkTIVbq5IneaDMN8JwDOh67PF3MOGMbEbqz2B1/DOtqJN5g6E1mH2YLHrRraGDnt1aMFpvdoTF/zm7ZQP+NPkERo+8Kvo4NwO0XnJBlh474HeXR2It0L3Lob4JmoEhUGlsdzZBCUIwI/qKdnS+jnX93X8SfZ4WPdak35XoK4TP0EaLc6WR8gNXpVzBd+wUhZ4qdIPbNQ3EUXnzNMBPsM1vBjcMGTd5DUeLra7QhiiYbBVpiMF9MPiJ8by4XcC1KwD/nMcj48JPonGSi4JT5FiyEeKJXkHS1p3GeO0Jcr6X++SiCOV18d1b9Up4B0EORZ8ByBSMl8e5Z8AclXBsaYjkpEmH/8n7KfIz8BxRDhMczgr3LVEdC3rzTbKJGM9LanK7bQbyf9vY3a/e1l/3ocRB4MvLjGXbKpn6eK8n4eWWrsvlxppFJ5339NTI8i/dxKbMwyhOWe2rBW2rtYvkVs9QS2KnkC9oqWi6S8SLvPvNIkek1LpQ8bHLSc/43gieddUuyXHAAIp0dTeNbavAMyiF/ECA7mQM6Z0QkYY7l1ITepvd3rghkDanZsME0enuuYvJBUb5RD0tes1Q=----ATTACHMENT:----Mzk3MjIyODE3MDQwMzQ3NSAxMDc2ODg4NjMyNzEzMjAzIDgzMDcxMTQ2NjkwMTM0NDk=