|
5 | 5 | use Adldap\Adldap; |
6 | 6 | use Adldap\Connections\Provider; |
7 | 7 | use Adldap\Contracts\AdldapInterface; |
| 8 | +use Adldap\Contracts\Connections\ConnectionInterface; |
| 9 | +use Adldap\Contracts\Schemas\SchemaInterface; |
8 | 10 | use Adldap\Laravel\Exceptions\ConfigurationMissingException; |
9 | 11 | use Illuminate\Contracts\Foundation\Application; |
10 | 12 | use Illuminate\Support\ServiceProvider; |
@@ -45,7 +47,7 @@ public function register() |
45 | 47 | throw new ConfigurationMissingException($message); |
46 | 48 | } |
47 | 49 |
|
48 | | - return $this->addProviders(new Adldap(), $config['connections']); |
| 50 | + return $this->addProviders($this->newAdldap(), $config['connections']); |
49 | 51 | }); |
50 | 52 |
|
51 | 53 | // Bind the Adldap contract to the Adldap object |
@@ -76,21 +78,45 @@ public function provides() |
76 | 78 | protected function addProviders(Adldap $adldap, array $connections = []) |
77 | 79 | { |
78 | 80 | // 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 | + ); |
85 | 87 |
|
86 | 88 | if ($settings['auto_connect'] === true) { |
87 | 89 | // Try connecting to the provider if `auto_connect` is true. |
88 | 90 | $provider->connect(); |
89 | 91 | } |
90 | 92 |
|
91 | 93 | $adldap->addProvider($name, $provider); |
92 | | - } |
| 94 | + }); |
93 | 95 |
|
94 | 96 | return $adldap; |
95 | 97 | } |
| 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 | + } |
96 | 122 | } |
0 commit comments