/**
* 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');
}