33namespace Adldap \Laravel ;
44
55use Adldap \Adldap ;
6- use Adldap \Connections \Configuration ;
7- use Adldap \Connections \Manager ;
86use Adldap \Connections \Provider ;
97use Adldap \Contracts \AdldapInterface ;
108use 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}
0 commit comments