3
3
namespace Adldap \Laravel ;
4
4
5
5
use Adldap \Adldap ;
6
- use Adldap \Connections \Configuration ;
7
- use Adldap \Connections \Manager ;
8
6
use Adldap \Connections \Provider ;
9
7
use Adldap \Contracts \AdldapInterface ;
10
8
use Adldap \Laravel \Exceptions \ConfigurationMissingException ;
@@ -15,6 +13,8 @@ class AdldapServiceProvider extends ServiceProvider
15
13
{
16
14
/**
17
15
* Run service provider boot operations.
16
+ *
17
+ * @return void
18
18
*/
19
19
public function boot ()
20
20
{
@@ -29,6 +29,8 @@ public function boot()
29
29
30
30
/**
31
31
* Register the service provider.
32
+ *
33
+ * @return void
32
34
*/
33
35
public function register ()
34
36
{
@@ -43,31 +45,7 @@ public function register()
43
45
throw new ConfigurationMissingException ($ message );
44
46
}
45
47
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 ' ]);
71
49
});
72
50
73
51
// Bind the Adldap contract to the Adldap object
@@ -84,4 +62,34 @@ public function provides()
84
62
{
85
63
return ['adldap ' ];
86
64
}
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
+ }
87
95
}
0 commit comments