vendor/symfony/ldap/Ldap.php line 34

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\Ldap;
  11. use Symfony\Component\Ldap\Adapter\AdapterInterface;
  12. use Symfony\Component\Ldap\Adapter\EntryManagerInterface;
  13. use Symfony\Component\Ldap\Adapter\ExtLdap\Adapter;
  14. use Symfony\Component\Ldap\Adapter\QueryInterface;
  15. use Symfony\Component\Ldap\Exception\DriverNotFoundException;
  16. /**
  17.  * @author Charles Sarrazin <charles@sarraz.in>
  18.  */
  19. final class Ldap implements LdapInterface
  20. {
  21.     private AdapterInterface $adapter;
  22.     public function __construct(AdapterInterface $adapter)
  23.     {
  24.         $this->adapter $adapter;
  25.     }
  26.     public function bind(string $dn null, #[\SensitiveParameterstring $password null): void
  27.     {
  28.         $this->adapter->getConnection()->bind($dn$password);
  29.     }
  30.     public function query(string $dnstring $query, array $options = []): QueryInterface
  31.     {
  32.         return $this->adapter->createQuery($dn$query$options);
  33.     }
  34.     public function getEntryManager(): EntryManagerInterface
  35.     {
  36.         return $this->adapter->getEntryManager();
  37.     }
  38.     public function escape(string $subjectstring $ignore ''int $flags 0): string
  39.     {
  40.         return $this->adapter->escape($subject$ignore$flags);
  41.     }
  42.     /**
  43.      * Creates a new Ldap instance.
  44.      *
  45.      * @param string $adapter The adapter name
  46.      * @param array  $config  The adapter's configuration
  47.      */
  48.     public static function create(string $adapter, array $config = []): static
  49.     {
  50.         if ('ext_ldap' !== $adapter) {
  51.             throw new DriverNotFoundException(sprintf('Adapter "%s" not found. Only "ext_ldap" is supported at the moment.'$adapter));
  52.         }
  53.         return new self(new Adapter($config));
  54.     }
  55. }