|
4 | 4 |
|
5 | 5 | use Adldap\Adldap;
|
6 | 6 | use Adldap\AdldapInterface;
|
| 7 | +use Adldap\Auth\BindException; |
7 | 8 | use Adldap\Connections\Provider;
|
8 | 9 | use Adldap\Schemas\SchemaInterface;
|
9 | 10 | use Adldap\Connections\ConnectionInterface;
|
10 | 11 | use Adldap\Laravel\Exceptions\ConfigurationMissingException;
|
11 | 12 | use Illuminate\Container\Container;
|
| 13 | +use Illuminate\Support\Facades\Log; |
12 | 14 | use Illuminate\Support\ServiceProvider;
|
13 | 15 |
|
14 | 16 | class AdldapServiceProvider extends ServiceProvider
|
@@ -93,9 +95,15 @@ protected function addProviders(Adldap $adldap, array $connections = [])
|
93 | 95 | new $settings['schema']
|
94 | 96 | );
|
95 | 97 |
|
96 |
| - // Try connecting to the provider if `auto_connect` is true. |
97 |
| - if (isset($settings['auto_connect']) && $settings['auto_connect'] === true) { |
98 |
| - $provider->connect(); |
| 98 | + if ($this->shouldAutoConnect($settings)) { |
| 99 | + try { |
| 100 | + $provider->connect(); |
| 101 | + } catch (BindException $e) { |
| 102 | + // We'll catch and log bind exceptions so |
| 103 | + // any connection issues fail gracefully |
| 104 | + // in our application. |
| 105 | + Log::error($e); |
| 106 | + } |
99 | 107 | }
|
100 | 108 |
|
101 | 109 | // Add the provider to the Adldap container.
|
@@ -129,6 +137,19 @@ protected function newProvider($configuration = [], ConnectionInterface $connect
|
129 | 137 | return new Provider($configuration, $connection, $schema);
|
130 | 138 | }
|
131 | 139 |
|
| 140 | + /** |
| 141 | + * Determine if the given settings is configured for auto-connecting. |
| 142 | + * |
| 143 | + * @param array $settings |
| 144 | + * |
| 145 | + * @return bool |
| 146 | + */ |
| 147 | + protected function shouldAutoConnect(array $settings) |
| 148 | + { |
| 149 | + return array_key_exists('auto_connect', $settings) |
| 150 | + && $settings['auto_connect'] === true; |
| 151 | + } |
| 152 | + |
132 | 153 | /**
|
133 | 154 | * Determines if the current application is Lumen.
|
134 | 155 | *
|
|
0 commit comments