@@ -27,22 +27,22 @@ public static function loadApplicationConfig()
2727 {
2828 static ::loadConfig ();
2929
30- if (class_exists ('Leaf\Auth ' ) && Config:: getStatic ( ' mvc.config.auth ' ) ) {
30+ if (class_exists ('Leaf\Auth ' )) {
3131 auth ()->config (Config::getStatic ('mvc.config.auth ' ));
3232 }
3333
34- if (class_exists ('Leaf\Mail ' ) && Config:: getStatic ( ' mvc.config.mail ' ) ) {
34+ if (class_exists ('Leaf\Mail ' )) {
3535 mailer ()->connect (Config::getStatic ('mvc.config.mail ' ));
3636 }
3737
3838 if (php_sapi_name () !== 'cli ' ) {
3939 app ()->config (Config::getStatic ('mvc.config.app ' ));
40-
41- if (class_exists ('Leaf\Http\Cors ' ) && Config:: getStatic ( ' mvc.config.cors ' ) ) {
40+
41+ if (class_exists ('Leaf\Http\Cors ' )) {
4242 app ()->cors (Config::getStatic ('mvc.config.cors ' ));
4343 }
4444
45- if (class_exists ('Leaf\Anchor\CSRF ' ) && Config:: getStatic ( ' mvc.config.csrf ' ) ) {
45+ if (class_exists ('Leaf\Anchor\CSRF ' )) {
4646 $ csrfConfig = Config::getStatic ('mvc.config.csrf ' );
4747
4848 $ csrfEnabled = (
@@ -74,6 +74,148 @@ protected static function loadConfig()
7474 {
7575 static ::$ paths = PathsConfig ();
7676
77+ $ config = [
78+ 'app ' => [
79+ 'app.down ' => _env ('APP_DOWN ' , false ),
80+ 'debug ' => _env ('APP_DEBUG ' , true ),
81+ 'log.dir ' => 'storage/logs/ ' ,
82+ 'log.enabled ' => true ,
83+ 'log.file ' => 'app.log ' ,
84+ 'log.level ' => Log::DEBUG ,
85+ 'log.open ' => true ,
86+ 'log.writer ' => null ,
87+ 'mode ' => 'development ' ,
88+ 'views.path ' => ViewsPath (null , false ),
89+ 'views.cachePath ' => StoragePath ('framework/views ' )
90+ ],
91+ 'auth ' => [
92+ 'db.table ' => 'users ' ,
93+ 'id.key ' => 'id ' ,
94+ 'timestamps ' => true ,
95+ 'timestamps.format ' => 'YYYY-MM-DD HH:mm:ss ' ,
96+ 'unique ' => ['email ' ],
97+ 'hidden ' => ['field.id ' , 'field.password ' ],
98+ 'session ' => true ,
99+ 'session.lifetime ' => 60 * 60 * 24 ,
100+ 'session.cookie ' => ['secure ' => false , 'httponly ' => true , 'samesite ' => 'lax ' ],
101+ 'token.lifetime ' => 60 * 60 * 24 * 365 ,
102+ 'token.secret ' => _env ('TOKEN_SECRET ' , '@leaf$MVC*JWT#AUTH.Secret ' ),
103+ 'messages.loginParamsError ' => 'Incorrect credentials! ' ,
104+ 'messages.loginPasswordError ' => 'Password is incorrect! ' ,
105+ 'password.key ' => 'password ' ,
106+ 'password.encode ' => function ($ password ) {
107+ return \Leaf \Helpers \Password::hash ($ password );
108+ },
109+ 'password.verify ' => function ($ password , $ hashedPassword ) {
110+ return \Leaf \Helpers \Password::verify ($ password , $ hashedPassword );
111+ },
112+ ],
113+ 'cors ' => [
114+ 'origin ' => '* ' ,
115+ 'methods ' => 'GET,HEAD,PUT,PATCH,POST,DELETE ' ,
116+ 'allowedHeaders ' => '* ' ,
117+ 'exposedHeaders ' => '' ,
118+ 'credentials ' => false ,
119+ 'maxAge ' => null ,
120+ 'preflightContinue ' => false ,
121+ 'optionsSuccessStatus ' => 204 ,
122+ ],
123+ 'csrf ' => [
124+ 'secret ' => _env ('APP_KEY ' , '@nkor_leaf$0Secret!! ' ),
125+ 'secretKey ' => 'X-Leaf-CSRF-Token ' ,
126+ 'except ' => [],
127+ 'methods ' => ['POST ' , 'PUT ' , 'PATCH ' , 'DELETE ' ],
128+ 'messages.tokenNotFound ' => 'Token not found. ' ,
129+ 'messages.tokenInvalid ' => 'Invalid token. ' ,
130+ 'onError ' => null ,
131+ ],
132+ 'database ' => [
133+ 'default ' => _env ('DB_CONNECTION ' , 'mysql ' ),
134+ 'connections ' => [
135+ 'sqlite ' => [
136+ 'driver ' => 'sqlite ' ,
137+ 'url ' => _env ('DATABASE_URL ' ),
138+ 'database ' => _env ('DB_DATABASE ' , AppPaths ('databaseStorage ' ) . '/database.sqlite ' ),
139+ 'prefix ' => '' ,
140+ 'foreign_key_constraints ' => _env ('DB_FOREIGN_KEYS ' , true ),
141+ ],
142+ 'mysql ' => [
143+ 'driver ' => 'mysql ' ,
144+ 'url ' => _env ('DATABASE_URL ' ),
145+ 'host ' => _env ('DB_HOST ' , '127.0.0.1 ' ),
146+ 'port ' => _env ('DB_PORT ' , '3306 ' ),
147+ 'database ' => _env ('DB_DATABASE ' , 'forge ' ),
148+ 'username ' => _env ('DB_USERNAME ' , 'forge ' ),
149+ 'password ' => _env ('DB_PASSWORD ' , '' ),
150+ 'unix_socket ' => _env ('DB_SOCKET ' , '' ),
151+ 'charset ' => _env ('DB_CHARSET ' , 'utf8mb4 ' ),
152+ 'collation ' => _env ('DB_COLLATION ' , 'utf8mb4_unicode_ci ' ),
153+ 'prefix ' => '' ,
154+ 'prefix_indexes ' => true ,
155+ 'strict ' => true ,
156+ 'engine ' => null ,
157+ 'options ' => extension_loaded ('pdo_mysql ' ) ? array_filter ([
158+ \PDO ::MYSQL_ATTR_SSL_CA => _env ('MYSQL_ATTR_SSL_CA ' ),
159+ ]) : [],
160+ ],
161+ 'pgsql ' => [
162+ 'driver ' => 'pgsql ' ,
163+ 'url ' => _env ('DATABASE_URL ' ),
164+ 'host ' => _env ('DB_HOST ' , '127.0.0.1 ' ),
165+ 'port ' => _env ('DB_PORT ' , '5432 ' ),
166+ 'database ' => _env ('DB_DATABASE ' , 'forge ' ),
167+ 'username ' => _env ('DB_USERNAME ' , 'forge ' ),
168+ 'password ' => _env ('DB_PASSWORD ' , '' ),
169+ 'charset ' => _env ('DB_CHARSET ' , 'utf8 ' ),
170+ 'prefix ' => '' ,
171+ 'prefix_indexes ' => true ,
172+ 'schema ' => 'public ' ,
173+ 'sslmode ' => 'prefer ' ,
174+ ],
175+ 'sqlsrv ' => [
176+ 'driver ' => 'sqlsrv ' ,
177+ 'url ' => _env ('DATABASE_URL ' ),
178+ 'host ' => _env ('DB_HOST ' , 'localhost ' ),
179+ 'port ' => _env ('DB_PORT ' , '1433 ' ),
180+ 'database ' => _env ('DB_DATABASE ' , 'forge ' ),
181+ 'username ' => _env ('DB_USERNAME ' , 'forge ' ),
182+ 'password ' => _env ('DB_PASSWORD ' , '' ),
183+ 'charset ' => _env ('DB_CHARSET ' , 'utf8 ' ),
184+ 'prefix ' => '' ,
185+ 'prefix_indexes ' => true ,
186+ ],
187+ ],
188+ ],
189+ 'view ' => [
190+ 'viewEngine ' => \Leaf \Blade::class,
191+ 'render ' => null ,
192+ 'config ' => function ($ config ) {
193+ \Leaf \Config::get ('views.blade ' )->configure ($ config ['views ' ], $ config ['cache ' ]);
194+ },
195+ ],
196+ 'mail ' => [
197+ 'host ' => _env ('MAIL_HOST ' , 'smtp.mailtrap.io ' ),
198+ 'port ' => _env ('MAIL_PORT ' , 2525 ),
199+ 'keepAlive ' => true ,
200+ 'debug ' => _env ('MAIL_DEBUG ' , 'SERVER ' ),
201+ 'security ' => _env ('MAIL_ENCRYPTION ' , 'STARTTLS ' ),
202+ 'auth ' => [
203+ 'username ' => _env ('MAIL_USERNAME ' ),
204+ 'password ' => _env ('MAIL_PASSWORD ' ),
205+ ],
206+ 'defaults ' => [
207+ 'senderName ' => _env ('MAIL_SENDER_NAME ' ),
208+ 'senderEmail ' => _env ('MAIL_SENDER_EMAIL ' ),
209+ 'replyToName ' => _env ('MAIL_REPLY_TO_NAME ' ),
210+ 'replyToEmail ' => _env ('MAIL_REPLY_TO_EMAIL ' ),
211+ ],
212+ ],
213+ ];
214+
215+ foreach ($ config as $ configName => $ config ) {
216+ \Leaf \Config::set ("mvc.config. $ configName " , $ config );
217+ }
218+
77219 $ configPath = static ::$ paths ['config ' ];
78220 $ configFiles = glob ("$ configPath/*.php " );
79221
@@ -98,6 +240,33 @@ public static function loadLibs()
98240 }
99241 }
100242
243+ /**
244+ * Load Aloe console and user defined commands
245+ */
246+ public static function loadConsole ()
247+ {
248+ static ::loadApplicationConfig ();
249+
250+ \Leaf \Database::connect ();
251+
252+ $ console = new \Aloe \Console ('v3.8.0 ' );
253+
254+ if (\Leaf \FS \Directory::exists (static ::$ paths ['commands ' ])) {
255+ $ consolePath = static ::$ paths ['commands ' ];
256+ $ consoleFiles = glob ("$ consolePath/*.php " );
257+
258+ foreach ($ consoleFiles as $ consoleFile ) {
259+ $ commandName = basename ($ consoleFile , '.php ' );
260+
261+ $ console ->register (
262+ "App \\Console \\$ commandName " ,
263+ );
264+ }
265+ }
266+
267+ $ console ->run ();
268+ }
269+
101270 /**
102271 * Load all application routes and run the application
103272 */
0 commit comments