@@ -27,81 +27,19 @@ public static function loadApplicationConfig()
27
27
{
28
28
static ::loadConfig ();
29
29
30
- if (class_exists ('Leaf\Auth ' )) {
31
- auth ()->config (Config::getStatic ('mvc.config.auth ' ));
32
- }
33
-
34
- if (class_exists ('Leaf\Mail ' )) {
35
- mailer ()->connect (Config::getStatic ('mvc.config.mail ' ));
36
- }
37
-
38
30
if (php_sapi_name () !== 'cli ' ) {
39
- app ()->config (Config::getStatic ('mvc.config.app ' ));
40
-
41
- if (class_exists ('Leaf\Http\Cors ' )) {
42
- app ()->cors (Config::getStatic ('mvc.config.cors ' ));
43
- }
44
-
45
- if (class_exists ('Leaf\Anchor\CSRF ' )) {
46
- $ csrfConfig = Config::getStatic ('mvc.config.csrf ' );
47
-
48
- $ csrfEnabled = (
49
- $ csrfConfig &&
50
- Config::getStatic ('mvc.config.auth ' )['session ' ] ?? false
51
- );
52
-
53
- if (($ csrfConfig ['enabled ' ] ?? null ) !== null ) {
54
- $ csrfEnabled = $ csrfConfig ['enabled ' ];
55
- }
56
-
57
- if ($ csrfEnabled ) {
58
- app ()->csrf ($ csrfConfig );
59
- }
60
- }
61
-
62
31
if (class_exists ('Leaf\Vite ' )) {
63
32
\Leaf \Vite::config ('assets ' , PublicPath ('build ' ));
64
33
\Leaf \Vite::config ('build ' , 'public/build ' );
65
34
\Leaf \Vite::config ('hotFile ' , 'public/hot ' );
66
35
}
67
36
68
- if (ViewConfig ('viewEngine ' )) {
69
- Config::attachView (ViewConfig ('viewEngine ' ), 'template ' );
70
-
71
- if (ViewConfig ('config ' )) {
72
- call_user_func_array (ViewConfig ('config ' ), [
73
- app ()->template (),
74
- [
75
- 'views ' => AppConfig ('views.path ' ),
76
- 'cache ' => AppConfig ('views.cachePath ' ),
77
- ]
78
- ]);
79
- } else if (method_exists (app ()->template (), 'configure ' )) {
80
- app ()->template ()->configure ([
81
- 'views ' => AppConfig ('views.path ' ),
82
- 'cache ' => AppConfig ('views.cachePath ' ),
83
- ]);
84
- }
85
-
86
- if (is_callable (ViewConfig ('extend ' ))) {
87
- call_user_func (ViewConfig ('extend ' ), app ()->template ());
88
- }
89
- }
90
-
91
37
\Leaf \Database::initDb ();
92
38
93
39
if (storage ()->exists (LibPath ())) {
94
40
static ::loadLibs ();
95
41
}
96
42
97
- if (
98
- class_exists ('Leaf\Billing\Stripe ' ) ||
99
- class_exists ('Leaf\Billing\PayStack ' ) ||
100
- class_exists ('Leaf\Billing\LemonSqueezy ' )
101
- ) {
102
- billing (Config::getStatic ('mvc.config.billing ' ));
103
- }
104
-
105
43
if (storage ()->exists ('app/index.php ' )) {
106
44
require 'app/index.php ' ;
107
45
}
@@ -129,47 +67,6 @@ protected static function loadConfig()
129
67
'views.path ' => ViewsPath (null , false ),
130
68
'views.cachePath ' => StoragePath ('framework/views ' )
131
69
],
132
- 'auth ' => [
133
- 'db.table ' => 'users ' ,
134
- 'id.key ' => 'id ' ,
135
- 'timestamps ' => true ,
136
- 'timestamps.format ' => 'YYYY-MM-DD HH:mm:ss ' ,
137
- 'unique ' => ['email ' ],
138
- 'hidden ' => ['field.id ' , 'field.password ' ],
139
- 'session ' => _env ('AUTH_SESSION ' , true ),
140
- 'session.lifetime ' => 60 * 60 * 24 ,
141
- 'session.cookie ' => ['secure ' => false , 'httponly ' => true , 'samesite ' => 'lax ' ],
142
- 'token.lifetime ' => 60 * 60 * 24 * 365 ,
143
- 'token.secret ' => _env ('AUTH_TOKEN_SECRET ' , '@leaf$MVC*JWT#AUTH.Secret ' ),
144
- 'messages.loginParamsError ' => 'Incorrect credentials! ' ,
145
- 'messages.loginPasswordError ' => 'Password is incorrect! ' ,
146
- 'password.key ' => 'password ' ,
147
- 'password.encode ' => function ($ password ) {
148
- return \Leaf \Helpers \Password::hash ($ password );
149
- },
150
- 'password.verify ' => function ($ password , $ hashedPassword ) {
151
- return \Leaf \Helpers \Password::verify ($ password , $ hashedPassword );
152
- },
153
- ],
154
- 'cors ' => [
155
- 'origin ' => _env ('CORS_ALLOWED_ORIGINS ' , '* ' ),
156
- 'methods ' => _env ('CORS_ALLOWED_METHODS ' , 'GET,HEAD,PUT,PATCH,POST,DELETE ' ),
157
- 'allowedHeaders ' => _env ('CORS_ALLOWED_HEADERS ' , '* ' ),
158
- 'exposedHeaders ' => _env ('CORS_EXPOSED_HEADERS ' , '' ),
159
- 'credentials ' => false ,
160
- 'maxAge ' => null ,
161
- 'preflightContinue ' => false ,
162
- 'optionsSuccessStatus ' => 204 ,
163
- ],
164
- 'csrf ' => [
165
- 'secret ' => _env ('APP_KEY ' , '@nkor_leaf$0Secret!! ' ),
166
- 'secretKey ' => 'X-Leaf-CSRF-Token ' ,
167
- 'except ' => [],
168
- 'methods ' => ['POST ' , 'PUT ' , 'PATCH ' , 'DELETE ' ],
169
- 'messages.tokenNotFound ' => 'Token not found. ' ,
170
- 'messages.tokenInvalid ' => 'Invalid token. ' ,
171
- 'onError ' => null ,
172
- ],
173
70
'database ' => [
174
71
'default ' => _env ('DB_CONNECTION ' , 'mysql ' ),
175
72
'connections ' => [
@@ -229,13 +126,114 @@ protected static function loadConfig()
229
126
],
230
127
'view ' => [
231
128
'viewEngine ' => \Leaf \Blade::class,
232
- 'config ' => function ($ engine , $ config ) {
233
- $ engine ->configure ($ config ['views ' ], $ config ['cache ' ]);
129
+ 'config ' => function ($ engine , $ viewConfig ) {
130
+ $ engine ->configure ($ viewConfig ['views ' ], $ viewConfig ['cache ' ]);
234
131
},
235
132
'render ' => null ,
236
133
'extend ' => null ,
237
134
],
238
- 'mail ' => [
135
+ ];
136
+
137
+ if (storage ()->exists ($ configPath = static ::$ paths ['config ' ])) {
138
+ foreach (glob ("$ configPath/*.php " ) as $ configFile ) {
139
+ $ config [basename ($ configFile , '.php ' )] = require $ configFile ;
140
+ }
141
+ }
142
+
143
+ app ()->config ($ config ['app ' ]);
144
+
145
+ if ($ config ['view ' ]['viewEngine ' ]) {
146
+ Config::attachView ($ config ['view ' ]['viewEngine ' ], 'template ' );
147
+
148
+ if ($ config ['view ' ]['config ' ]) {
149
+ call_user_func_array ($ config ['view ' ]['config ' ], [
150
+ app ()->template (),
151
+ [
152
+ 'views ' => $ config ['app ' ]['views.path ' ],
153
+ 'cache ' => $ config ['app ' ]['views.cachePath ' ],
154
+ ]
155
+ ]);
156
+ } else if (method_exists (app ()->template (), 'configure ' )) {
157
+ app ()->template ()->configure ([
158
+ 'views ' => $ config ['app ' ]['views.path ' ],
159
+ 'cache ' => $ config ['app ' ]['views.cachePath ' ],
160
+ ]);
161
+ }
162
+
163
+ if (is_callable ($ config ['view ' ]['extend ' ])) {
164
+ call_user_func ($ config ['view ' ]['extend ' ], app ()->template ());
165
+ }
166
+ }
167
+
168
+ if (class_exists ('Leaf\Auth ' )) {
169
+ $ config ['auth ' ] = [
170
+ 'db.table ' => 'users ' ,
171
+ 'id.key ' => 'id ' ,
172
+ 'timestamps ' => true ,
173
+ 'timestamps.format ' => 'YYYY-MM-DD HH:mm:ss ' ,
174
+ 'unique ' => ['email ' ],
175
+ 'hidden ' => ['field.id ' , 'field.password ' ],
176
+ 'session ' => _env ('AUTH_SESSION ' , true ),
177
+ 'session.lifetime ' => 60 * 60 * 24 ,
178
+ 'session.cookie ' => ['secure ' => false , 'httponly ' => true , 'samesite ' => 'lax ' ],
179
+ 'token.lifetime ' => 60 * 60 * 24 * 365 ,
180
+ 'token.secret ' => _env ('AUTH_TOKEN_SECRET ' , '@leaf$MVC*JWT#AUTH.Secret ' ),
181
+ 'messages.loginParamsError ' => 'Incorrect credentials! ' ,
182
+ 'messages.loginPasswordError ' => 'Password is incorrect! ' ,
183
+ 'password.key ' => 'password ' ,
184
+ 'password.encode ' => function ($ password ) {
185
+ return \Leaf \Helpers \Password::hash ($ password );
186
+ },
187
+ 'password.verify ' => function ($ password , $ hashedPassword ) {
188
+ return \Leaf \Helpers \Password::verify ($ password , $ hashedPassword );
189
+ },
190
+ ];
191
+
192
+ auth ()->config ($ config ['auth ' ]);
193
+ }
194
+
195
+ if (class_exists ('Leaf\Http\Cors ' )) {
196
+ $ config ['cors ' ] = [
197
+ 'origin ' => _env ('CORS_ALLOWED_ORIGINS ' , '* ' ),
198
+ 'methods ' => _env ('CORS_ALLOWED_METHODS ' , 'GET,HEAD,PUT,PATCH,POST,DELETE ' ),
199
+ 'allowedHeaders ' => _env ('CORS_ALLOWED_HEADERS ' , '* ' ),
200
+ 'exposedHeaders ' => _env ('CORS_EXPOSED_HEADERS ' , '' ),
201
+ 'credentials ' => false ,
202
+ 'maxAge ' => null ,
203
+ 'preflightContinue ' => false ,
204
+ 'optionsSuccessStatus ' => 204 ,
205
+ ];
206
+
207
+ app ()->cors ($ config ['cors ' ]);
208
+ }
209
+
210
+ if (class_exists ('Leaf\Anchor\CSRF ' )) {
211
+ $ config ['csrf ' ] = [
212
+ 'secret ' => _env ('APP_KEY ' , '@nkor_leaf$0Secret!! ' ),
213
+ 'secretKey ' => 'X-Leaf-CSRF-Token ' ,
214
+ 'except ' => [],
215
+ 'methods ' => ['POST ' , 'PUT ' , 'PATCH ' , 'DELETE ' ],
216
+ 'messages.tokenNotFound ' => 'Token not found. ' ,
217
+ 'messages.tokenInvalid ' => 'Invalid token. ' ,
218
+ 'onError ' => null ,
219
+ ];
220
+
221
+ $ csrfEnabled = (
222
+ $ config ['csrf ' ] &&
223
+ Config::getStatic ('mvc.config.auth ' )['session ' ] ?? false
224
+ );
225
+
226
+ if (($ config ['csrf ' ]['enabled ' ] ?? null ) !== null ) {
227
+ $ csrfEnabled = $ config ['csrf ' ]['enabled ' ];
228
+ }
229
+
230
+ if ($ csrfEnabled ) {
231
+ app ()->csrf ($ config ['csrf ' ]);
232
+ }
233
+ }
234
+
235
+ if (class_exists ('Leaf\Mail ' )) {
236
+ $ config ['mail ' ] = [
239
237
'host ' => _env ('MAIL_HOST ' , 'smtp.mailtrap.io ' ),
240
238
'port ' => _env ('MAIL_PORT ' , 2525 ),
241
239
'keepAlive ' => true ,
@@ -251,22 +249,20 @@ protected static function loadConfig()
251
249
'replyToName ' => _env ('MAIL_REPLY_TO_NAME ' ),
252
250
'replyToEmail ' => _env ('MAIL_REPLY_TO_EMAIL ' ),
253
251
],
254
- ],
255
- ];
252
+ ];
256
253
257
- foreach ($ config as $ configName => $ config ) {
258
- \Leaf \Config::set ("mvc.config. $ configName " , $ config );
254
+ mailer ()->connect ($ config ['mail ' ]);
259
255
}
260
256
261
- $ configPath = static ::$ paths ['config ' ];
262
- $ configFiles = glob ("$ configPath/*.php " );
263
-
264
- foreach ($ configFiles as $ configFile ) {
265
- $ configName = basename ($ configFile , '.php ' );
266
- $ config = require $ configFile ;
267
-
268
- \Leaf \Config::set ("mvc.config. $ configName " , $ config );
257
+ if (
258
+ class_exists ('Leaf\Billing\Stripe ' ) ||
259
+ class_exists ('Leaf\Billing\PayStack ' ) ||
260
+ class_exists ('Leaf\Billing\LemonSqueezy ' )
261
+ ) {
262
+ billing ($ config ['billing ' ]);
269
263
}
264
+
265
+ Config::set ('mvc.config ' , $ config );
270
266
}
271
267
272
268
/**
@@ -291,7 +287,7 @@ public static function loadConsole($externalCommands = [])
291
287
292
288
\Leaf \Database::connect ();
293
289
294
- $ console = new \Aloe \Console ('v4.x-ALPHA ' );
290
+ $ console = new \Aloe \Console ('v4.x-BETA ' );
295
291
296
292
if (\Leaf \FS \Directory::exists (static ::$ paths ['commands ' ])) {
297
293
$ consolePath = static ::$ paths ['commands ' ];
0 commit comments