Skip to content

Commit

Permalink
refactor: move CodeIgniter::bootstrapEnvironment() to bootstrap.php
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Feb 18, 2024
1 parent 76b3acf commit 88d4e6e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 15 deletions.
14 changes: 8 additions & 6 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
14 changes: 8 additions & 6 deletions spark
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 2 additions & 3 deletions system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,6 @@ public function __construct(App $config)
*/
public function initialize()
{
// Define environment variables
$this->bootstrapEnvironment();

// Setup Exception Handling
Services::exceptions()->initialize();

Expand Down Expand Up @@ -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()
{
Expand Down
9 changes: 9 additions & 0 deletions system/Test/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@
defined('COMPOSER_PATH') || define('COMPOSER_PATH', (string) realpath(HOMEPATH . 'vendor/autoload.php'));
defined('VENDORPATH') || define('VENDORPATH', realpath(HOMEPATH . 'vendor') . DIRECTORY_SEPARATOR);

if (is_file(APPPATH . 'Config/Boot/' . ENVIRONMENT . '.php')) {
require_once APPPATH . 'Config/Boot/' . ENVIRONMENT . '.php';
} else {
echo 'The application environment is not set correctly.';

exit(EXIT_ERROR); // EXIT_ERROR
}

// Load Common.php from App then System
if (is_file(APPPATH . 'Common.php')) {
require_once APPPATH . 'Common.php';
Expand Down Expand Up @@ -78,6 +86,7 @@
// Initialize and register the loader with the SPL autoloader stack.
Services::autoloader()->initialize(new Autoload(), new Modules())->register();
Services::autoloader()->loadHelpers();
Services::autoloader()->initializeKint();

// Now load Composer's if it's available
if (is_file(COMPOSER_PATH)) {
Expand Down
20 changes: 20 additions & 0 deletions system/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,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
Expand Down

0 comments on commit 88d4e6e

Please sign in to comment.