diff --git a/public/index.php b/public/index.php index 8cf5ce347c82..6d78241411ba 100644 --- a/public/index.php +++ b/public/index.php @@ -36,18 +36,20 @@ $paths = new Config\Paths(); -// Location of the framework bootstrap file. -require rtrim($paths->systemDirectory, '\\/ ') . DIRECTORY_SEPARATOR . 'bootstrap.php'; - // Load environment settings from .env files into $_SERVER and $_ENV -require_once SYSTEMPATH . 'Config/DotEnv.php'; -(new CodeIgniter\Config\DotEnv(ROOTPATH))->load(); +require_once $paths->systemDirectory . '/Config/DotEnv.php'; +(new CodeIgniter\Config\DotEnv($paths->appDirectory . '/../'))->load(); // Define ENVIRONMENT if (! defined('ENVIRONMENT')) { - define('ENVIRONMENT', env('CI_ENVIRONMENT', 'production')); + $env = $_ENV['CI_ENVIRONMENT'] ?? $_SERVER['CI_ENVIRONMENT'] ?? getenv('CI_ENVIRONMENT'); + define('ENVIRONMENT', ($env !== false) ? $env : 'production'); + unset($env); } +// Location of the framework bootstrap file. +require rtrim($paths->systemDirectory, '\\/ ') . DIRECTORY_SEPARATOR . 'bootstrap.php'; + // Load Config Cache // $factoriesCache = new \CodeIgniter\Cache\FactoriesCache(); // $factoriesCache->load('config'); diff --git a/spark b/spark index 7029eee1f775..7428b8a392a5 100755 --- a/spark +++ b/spark @@ -71,18 +71,20 @@ require FCPATH . '../app/Config/Paths.php'; $paths = new Config\Paths(); -// Location of the framework bootstrap file. -require rtrim($paths->systemDirectory, '\\/ ') . DIRECTORY_SEPARATOR . 'bootstrap.php'; - // Load environment settings from .env files into $_SERVER and $_ENV -require_once SYSTEMPATH . 'Config/DotEnv.php'; -(new CodeIgniter\Config\DotEnv(ROOTPATH))->load(); +require_once $paths->systemDirectory . '/Config/DotEnv.php'; +(new CodeIgniter\Config\DotEnv($paths->appDirectory . '/../'))->load(); // Define ENVIRONMENT if (! defined('ENVIRONMENT')) { - define('ENVIRONMENT', env('CI_ENVIRONMENT', 'production')); + $env = $_ENV['CI_ENVIRONMENT'] ?? $_SERVER['CI_ENVIRONMENT'] ?? getenv('CI_ENVIRONMENT'); + define('ENVIRONMENT', ($env !== false) ? $env : 'production'); + unset($env); } +// Location of the framework bootstrap file. +require rtrim($paths->systemDirectory, '\\/ ') . DIRECTORY_SEPARATOR . 'bootstrap.php'; + // Grab our CodeIgniter $app = Config\Services::codeigniter(); $app->initialize(); diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index 85776368ed24..2bd5965bb22a 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -186,9 +186,6 @@ public function __construct(App $config) */ public function initialize() { - // Define environment variables - $this->bootstrapEnvironment(); - // Setup Exception Handling Services::exceptions()->initialize(); @@ -584,6 +581,8 @@ protected function detectEnvironment() * is wrong. At the very least, they should have error reporting setup. * * @return void + * + * @deprecated 4.5.0 Moved to system/bootstrap.php. */ protected function bootstrapEnvironment() { diff --git a/system/bootstrap.php b/system/bootstrap.php index be1e43c85e03..9777c7177eaa 100644 --- a/system/bootstrap.php +++ b/system/bootstrap.php @@ -52,6 +52,26 @@ define('TESTPATH', realpath(rtrim($paths->testsDirectory, '\\/ ')) . DIRECTORY_SEPARATOR); } +/** + * --------------------------------------------------------------- + * LOAD ENVIRONMENT BOOTSTRAP + * --------------------------------------------------------------- + * + * Load any custom boot files based upon the current environment. + * If no boot file exists, we shouldn't continue because something + * is wrong. At the very least, they should have error reporting setup. + */ +if (is_file(APPPATH . 'Config/Boot/' . ENVIRONMENT . '.php')) { + require_once APPPATH . 'Config/Boot/' . ENVIRONMENT . '.php'; +} else { + // @codeCoverageIgnoreStart + header('HTTP/1.1 503 Service Unavailable.', true, 503); + echo 'The application environment is not set correctly.'; + + exit(EXIT_ERROR); // EXIT_ERROR + // @codeCoverageIgnoreEnd +} + /* * --------------------------------------------------------------- * GRAB OUR CONSTANTS & COMMON