Adldap\Connections\Provider::connect PHP Method

connect() public method

public connect ( $username = null, $password = null )
    public function connect($username = null, $password = null)
    {
        // Get the default guard instance.
        $guard = $this->getGuard();
        if (is_null($username) && is_null($password)) {
            // If both the username and password are null, we'll connect to the server
            // using the configured administrator username and password.
            $guard->bindAsAdministrator();
        } else {
            // Bind to the server with the specified username and password otherwise.
            $guard->bind($username, $password);
        }
        return $this;
    }

Usage Example

 /**
  * Register the service provider.
  */
 public function register()
 {
     // Bind the Adldap instance to the IoC
     $this->app->singleton('adldap', function (Application $app) {
         $config = $app->make('config')->get('adldap');
         // Verify configuration exists.
         if (is_null($config)) {
             $message = 'Adldap configuration could not be found. Try re-publishing using `php artisan vendor:publish --tag="adldap"`.';
             throw new ConfigurationMissingException($message);
         }
         // Create a new connection Manager.
         $manager = new Manager();
         // Retrieve the LDAP connections.
         $connections = $config['connections'];
         // Go through each connection and construct a Provider.
         foreach ($connections as $name => $settings) {
             $configuration = new Configuration($settings['connection_settings']);
             $connection = new $settings['connection']();
             $schema = new $settings['schema']();
             // Construct a new connection Provider with its settings.
             $provider = new Provider($configuration, $connection, $schema);
             if ($settings['auto_connect'] === true) {
                 // Try connecting to the provider if `auto_connect` is true.
                 $provider->connect();
             }
             // Add the Provider to the Manager.
             $manager->add($name, $provider);
         }
         return new Adldap($manager);
     });
     // Bind the Adldap contract to the Adldap object
     // in the IoC for dependency injection.
     $this->app->singleton(AdldapInterface::class, 'adldap');
 }