1010use Bow \Support \Arraydotify ;
1111use Bow \Session \SessionConfiguration ;
1212use Bow \Configuration \EnvConfiguration ;
13- use Bow \Container \ContainerConfiguration ;
1413use Bow \Application \Exception \ApplicationException ;
14+ use Bow \Container \CompassConfiguration ;
1515
1616class Loader implements ArrayAccess
1717{
@@ -175,32 +175,20 @@ public function boot(): Loader
175175 return $ this ;
176176 }
177177
178- $ services = array_merge (
179- [ContainerConfiguration::class, EnvConfiguration::class],
180- $ this ->configurations (),
181- );
182-
183- $ service_collection = [];
178+ $ services = array_merge ([CompassConfiguration::class], $ this ->configurations ());
184179
185180 $ container = Capsule::getInstance ();
186181
182+ $ this ->loadConfiguration (EnvConfiguration::class, $ container );
183+
187184 // Configuration of services
188185 foreach ($ services as $ service ) {
189186 if ($ this ->without_session && $ service === SessionConfiguration::class) {
190187 continue ;
191188 }
192189
193- if (!class_exists ($ service )) {
194- continue ;
195- }
196-
197- $ service_instance = new $ service ($ container );
198- $ service_instance ->create ($ this );
199- $ service_collection [] = $ service_instance ;
200-
201- // Encure that the .env file is loaded before others services
202- if ($ service === EnvConfiguration::class) {
203- $ this ->loadEnvfile ();
190+ if (class_exists ($ service )) {
191+ $ service_collection [] = $ this ->loadConfiguration ($ service , $ container );
204192 }
205193 }
206194
@@ -213,7 +201,7 @@ public function boot(): Loader
213201 foreach ($ this ->events () as $ name => $ handlers ) {
214202 $ handlers = (array ) $ handlers ;
215203 foreach ($ handlers as $ handler ) {
216- Event:: on ($ name , $ handler );
204+ app_event ($ name , $ handler );
217205 }
218206 }
219207
@@ -223,6 +211,22 @@ public function boot(): Loader
223211 return $ this ;
224212 }
225213
214+ /**
215+ * Load a configuration service
216+ *
217+ * @param string $service
218+ * @param Capsule $container
219+ * @return Configuration
220+ */
221+ private function loadConfiguration (string $ service , Capsule $ container ): Configuration
222+ {
223+ $ service_instance = new $ service ($ container );
224+
225+ $ service_instance ->create ($ this );
226+
227+ return $ service_instance ;
228+ }
229+
226230 /**
227231 * Load the .env file
228232 *
0 commit comments