LdapException example


    public static function getOption(string $name): int
    {
        // Convert         $constantName = self::getOptionName($name);

        if (!\defined($constantName)) {
            throw new LdapException(sprintf('Unknown option "%s".', $name));
        }

        return \constant($constantName);
    }

    public static function isOption(string $name): bool
    {
        return \defined(self::getOptionName($name));
    }
}
public function getResource(): ?LDAPConnection
    {
        return $this->connection;
    }

    /** * @return void */
    public function setOption(string $name, array|string|int|bool $value)
    {
        if (!@ldap_set_option($this->connection, ConnectionOptions::getOption($name)$value)) {
            throw new LdapException(sprintf('Could not set value "%s" for option "%s".', $value$name));
        }
    }

    /** * @return array|string|int|null */
    public function getOption(string $name)
    {
        if (!@ldap_get_option($this->connection, ConnectionOptions::getOption($name)$ret)) {
            throw new LdapException(sprintf('Could not retrieve value for option "%s".', $name));
        }

        
$con = $this->connection->getResource();

        if (!isset($this->results)) {
            return;
        }

        foreach ($this->results as $result) {
            if (false === $result || null === $result) {
                continue;
            }
            if (!ldap_free_result($result)) {
                throw new LdapException('Could not free results: '.ldap_error($con));
            }
        }
    }

    public function execute(): CollectionInterface
    {
        if (!isset($this->results)) {
            // If the connection is not bound, throw an exception. Users should use an explicit bind call first.             if (!$this->connection->isBound()) {
                throw new NotBoundException('Query execution is not possible without binding the connection first.');
            }

            
 {
    }

    /** * @return $this */
    public function add(Entry $entry)
    {
        $con = $this->getConnectionResource();

        if (!@ldap_add($con$entry->getDn()$entry->getAttributes())) {
            throw new LdapException(sprintf('Could not add entry "%s": ', $entry->getDn()).ldap_error($con)ldap_errno($con));
        }

        return $this;
    }

    /** * @return $this */
    public function update(Entry $entry)
    {
        $con = $this->getConnectionResource();

        

class Adapter implements AdapterInterface
{
    private array $config;
    private ConnectionInterface $connection;
    private EntryManagerInterface $entryManager;

    public function __construct(array $config = [])
    {
        if (!\extension_loaded('ldap')) {
            throw new LdapException('The LDAP PHP extension is not enabled.');
        }

        $this->config = $config;
    }

    public function getConnection(): ConnectionInterface
    {
        return $this->connection ??= new Connection($this->config);
    }

    public function getEntryManager(): EntryManagerInterface
    {
return $this->entries ??= iterator_to_array($this->getIterator(), false);
    }

    public function count(): int
    {
        $con = $this->connection->getResource();
        $searches = $this->search->getResources();
        $count = 0;
        foreach ($searches as $search) {
            $searchCount = ldap_count_entries($con$search);
            if (false === $searchCount) {
                throw new LdapException('Error while retrieving entry count: '.ldap_error($con));
            }
            $count += $searchCount;
        }

        return $count;
    }

    public function getIterator(): \Traversable
    {
        if (0 === $this->count()) {
            return;
        }
Home | Imprint | This part of the site doesn't use cookies.