13
13
14
14
namespace CodeIgniter ;
15
15
16
+ use CodeIgniter \Cache \FactoriesCache ;
16
17
use CodeIgniter \Config \DotEnv ;
17
18
use Config \Autoload ;
19
+ use Config \Cache ;
18
20
use Config \Modules ;
19
21
use Config \Paths ;
20
22
use Config \Services ;
@@ -32,21 +34,47 @@ class Boot
32
34
* Context
33
35
* web: Invoked by HTTP request
34
36
* php-cli: Invoked by CLI via `php public/index.php`
37
+ *
38
+ * @return int Exit code.
35
39
*/
36
- public static function bootWeb (Paths $ paths ): void
40
+ public static function bootWeb (Paths $ paths ): int
37
41
{
38
- static ::boot ($ paths );
42
+ static ::definePathConstants ($ paths );
43
+ if (! defined ('APP_NAMESPACE ' )) {
44
+ static ::loadConstants ();
45
+ }
46
+ static ::checkMissingExtensions ();
47
+
48
+ static ::loadDotEnv ($ paths );
49
+ static ::defineEnvironment ();
50
+ static ::loadEnvironmentBootstrap ($ paths );
51
+
52
+ static ::loadCommonFunctions ();
53
+ static ::loadAutoloader ();
54
+ static ::setExceptionHandler ();
55
+ static ::initializeKint ();
56
+
57
+ $ configCacheEnabled = (new Cache ())->configCacheEnabled ?? false ;
58
+ if ($ configCacheEnabled ) {
59
+ $ factoriesCache = static ::loadConfigCache ();
60
+ }
61
+
62
+ $ app = static ::initializeCodeIgniter ();
63
+ static ::runCodeIgniter ($ app );
64
+
65
+ if ($ configCacheEnabled ) {
66
+ static ::saveConfigCache ($ factoriesCache );
67
+ }
68
+
69
+ // Exits the application, setting the exit code for CLI-based
70
+ // applications that might be watching.
71
+ return EXIT_SUCCESS ;
39
72
}
40
73
41
74
/**
42
75
* Used by `spark`
43
76
*/
44
77
public static function bootSpark (Paths $ paths ): void
45
- {
46
- static ::boot ($ paths );
47
- }
48
-
49
- protected static function boot (Paths $ paths ): void
50
78
{
51
79
static ::definePathConstants ($ paths );
52
80
if (! defined ('APP_NAMESPACE ' )) {
@@ -234,4 +262,41 @@ protected static function initializeKint(): void
234
262
{
235
263
Services::autoloader ()->initializeKint (CI_DEBUG );
236
264
}
265
+
266
+ protected static function loadConfigCache (): FactoriesCache
267
+ {
268
+ $ factoriesCache = new FactoriesCache ();
269
+ $ factoriesCache ->load ('config ' );
270
+
271
+ return $ factoriesCache ;
272
+ }
273
+
274
+ /**
275
+ * The CodeIgniter class contains the core functionality to make
276
+ * the application run, and does all the dirty work to get
277
+ * the pieces all working together.
278
+ */
279
+ protected static function initializeCodeIgniter (): CodeIgniter
280
+ {
281
+ $ app = Config \Services::codeigniter ();
282
+ $ app ->initialize ();
283
+ $ context = is_cli () ? 'php-cli ' : 'web ' ;
284
+ $ app ->setContext ($ context );
285
+
286
+ return $ app ;
287
+ }
288
+
289
+ /**
290
+ * Now that everything is set up, it's time to actually fire
291
+ * up the engines and make this app do its thang.
292
+ */
293
+ protected static function runCodeIgniter (CodeIgniter $ app ): void
294
+ {
295
+ $ app ->run ();
296
+ }
297
+
298
+ protected static function saveConfigCache (FactoriesCache $ factoriesCache ): void
299
+ {
300
+ $ factoriesCache ->save ('config ' );
301
+ }
237
302
}
0 commit comments