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

Commit bfa56c5

Browse files
committed
Catch connection exceptions when creating new providers
1 parent a14d504 commit bfa56c5

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

src/AdldapServiceProvider.php

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Adldap\Auth\BindException;
88
use Adldap\Connections\Provider;
99
use Adldap\Connections\ConnectionInterface;
10+
use Adldap\Connections\ConnectionException;
1011
use Illuminate\Container\Container;
1112
use Illuminate\Support\Facades\Config;
1213
use Illuminate\Support\ServiceProvider;
@@ -95,25 +96,29 @@ protected function addProviders(Adldap $adldap, array $connections = [])
9596
{
9697
// Go through each connection and construct a Provider.
9798
foreach ($connections as $name => $config) {
98-
// Create a new provider.
99-
$provider = $this->newProvider(
100-
$config['settings'],
101-
new $config['connection']
102-
);
103-
104-
if ($this->shouldAutoConnect($config)) {
105-
try {
106-
$provider->connect();
107-
} catch (BindException $e) {
108-
// We'll catch and log bind exceptions so
109-
// any connection issues fail gracefully
110-
// in our application.
111-
logger()->error($e);
99+
try {
100+
// Create a new provider.
101+
$provider = $this->newProvider(
102+
$config['settings'],
103+
new $config['connection']
104+
);
105+
106+
if ($this->shouldAutoConnect($config)) {
107+
try {
108+
$provider->connect();
109+
} catch (BindException $e) {
110+
// We will catch and log bind exceptions so
111+
// any connection issues fail gracefully
112+
// in our application.
113+
logger()->error($e);
114+
}
112115
}
113-
}
114116

115-
// Add the provider to the Adldap container.
116-
$adldap->addProvider($provider, $name);
117+
// Add the provider to the Adldap container.
118+
$adldap->addProvider($provider, $name);
119+
} catch (ConnectionException $e) {
120+
logger()->error($e);
121+
}
117122
}
118123

119124
return $adldap;
@@ -132,9 +137,11 @@ protected function newAdldap()
132137
/**
133138
* Returns a new Provider instance.
134139
*
135-
* @param array $configuration
140+
* @param array $configuration
136141
* @param ConnectionInterface|null $connection
137142
*
143+
* @throws ConnectionException If starting TLS fails.
144+
*
138145
* @return Provider
139146
*/
140147
protected function newProvider($configuration = [], ConnectionInterface $connection = null)

0 commit comments

Comments
 (0)