1212
1313/*
1414 * --------------------------------------------------------------------
15- * CodeIgniter command-line tools
15+ * CODEIGNITER COMMAND-LINE TOOLS
1616 * --------------------------------------------------------------------
1717 * The main entry point into the CLI system and allows you to run
1818 * commands and perform maintenance on your application.
@@ -26,7 +26,12 @@ if (strpos(PHP_SAPI, 'cgi') === 0) {
2626 exit ("The cli tool is not supported when running php-cgi. It needs php-cli to function! \n\n" );
2727}
2828
29- // Check PHP version.
29+ /*
30+ *---------------------------------------------------------------
31+ * CHECK PHP VERSION
32+ *---------------------------------------------------------------
33+ */
34+
3035$ minPhpVersion = '8.1 ' ; // If you update this, don't forget to update `public/index.php`.
3136if (version_compare (PHP_VERSION , $ minPhpVersion , '< ' )) {
3237 $ message = sprintf (
@@ -42,6 +47,12 @@ if (version_compare(PHP_VERSION, $minPhpVersion, '<')) {
4247error_reporting (E_ALL );
4348ini_set ('display_errors ' , '1 ' );
4449
50+ /*
51+ *---------------------------------------------------------------
52+ * SET THE CURRENT DIRECTORY
53+ *---------------------------------------------------------------
54+ */
55+
4556// Path to the front controller
4657define ('FCPATH ' , __DIR__ . DIRECTORY_SEPARATOR . 'public ' . DIRECTORY_SEPARATOR );
4758
@@ -57,32 +68,56 @@ chdir(FCPATH);
5768 * and fires up an environment-specific bootstrapping.
5869 */
5970
60- // Load our paths config file
71+ // LOAD OUR PATHS CONFIG FILE
6172// This is the line that might need to be changed, depending on your folder structure.
6273require FCPATH . '../app/Config/Paths.php ' ;
6374// ^^^ Change this line if you move your application folder
6475
6576$ paths = new Config \Paths ();
6677
67- // Location of the framework bootstrap file.
68- require rtrim ($ paths ->systemDirectory , '\\/ ' ) . DIRECTORY_SEPARATOR . 'bootstrap.php ' ;
69-
78+ // LOAD DOTENV FILE
7079// Load environment settings from .env files into $_SERVER and $_ENV
71- require_once SYSTEMPATH . 'Config/DotEnv.php ' ;
72- (new CodeIgniter \Config \DotEnv (ROOTPATH ))->load ();
80+ require_once $ paths -> systemDirectory . '/ Config/DotEnv.php ' ;
81+ (new CodeIgniter \Config \DotEnv ($ paths -> appDirectory . ' /../ ' ))->load ();
7382
74- // Define ENVIRONMENT
83+ // DEFINE ENVIRONMENT
7584if (! defined ('ENVIRONMENT ' )) {
76- define ('ENVIRONMENT ' , env ('CI_ENVIRONMENT ' , 'production ' ));
85+ $ env = $ _ENV ['CI_ENVIRONMENT ' ] ?? $ _SERVER ['CI_ENVIRONMENT ' ] ?? getenv ('CI_ENVIRONMENT ' );
86+ define ('ENVIRONMENT ' , ($ env !== false ) ? $ env : 'production ' );
87+ unset($ env );
88+ }
89+
90+ // LOAD ENVIRONMENT BOOTSTRAP
91+ if (is_file ($ paths ->appDirectory . '/Config/Boot/ ' . ENVIRONMENT . '.php ' )) {
92+ require_once $ paths ->appDirectory . '/Config/Boot/ ' . ENVIRONMENT . '.php ' ;
93+ } else {
94+ header ('HTTP/1.1 503 Service Unavailable. ' , true , 503 );
95+ echo 'The application environment is not set correctly. ' ;
96+
97+ exit (EXIT_ERROR ); // EXIT_ERROR
7798}
7899
79- // Grab our CodeIgniter
100+ // LOAD THE FRAMEWORK BOOTSTRAP FILE
101+ require rtrim ($ paths ->systemDirectory , '\\/ ' ) . DIRECTORY_SEPARATOR . 'bootstrap.php ' ;
102+
103+ /*
104+ * ---------------------------------------------------------------
105+ * GRAB OUR CODEIGNITER INSTANCE
106+ * ---------------------------------------------------------------
107+ */
108+
80109$ app = Config \Services::codeigniter ();
81110$ app ->initialize ();
82111
83- // Grab our Console
112+ /*
113+ * ---------------------------------------------------------------
114+ * GRAB OUR CONSOLE
115+ * ---------------------------------------------------------------
116+ */
117+
84118$ console = new CodeIgniter \CLI \Console ();
85119
120+ // SHOW HEADER
86121// Show basic information before we do anything else.
87122if (is_int ($ suppress = array_search ('--no-header ' , $ _SERVER ['argv ' ], true ))) {
88123 unset($ _SERVER ['argv ' ][$ suppress ]); // @codeCoverageIgnore
@@ -91,6 +126,12 @@ if (is_int($suppress = array_search('--no-header', $_SERVER['argv'], true))) {
91126
92127$ console ->showHeader ($ suppress );
93128
129+ /*
130+ *---------------------------------------------------------------
131+ * EXECUTE THE COMMAND
132+ *---------------------------------------------------------------
133+ */
134+
94135// fire off the command in the main framework.
95136$ exit = $ console ->run ();
96137
0 commit comments