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

Commit f9a825a

Browse files
committed
Small tweaks and optimizations.
1 parent 475104a commit f9a825a

File tree

4 files changed

+37
-35
lines changed

4 files changed

+37
-35
lines changed

src/AdldapServiceProvider.php

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
namespace Adldap\Laravel;
44

55
use Adldap\Adldap;
6-
use Adldap\Connections\Configuration;
7-
use Adldap\Connections\Manager;
86
use Adldap\Connections\Provider;
97
use Adldap\Contracts\AdldapInterface;
108
use Adldap\Laravel\Exceptions\ConfigurationMissingException;
@@ -15,6 +13,8 @@ class AdldapServiceProvider extends ServiceProvider
1513
{
1614
/**
1715
* Run service provider boot operations.
16+
*
17+
* @return void
1818
*/
1919
public function boot()
2020
{
@@ -29,6 +29,8 @@ public function boot()
2929

3030
/**
3131
* Register the service provider.
32+
*
33+
* @return void
3234
*/
3335
public function register()
3436
{
@@ -43,31 +45,7 @@ public function register()
4345
throw new ConfigurationMissingException($message);
4446
}
4547

46-
// Create a new connection Manager.
47-
$manager = new Manager();
48-
49-
// Retrieve the LDAP connections.
50-
$connections = $config['connections'];
51-
52-
// Go through each connection and construct a Provider.
53-
foreach ($connections as $name => $settings) {
54-
$configuration = new Configuration($settings['connection_settings']);
55-
$connection = new $settings['connection']();
56-
$schema = new $settings['schema']();
57-
58-
// Construct a new connection Provider with its settings.
59-
$provider = new Provider($configuration, $connection, $schema);
60-
61-
if ($settings['auto_connect'] === true) {
62-
// Try connecting to the provider if `auto_connect` is true.
63-
$provider->connect();
64-
}
65-
66-
// Add the Provider to the Manager.
67-
$manager->add($name, $provider);
68-
}
69-
70-
return new Adldap($manager);
48+
return $this->addProviders(new Adldap(), $config['connections']);
7149
});
7250

7351
// Bind the Adldap contract to the Adldap object
@@ -84,4 +62,34 @@ public function provides()
8462
{
8563
return ['adldap'];
8664
}
65+
66+
/**
67+
* Adds providers to the specified Adldap instance.
68+
*
69+
* @param Adldap $adldap
70+
* @param array $connections
71+
*
72+
* @return Adldap
73+
* @throws \Adldap\Exceptions\ConnectionException
74+
*/
75+
protected function addProviders(Adldap $adldap, array $connections = [])
76+
{
77+
// Go through each connection and construct a Provider.
78+
foreach ($connections as $name => $settings) {
79+
$connection = new $settings['connection']();
80+
$schema = new $settings['schema']();
81+
82+
// Construct a new connection Provider with its settings.
83+
$provider = new Provider($settings['connection_settings'], $connection, $schema);
84+
85+
if ($settings['auto_connect'] === true) {
86+
// Try connecting to the provider if `auto_connect` is true.
87+
$provider->connect();
88+
}
89+
90+
$adldap->addProvider($name, $provider);
91+
}
92+
93+
return $adldap;
94+
}
8795
}

src/Facades/Adldap.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
class Adldap extends Facade
88
{
99
/**
10-
* Get the registered name of the component.
11-
*
12-
* @return string
10+
* {@inheritdoc}
1311
*/
1412
protected static function getFacadeAccessor()
1513
{

src/Middleware/WindowsAuthenticate.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ public function __construct(Guard $auth)
4141
*/
4242
public function handle(Request $request, Closure $next)
4343
{
44-
// If the user is already logged in, we don't need to reauthenticate.
4544
if (!$this->auth->check()) {
4645
// Retrieve the SSO login attribute.
4746
$auth = $this->getWindowsAuthAttribute();

src/Traits/ImportsUsers.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ protected function getModelFromAdldap(User $user, $password)
3737

3838
// Make sure we retrieve the first username
3939
// result if it's an array.
40-
if (is_array($username)) {
41-
$username = Arr::get($username, 0);
42-
}
40+
$username = (is_array($username) ? Arr::get($username, 0) : $username);
4341

4442
// Try to retrieve the model from the model key and AD username.
4543
$model = $this->createModel()->newQuery()->where([$key => $username])->first();
@@ -238,7 +236,6 @@ protected function getSchema()
238236
*/
239237
protected function getAdldap($provider = null)
240238
{
241-
/** @var \Adldap\Adldap $ad */
242239
$ad = Adldap::getFacadeRoot();
243240

244241
if (is_null($provider)) {

0 commit comments

Comments
 (0)