LdapTools\LdapManager::getConnection PHP Метод

getConnection() публичный Метод

Get the Ldap Connection object. By default it will get the connection of the domain currently in context. To get a different domain connection pass the domain name as a parameter.
public getConnection ( null | string $domain = null ) : LdapTools\Connection\LdapConnectionInterface
$domain null | string
Результат LdapTools\Connection\LdapConnectionInterface
    public function getConnection($domain = null)
    {
        $domain = $domain ?: $this->context;
        $this->validateDomainName($domain);
        if (!$this->connections[$domain]) {
            $this->connections[$domain] = new LdapConnection($this->domains[$domain], $this->config->getEventDispatcher(), $this->config->getLogger());
        }
        return $this->connections[$domain];
    }

Usage Example

 /**
  * @param \Symfony\Component\Security\Core\User\UserProviderInterface $userProvider
  * @param \LdapTools\Bundle\LdapToolsBundle\Security\User\LdapUserChecker $userChecker
  * @param \LdapTools\LdapManager $ldap
  * @param \Symfony\Component\Security\Core\Authentication\Token\TokenInterface $token
  * @param \LdapTools\Bundle\LdapToolsBundle\Security\User\LdapUser $user
  * @param \LdapTools\Connection\LdapConnectionInterface $connection
  * @param \LdapTools\Operation\AuthenticationResponse $response
  * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher
  */
 function let($userProvider, $userChecker, $ldap, $token, $user, $connection, $response, $dispatcher)
 {
     $this->userProvider = $userProvider;
     $this->userChecker = $userChecker;
     $this->ldap = $ldap;
     $this->token = $token;
     $this->user = $user;
     $this->connection = $connection;
     $this->operation = (new AuthenticationOperation())->setUsername('foo')->setPassword('bar');
     $this->response = $response;
     $this->dispatcher = $dispatcher;
     $token->getUsername()->willReturn('foo');
     $token->getCredentials()->willReturn('bar');
     $token->hasAttribute('ldap_domain')->willReturn(false);
     $token->getAttributes()->willReturn([]);
     $this->userProvider->loadUserByUsername('foo')->willReturn($user);
     $this->connection->getConfig()->willReturn(new DomainConfiguration('foo.bar'));
     $this->connection->execute($this->operation)->willReturn($this->response);
     $this->response->isAuthenticated()->willReturn(true);
     $this->ldap->getConnection()->willReturn($this->connection);
     $this->ldap->getDomainContext()->willReturn('foo.bar');
     $this->user->getUsername()->willReturn('foo');
     $this->user->getRoles()->willReturn(['ROLE_USER']);
     $this->user->isAccountNonLocked()->willReturn(true);
     $this->user->isEnabled()->willReturn(true);
     $this->user->isAccountNonExpired()->willReturn(true);
     $this->user->isCredentialsNonExpired()->willReturn(true);
     $this->beConstructedWith('restricted', true, $this->userProvider, new LdapUserChecker(), $this->ldap, $this->dispatcher);
 }
All Usage Examples Of LdapTools\LdapManager::getConnection