Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Commit 01f7a50

Browse files
committed
Added more methods for extensibility.
1 parent 6aef5f2 commit 01f7a50

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

src/AdldapServiceProvider.php

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use Adldap\Adldap;
66
use Adldap\Connections\Provider;
77
use Adldap\Contracts\AdldapInterface;
8+
use Adldap\Contracts\Connections\ConnectionInterface;
9+
use Adldap\Contracts\Schemas\SchemaInterface;
810
use Adldap\Laravel\Exceptions\ConfigurationMissingException;
911
use Illuminate\Contracts\Foundation\Application;
1012
use Illuminate\Support\ServiceProvider;
@@ -45,7 +47,7 @@ public function register()
4547
throw new ConfigurationMissingException($message);
4648
}
4749

48-
return $this->addProviders(new Adldap(), $config['connections']);
50+
return $this->addProviders($this->newAdldap(), $config['connections']);
4951
});
5052

5153
// Bind the Adldap contract to the Adldap object
@@ -76,21 +78,45 @@ public function provides()
7678
protected function addProviders(Adldap $adldap, array $connections = [])
7779
{
7880
// Go through each connection and construct a Provider.
79-
foreach ($connections as $name => $settings) {
80-
$connection = new $settings['connection']();
81-
$schema = new $settings['schema']();
82-
83-
// Construct a new connection Provider with its settings.
84-
$provider = new Provider($settings['connection_settings'], $connection, $schema);
81+
collect($connections)->each(function ($settings, $name) use ($adldap) {
82+
$provider = $this->newProvider(
83+
$settings['connection_settings'],
84+
new $settings['connection'],
85+
new $settings['schema']
86+
);
8587

8688
if ($settings['auto_connect'] === true) {
8789
// Try connecting to the provider if `auto_connect` is true.
8890
$provider->connect();
8991
}
9092

9193
$adldap->addProvider($name, $provider);
92-
}
94+
});
9395

9496
return $adldap;
9597
}
98+
99+
/**
100+
* Returns a new Adldap instance.
101+
*
102+
* @return Adldap
103+
*/
104+
protected function newAdldap()
105+
{
106+
return new Adldap();
107+
}
108+
109+
/**
110+
* Returns a new Provider instance.
111+
*
112+
* @param array $configuration
113+
* @param ConnectionInterface|null $connection
114+
* @param SchemaInterface|null $schema
115+
*
116+
* @return Provider
117+
*/
118+
protected function newProvider($configuration = [], ConnectionInterface $connection = null, SchemaInterface $schema = null)
119+
{
120+
return new Provider($configuration, $connection, $schema);
121+
}
96122
}

0 commit comments

Comments
 (0)