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 707448a commit 98740ea
Show file tree
Hide file tree
Showing 4 changed files with 38 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
20 changes: 20 additions & 0 deletions system/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,26 @@
define('TESTPATH', realpath(rtrim($paths->testsDirectory, '\\/ ')) . DIRECTORY_SEPARATOR);

Check failure on line 52 in system/bootstrap.php

View workflow job for this annotation

GitHub Actions / Psalm Analysis

UndefinedGlobalVariable

system/bootstrap.php:52:39: UndefinedGlobalVariable: Cannot find referenced variable $paths in global scope (see https://psalm.dev/127)

Check failure on line 52 in system/bootstrap.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis

Variable $paths might not be defined.
}

/**
* ---------------------------------------------------------------
* 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 98740ea

Please sign in to comment.