From 28a8009179b5019cc291e720d483a2ac2aec3611 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 18 Feb 2024 18:54:13 +0900 Subject: [PATCH 01/22] refactor: move CodeIgniter::initializeKint() to Autoloader --- system/Autoloader/Autoloader.php | 78 ++++++++++++++++++++++++++++ system/CodeIgniter.php | 10 +++- system/Test/bootstrap.php | 1 + system/bootstrap.php | 1 + tests/system/CommonFunctionsTest.php | 7 +-- 5 files changed, 90 insertions(+), 7 deletions(-) diff --git a/system/Autoloader/Autoloader.php b/system/Autoloader/Autoloader.php index 48516e522584..07510eb57625 100644 --- a/system/Autoloader/Autoloader.php +++ b/system/Autoloader/Autoloader.php @@ -17,8 +17,13 @@ use Composer\Autoload\ClassLoader; use Composer\InstalledVersions; use Config\Autoload; +use Config\Kint as KintConfig; use Config\Modules; +use Config\Services; use InvalidArgumentException; +use Kint; +use Kint\Renderer\CliRenderer; +use Kint\Renderer\RichRenderer; use RuntimeException; /** @@ -481,4 +486,77 @@ public function loadHelpers(): void { helper($this->helpers); } + + /** + * Initializes Kint + */ + public function initializeKint(bool $debug = false): void + { + if ($debug) { + $this->autoloadKint(); + $this->configureKint(); + } elseif (class_exists(Kint::class)) { + // In case that Kint is already loaded via Composer. + Kint::$enabled_mode = false; + // @codeCoverageIgnore + } + + helper('kint'); + } + + private function autoloadKint(): void + { + // If we have KINT_DIR it means it's already loaded via composer + if (! defined('KINT_DIR')) { + spl_autoload_register(function ($class) { + $class = explode('\\', $class); + + if (array_shift($class) !== 'Kint') { + return; + } + + $file = SYSTEMPATH . 'ThirdParty/Kint/' . implode('/', $class) . '.php'; + + if (is_file($file)) { + require_once $file; + } + }); + + require_once SYSTEMPATH . 'ThirdParty/Kint/init.php'; + } + } + + private function configureKint(): void + { + $config = new KintConfig(); + + Kint::$depth_limit = $config->maxDepth; + Kint::$display_called_from = $config->displayCalledFrom; + Kint::$expanded = $config->expanded; + + if (isset($config->plugins) && is_array($config->plugins)) { + Kint::$plugins = $config->plugins; + } + + $csp = Services::csp(); + if ($csp->enabled()) { + RichRenderer::$js_nonce = $csp->getScriptNonce(); + RichRenderer::$css_nonce = $csp->getStyleNonce(); + } + + RichRenderer::$theme = $config->richTheme; + RichRenderer::$folder = $config->richFolder; + RichRenderer::$sort = $config->richSort; + if (isset($config->richObjectPlugins) && is_array($config->richObjectPlugins)) { + RichRenderer::$value_plugins = $config->richObjectPlugins; + } + if (isset($config->richTabPlugins) && is_array($config->richTabPlugins)) { + RichRenderer::$tab_plugins = $config->richTabPlugins; + } + + CliRenderer::$cli_colors = $config->cliColors; + CliRenderer::$force_utf8 = $config->cliForceUTF8; + CliRenderer::$detect_width = $config->cliDetectWidth; + CliRenderer::$min_terminal_width = $config->cliMinWidth; + } } diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index f126878689b9..9521239a1c7d 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -202,8 +202,6 @@ public function initialize() // Set default timezone on the server date_default_timezone_set($this->config->appTimezone ?? 'UTC'); - - $this->initializeKint(); } /** @@ -240,6 +238,8 @@ protected function resolvePlatformExtensions() * Initializes Kint * * @return void + * + * @deprecated 4.5.0 Moved to Autoloader. */ protected function initializeKint() { @@ -255,6 +255,9 @@ protected function initializeKint() helper('kint'); } + /** + * @deprecated 4.5.0 Moved to Autoloader. + */ private function autoloadKint(): void { // If we have KINT_DIR it means it's already loaded via composer @@ -277,6 +280,9 @@ private function autoloadKint(): void } } + /** + * @deprecated 4.5.0 Moved to Autoloader. + */ private function configureKint(): void { $config = new KintConfig(); diff --git a/system/Test/bootstrap.php b/system/Test/bootstrap.php index 8b992be9f884..a8ef6b01b0b9 100644 --- a/system/Test/bootstrap.php +++ b/system/Test/bootstrap.php @@ -78,6 +78,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(CI_DEBUG); // Now load Composer's if it's available if (is_file(COMPOSER_PATH)) { diff --git a/system/bootstrap.php b/system/bootstrap.php index e03fd570ca4c..b89689644389 100644 --- a/system/bootstrap.php +++ b/system/bootstrap.php @@ -106,3 +106,4 @@ // Initialize and register the loader with the SPL autoloader stack. Services::autoloader()->initialize(new Autoload(), new Modules())->register(); Services::autoloader()->loadHelpers(); +Services::autoloader()->initializeKint(CI_DEBUG); diff --git a/tests/system/CommonFunctionsTest.php b/tests/system/CommonFunctionsTest.php index e583b8a67194..a31e73c749cf 100644 --- a/tests/system/CommonFunctionsTest.php +++ b/tests/system/CommonFunctionsTest.php @@ -26,7 +26,6 @@ use CodeIgniter\Session\Handlers\FileHandler; use CodeIgniter\Session\Session; use CodeIgniter\Test\CIUnitTestCase; -use CodeIgniter\Test\Mock\MockCodeIgniter; use CodeIgniter\Test\Mock\MockIncomingRequest; use CodeIgniter\Test\Mock\MockSecurity; use CodeIgniter\Test\Mock\MockSession; @@ -710,8 +709,7 @@ public function testDWithCSP(): void $config->CSPEnabled = true; // Initialize Kint - $app = new MockCodeIgniter($config); - $app->initialize(); + Services::autoloader()->initializeKint(CI_DEBUG); $cliDetection = Kint::$cli_detection; Kint::$cli_detection = false; @@ -736,8 +734,7 @@ public function testTraceWithCSP(): void $config->CSPEnabled = true; // Initialize Kint - $app = new MockCodeIgniter($config); - $app->initialize(); + Services::autoloader()->initializeKint(CI_DEBUG); Kint::$cli_detection = false; From 470dace722315e649ef4376de2022f4ba95909ce Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 18 Feb 2024 18:55:59 +0900 Subject: [PATCH 02/22] docs: remove unneeded @var --- system/bootstrap.php | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/system/bootstrap.php b/system/bootstrap.php index b89689644389..6b7e94a2b0f6 100644 --- a/system/bootstrap.php +++ b/system/bootstrap.php @@ -26,11 +26,10 @@ * so they are available in the config files that are loaded. */ +/** @var Paths $paths */ + // The path to the application directory. if (! defined('APPPATH')) { - /** - * @var Paths $paths - */ define('APPPATH', realpath(rtrim($paths->appDirectory, '\\/ ')) . DIRECTORY_SEPARATOR); } @@ -41,25 +40,16 @@ // The path to the system directory. if (! defined('SYSTEMPATH')) { - /** - * @var Paths $paths - */ define('SYSTEMPATH', realpath(rtrim($paths->systemDirectory, '\\/ ')) . DIRECTORY_SEPARATOR); } // The path to the writable directory. if (! defined('WRITEPATH')) { - /** - * @var Paths $paths - */ define('WRITEPATH', realpath(rtrim($paths->writableDirectory, '\\/ ')) . DIRECTORY_SEPARATOR); } // The path to the tests directory if (! defined('TESTPATH')) { - /** - * @var Paths $paths - */ define('TESTPATH', realpath(rtrim($paths->testsDirectory, '\\/ ')) . DIRECTORY_SEPARATOR); } From 4e602a66f33295caf2b105db9cce694252805b39 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 18 Feb 2024 19:34:27 +0900 Subject: [PATCH 03/22] refactor: move CodeIgniter::bootstrapEnvironment() to bootstrap.php --- public/index.php | 14 ++++++++------ spark | 14 ++++++++------ system/CodeIgniter.php | 5 ++--- system/Test/bootstrap.php | 9 +++++++++ system/bootstrap.php | 21 +++++++++++++++++++++ 5 files changed, 48 insertions(+), 15 deletions(-) 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 adbd43fafd63..1d4293f59a1a 100755 --- a/spark +++ b/spark @@ -64,18 +64,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 9521239a1c7d..3b92da4362cf 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/Test/bootstrap.php b/system/Test/bootstrap.php index a8ef6b01b0b9..7d67acd070a6 100644 --- a/system/Test/bootstrap.php +++ b/system/Test/bootstrap.php @@ -39,6 +39,10 @@ require CONFIGPATH . 'Paths.php'; $paths = new Paths(); +// Load environment settings from .env files into $_SERVER and $_ENV +require_once $paths->systemDirectory . '/Config/DotEnv.php'; +(new DotEnv($paths->appDirectory . '/../'))->load(); + // Define necessary framework path constants defined('APPPATH') || define('APPPATH', realpath(rtrim($paths->appDirectory, '\\/ ')) . DIRECTORY_SEPARATOR); defined('WRITEPATH') || define('WRITEPATH', realpath(rtrim($paths->writableDirectory, '\\/ ')) . DIRECTORY_SEPARATOR); @@ -51,6 +55,11 @@ defined('COMPOSER_PATH') || define('COMPOSER_PATH', (string) realpath(HOMEPATH . 'vendor/autoload.php')); defined('VENDORPATH') || define('VENDORPATH', realpath(HOMEPATH . 'vendor') . DIRECTORY_SEPARATOR); +// Load environment bootstrap +if (is_file(APPPATH . 'Config/Boot/' . ENVIRONMENT . '.php')) { + require_once APPPATH . 'Config/Boot/' . ENVIRONMENT . '.php'; +} + // Load Common.php from App then System if (is_file(APPPATH . 'Common.php')) { require_once APPPATH . 'Common.php'; diff --git a/system/bootstrap.php b/system/bootstrap.php index 6b7e94a2b0f6..fef24bd9807f 100644 --- a/system/bootstrap.php +++ b/system/bootstrap.php @@ -53,6 +53,27 @@ 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 From 85adb5b655d3f4b285d5adb25e381a2ec22d03e6 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 18 Feb 2024 21:21:55 +0900 Subject: [PATCH 04/22] docs: remove meaningless @codeCoverageIgnore --- system/Autoloader/Autoloader.php | 1 - 1 file changed, 1 deletion(-) diff --git a/system/Autoloader/Autoloader.php b/system/Autoloader/Autoloader.php index 07510eb57625..c8c1767a9d83 100644 --- a/system/Autoloader/Autoloader.php +++ b/system/Autoloader/Autoloader.php @@ -498,7 +498,6 @@ public function initializeKint(bool $debug = false): void } elseif (class_exists(Kint::class)) { // In case that Kint is already loaded via Composer. Kint::$enabled_mode = false; - // @codeCoverageIgnore } helper('kint'); From c1575909b8fb2f453851d18f169f6ebebbf23e34 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 18 Feb 2024 21:38:41 +0900 Subject: [PATCH 05/22] docs: add comment headings --- public/index.php | 20 ++++++++++++++++---- spark | 43 ++++++++++++++++++++++++++++++++++++------- system/bootstrap.php | 8 +++++++- 3 files changed, 59 insertions(+), 12 deletions(-) diff --git a/public/index.php b/public/index.php index 6d78241411ba..9132d097e769 100644 --- a/public/index.php +++ b/public/index.php @@ -1,6 +1,11 @@ systemDirectory . '/Config/DotEnv.php'; (new CodeIgniter\Config\DotEnv($paths->appDirectory . '/../'))->load(); -// Define ENVIRONMENT +// DEFINE ENVIRONMENT if (! defined('ENVIRONMENT')) { $env = $_ENV['CI_ENVIRONMENT'] ?? $_SERVER['CI_ENVIRONMENT'] ?? getenv('CI_ENVIRONMENT'); define('ENVIRONMENT', ($env !== false) ? $env : 'production'); unset($env); } -// Location of the framework bootstrap file. +// LOAD THE FRAMEWORK BOOTSTRAP FILE require rtrim($paths->systemDirectory, '\\/ ') . DIRECTORY_SEPARATOR . 'bootstrap.php'; // Load Config Cache diff --git a/spark b/spark index 1d4293f59a1a..5d93cd5eec06 100755 --- a/spark +++ b/spark @@ -12,7 +12,7 @@ /* * -------------------------------------------------------------------- - * CodeIgniter command-line tools + * CODEIGNITER COMMAND-LINE TOOLS * -------------------------------------------------------------------- * The main entry point into the CLI system and allows you to run * commands and perform maintenance on your application. @@ -26,7 +26,12 @@ if (strpos(PHP_SAPI, 'cgi') === 0) { exit("The cli tool is not supported when running php-cgi. It needs php-cli to function!\n\n"); } -// Check PHP version. +/* + *--------------------------------------------------------------- + * CHECK PHP VERSION + *--------------------------------------------------------------- + */ + $minPhpVersion = '8.1'; // If you update this, don't forget to update `public/index.php`. if (version_compare(PHP_VERSION, $minPhpVersion, '<')) { $message = sprintf( @@ -42,6 +47,12 @@ if (version_compare(PHP_VERSION, $minPhpVersion, '<')) { error_reporting(E_ALL); ini_set('display_errors', '1'); +/* + *--------------------------------------------------------------- + * SET THE CURRENT DIRECTORY + *--------------------------------------------------------------- + */ + // Path to the front controller define('FCPATH', __DIR__ . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR); @@ -57,34 +68,46 @@ chdir(FCPATH); * and fires up an environment-specific bootstrapping. */ -// Load our paths config file +// LOAD OUR PATHS CONFIG FILE // This is the line that might need to be changed, depending on your folder structure. require FCPATH . '../app/Config/Paths.php'; // ^^^ Change this line if you move your application folder $paths = new Config\Paths(); +// LOAD DOTENV FILE // Load environment settings from .env files into $_SERVER and $_ENV require_once $paths->systemDirectory . '/Config/DotEnv.php'; (new CodeIgniter\Config\DotEnv($paths->appDirectory . '/../'))->load(); -// Define ENVIRONMENT +// DEFINE ENVIRONMENT if (! defined('ENVIRONMENT')) { $env = $_ENV['CI_ENVIRONMENT'] ?? $_SERVER['CI_ENVIRONMENT'] ?? getenv('CI_ENVIRONMENT'); define('ENVIRONMENT', ($env !== false) ? $env : 'production'); unset($env); } -// Location of the framework bootstrap file. +// LOAD THE FRAMEWORK BOOTSTRAP FILE require rtrim($paths->systemDirectory, '\\/ ') . DIRECTORY_SEPARATOR . 'bootstrap.php'; -// Grab our CodeIgniter +/* + * --------------------------------------------------------------- + * GRAB OUR CODEIGNITER INSTANCE + * --------------------------------------------------------------- + */ + $app = Config\Services::codeigniter(); $app->initialize(); -// Grab our Console +/* + * --------------------------------------------------------------- + * GRAB OUR CONSOLE + * --------------------------------------------------------------- + */ + $console = new CodeIgniter\CLI\Console(); +// SHOW HEADER // Show basic information before we do anything else. if (is_int($suppress = array_search('--no-header', $_SERVER['argv'], true))) { unset($_SERVER['argv'][$suppress]); // @codeCoverageIgnore @@ -93,6 +116,12 @@ if (is_int($suppress = array_search('--no-header', $_SERVER['argv'], true))) { $console->showHeader($suppress); +/* + *--------------------------------------------------------------- + * EXECUTE THE COMMAND + *--------------------------------------------------------------- + */ + // fire off the command in the main framework. $exit = $console->run(); diff --git a/system/bootstrap.php b/system/bootstrap.php index fef24bd9807f..50cc24043318 100644 --- a/system/bootstrap.php +++ b/system/bootstrap.php @@ -76,7 +76,7 @@ /* * --------------------------------------------------------------- - * GRAB OUR CONSTANTS & COMMON + * GRAB OUR CONSTANTS * --------------------------------------------------------------- */ @@ -84,6 +84,12 @@ require_once APPPATH . 'Config/Constants.php'; } +/* + * --------------------------------------------------------------- + * LOAD COMMON FUNCTIONS + * --------------------------------------------------------------- + */ + // Require app/Common.php file if exists. if (is_file(APPPATH . 'Common.php')) { require_once APPPATH . 'Common.php'; From e670df1ed958674cdfeb2a3f74e00d364fd7981d Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 18 Feb 2024 22:11:26 +0900 Subject: [PATCH 06/22] refactor: move DEFINE ENVIRONMENT to bootstrap.php --- public/index.php | 7 ------- spark | 7 ------- system/bootstrap.php | 12 ++++++++++++ 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/public/index.php b/public/index.php index 9132d097e769..9df0b8e86a67 100644 --- a/public/index.php +++ b/public/index.php @@ -52,13 +52,6 @@ require_once $paths->systemDirectory . '/Config/DotEnv.php'; (new CodeIgniter\Config\DotEnv($paths->appDirectory . '/../'))->load(); -// DEFINE ENVIRONMENT -if (! defined('ENVIRONMENT')) { - $env = $_ENV['CI_ENVIRONMENT'] ?? $_SERVER['CI_ENVIRONMENT'] ?? getenv('CI_ENVIRONMENT'); - define('ENVIRONMENT', ($env !== false) ? $env : 'production'); - unset($env); -} - // LOAD THE FRAMEWORK BOOTSTRAP FILE require rtrim($paths->systemDirectory, '\\/ ') . DIRECTORY_SEPARATOR . 'bootstrap.php'; diff --git a/spark b/spark index 5d93cd5eec06..16af4a543c52 100755 --- a/spark +++ b/spark @@ -80,13 +80,6 @@ $paths = new Config\Paths(); require_once $paths->systemDirectory . '/Config/DotEnv.php'; (new CodeIgniter\Config\DotEnv($paths->appDirectory . '/../'))->load(); -// DEFINE ENVIRONMENT -if (! defined('ENVIRONMENT')) { - $env = $_ENV['CI_ENVIRONMENT'] ?? $_SERVER['CI_ENVIRONMENT'] ?? getenv('CI_ENVIRONMENT'); - define('ENVIRONMENT', ($env !== false) ? $env : 'production'); - unset($env); -} - // LOAD THE FRAMEWORK BOOTSTRAP FILE require rtrim($paths->systemDirectory, '\\/ ') . DIRECTORY_SEPARATOR . 'bootstrap.php'; diff --git a/system/bootstrap.php b/system/bootstrap.php index 50cc24043318..dcb074242251 100644 --- a/system/bootstrap.php +++ b/system/bootstrap.php @@ -16,6 +16,18 @@ use Config\Paths; use Config\Services; +/* + * --------------------------------------------------------------- + * DEFINE ENVIRONMENT + * --------------------------------------------------------------- + */ + +if (! defined('ENVIRONMENT')) { + $env = $_ENV['CI_ENVIRONMENT'] ?? $_SERVER['CI_ENVIRONMENT'] ?? getenv('CI_ENVIRONMENT'); + define('ENVIRONMENT', ($env !== false) ? $env : 'production'); + unset($env); +} + /* * --------------------------------------------------------------- * SETUP OUR PATH CONSTANTS From 66c81bcc131f3d29d91b34c3a1b1c937887eaed3 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 18 Feb 2024 22:17:45 +0900 Subject: [PATCH 07/22] refactor: move Services::exceptions()->initialize() to bootstrap.php --- system/CodeIgniter.php | 3 --- system/Test/bootstrap.php | 5 +++++ system/bootstrap.php | 10 ++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index 3b92da4362cf..706e8404c945 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -186,9 +186,6 @@ public function __construct(App $config) */ public function initialize() { - // Setup Exception Handling - Services::exceptions()->initialize(); - // Run this check for manual installations if (! is_file(COMPOSER_PATH)) { $this->resolvePlatformExtensions(); // @codeCoverageIgnore diff --git a/system/Test/bootstrap.php b/system/Test/bootstrap.php index 7d67acd070a6..15b1b8cc4b2d 100644 --- a/system/Test/bootstrap.php +++ b/system/Test/bootstrap.php @@ -87,6 +87,11 @@ // Initialize and register the loader with the SPL autoloader stack. Services::autoloader()->initialize(new Autoload(), new Modules())->register(); Services::autoloader()->loadHelpers(); + +// Setup Exception Handling +Services::exceptions()->initialize(); + +// Initialize Kint Services::autoloader()->initializeKint(CI_DEBUG); // Now load Composer's if it's available diff --git a/system/bootstrap.php b/system/bootstrap.php index dcb074242251..58f8d645a748 100644 --- a/system/bootstrap.php +++ b/system/bootstrap.php @@ -135,4 +135,14 @@ // Initialize and register the loader with the SPL autoloader stack. Services::autoloader()->initialize(new Autoload(), new Modules())->register(); Services::autoloader()->loadHelpers(); + +/* + * --------------------------------------------------------------- + * SET EXCEPTION AND ERROR HANDLERS + * --------------------------------------------------------------- + */ + +Services::exceptions()->initialize(); + +// Initialize Kint Services::autoloader()->initializeKint(CI_DEBUG); From 83c15b90de3496f6360f1b1d793b78f07c6568e1 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 18 Feb 2024 22:23:48 +0900 Subject: [PATCH 08/22] refactor: move CodeIgniter::resolvePlatformExtensions() to bootstrap.php --- system/CodeIgniter.php | 7 ++----- system/bootstrap.php | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index 706e8404c945..99a230e88436 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -186,11 +186,6 @@ public function __construct(App $config) */ public function initialize() { - // Run this check for manual installations - if (! is_file(COMPOSER_PATH)) { - $this->resolvePlatformExtensions(); // @codeCoverageIgnore - } - // Set default locale on the server Locale::setDefault($this->config->defaultLocale ?? 'en'); @@ -206,6 +201,8 @@ public function initialize() * @throws FrameworkException * * @codeCoverageIgnore + * + * @deprecated 4.5.0 Moved to system/bootstrap.php. */ protected function resolvePlatformExtensions() { diff --git a/system/bootstrap.php b/system/bootstrap.php index 58f8d645a748..617492428b55 100644 --- a/system/bootstrap.php +++ b/system/bootstrap.php @@ -11,6 +11,7 @@ * the LICENSE file that was distributed with this source code. */ +use CodeIgniter\Exceptions\FrameworkException; use Config\Autoload; use Config\Modules; use Config\Paths; @@ -144,5 +145,37 @@ Services::exceptions()->initialize(); -// Initialize Kint +/* + * --------------------------------------------------------------- + * CHECK SYSTEM FOR MISSING REQUIRED PHP EXTENSIONS + * --------------------------------------------------------------- + */ + +// Run this check for manual installations +if (! is_file(COMPOSER_PATH)) { + $requiredExtensions = [ + 'intl', + 'json', + 'mbstring', + ]; + + $missingExtensions = []; + + foreach ($requiredExtensions as $extension) { + if (! extension_loaded($extension)) { + $missingExtensions[] = $extension; + } + } + + if ($missingExtensions !== []) { + throw FrameworkException::forMissingExtension(implode(', ', $missingExtensions)); + } +} + +/* + * --------------------------------------------------------------- + * INITIALIZE KINT + * --------------------------------------------------------------- + */ + Services::autoloader()->initializeKint(CI_DEBUG); From fb00173561710b359640fe8ca8185dfd56954c3f Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 18 Feb 2024 22:44:34 +0900 Subject: [PATCH 09/22] refactor: remove variables --- system/bootstrap.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/system/bootstrap.php b/system/bootstrap.php index 617492428b55..058160dd75b4 100644 --- a/system/bootstrap.php +++ b/system/bootstrap.php @@ -153,15 +153,13 @@ // Run this check for manual installations if (! is_file(COMPOSER_PATH)) { - $requiredExtensions = [ + $missingExtensions = []; + + foreach ([ 'intl', 'json', 'mbstring', - ]; - - $missingExtensions = []; - - foreach ($requiredExtensions as $extension) { + ] as $extension) { if (! extension_loaded($extension)) { $missingExtensions[] = $extension; } @@ -170,6 +168,8 @@ if ($missingExtensions !== []) { throw FrameworkException::forMissingExtension(implode(', ', $missingExtensions)); } + + unset($missingExtensions); } /* From a87af65a53030a9b2b517ed4256d847f95728921 Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 19 Feb 2024 07:13:38 +0900 Subject: [PATCH 10/22] refactor: match test/bootstrap to system/bootstrap as much as possible --- system/Test/bootstrap.php | 127 +++++++++++++++++++++++++++++--------- 1 file changed, 99 insertions(+), 28 deletions(-) diff --git a/system/Test/bootstrap.php b/system/Test/bootstrap.php index 15b1b8cc4b2d..4c9380b82b67 100644 --- a/system/Test/bootstrap.php +++ b/system/Test/bootstrap.php @@ -21,11 +21,52 @@ ini_set('display_errors', '1'); ini_set('display_startup_errors', '1'); +/* + * --------------------------------------------------------------- + * DEFINE ENVIRONMENT + * --------------------------------------------------------------- + */ + // Make sure it recognizes that we're testing. $_SERVER['CI_ENVIRONMENT'] = 'testing'; define('ENVIRONMENT', 'testing'); + defined('CI_DEBUG') || define('CI_DEBUG', true); +/* + *--------------------------------------------------------------- + * BOOTSTRAP THE APPLICATION + *--------------------------------------------------------------- + * This process sets up the path constants, loads and registers + * our autoloader, along with Composer's, loads our constants + * and fires up an environment-specific bootstrapping. + */ + +// LOAD OUR PATHS CONFIG FILE +// Load framework paths from their config file +require CONFIGPATH . 'Paths.php'; +$paths = new Paths(); + +// LOAD DOTENV FILE +// Load environment settings from .env files into $_SERVER and $_ENV +require_once $paths->systemDirectory . '/Config/DotEnv.php'; +(new DotEnv($paths->appDirectory . '/../'))->load(); + +// Set environment values that would otherwise stop the framework from functioning during tests. +if (! isset($_SERVER['app.baseURL'])) { + $_SERVER['app.baseURL'] = 'http://example.com/'; +} + +/* + * --------------------------------------------------------------- + * SETUP OUR PATH CONSTANTS + * --------------------------------------------------------------- + * + * The path constants provide convenient access to the folders + * throughout the application. We have to setup them up here + * so they are available in the config files that are loaded. + */ + // Often these constants are pre-defined, but query the current directory structure as a fallback defined('HOMEPATH') || define('HOMEPATH', realpath(rtrim(getcwd(), '\\/ ')) . DIRECTORY_SEPARATOR); $source = is_dir(HOMEPATH . 'app') @@ -35,31 +76,48 @@ defined('PUBLICPATH') || define('PUBLICPATH', realpath($source . 'public') . DIRECTORY_SEPARATOR); unset($source); -// Load framework paths from their config file -require CONFIGPATH . 'Paths.php'; -$paths = new Paths(); +// Define necessary framework path constants +defined('APPPATH') || define('APPPATH', realpath(rtrim($paths->appDirectory, '\\/ ')) . DIRECTORY_SEPARATOR); +defined('ROOTPATH') || define('ROOTPATH', realpath(APPPATH . '../') . DIRECTORY_SEPARATOR); +defined('SYSTEMPATH') || define('SYSTEMPATH', realpath(rtrim($paths->systemDirectory, '\\/')) . DIRECTORY_SEPARATOR); +defined('WRITEPATH') || define('WRITEPATH', realpath(rtrim($paths->writableDirectory, '\\/ ')) . DIRECTORY_SEPARATOR); +defined('TESTPATH') || define('TESTPATH', realpath(HOMEPATH . 'tests/') . DIRECTORY_SEPARATOR); -// Load environment settings from .env files into $_SERVER and $_ENV -require_once $paths->systemDirectory . '/Config/DotEnv.php'; -(new DotEnv($paths->appDirectory . '/../'))->load(); +defined('CIPATH') || define('CIPATH', realpath(SYSTEMPATH . '../') . DIRECTORY_SEPARATOR); +defined('FCPATH') || define('FCPATH', realpath(PUBLICPATH) . DIRECTORY_SEPARATOR); -// Define necessary framework path constants -defined('APPPATH') || define('APPPATH', realpath(rtrim($paths->appDirectory, '\\/ ')) . DIRECTORY_SEPARATOR); -defined('WRITEPATH') || define('WRITEPATH', realpath(rtrim($paths->writableDirectory, '\\/ ')) . DIRECTORY_SEPARATOR); -defined('SYSTEMPATH') || define('SYSTEMPATH', realpath(rtrim($paths->systemDirectory, '\\/')) . DIRECTORY_SEPARATOR); -defined('ROOTPATH') || define('ROOTPATH', realpath(APPPATH . '../') . DIRECTORY_SEPARATOR); -defined('CIPATH') || define('CIPATH', realpath(SYSTEMPATH . '../') . DIRECTORY_SEPARATOR); -defined('FCPATH') || define('FCPATH', realpath(PUBLICPATH) . DIRECTORY_SEPARATOR); -defined('TESTPATH') || define('TESTPATH', realpath(HOMEPATH . 'tests/') . DIRECTORY_SEPARATOR); defined('SUPPORTPATH') || define('SUPPORTPATH', realpath(TESTPATH . '_support/') . DIRECTORY_SEPARATOR); defined('COMPOSER_PATH') || define('COMPOSER_PATH', (string) realpath(HOMEPATH . 'vendor/autoload.php')); defined('VENDORPATH') || define('VENDORPATH', realpath(HOMEPATH . 'vendor') . DIRECTORY_SEPARATOR); -// Load environment bootstrap +/* + * --------------------------------------------------------------- + * 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'; } +/* + * --------------------------------------------------------------- + * GRAB OUR CONSTANTS + * --------------------------------------------------------------- + */ + +require_once APPPATH . 'Config/Constants.php'; + +/* + * --------------------------------------------------------------- + * LOAD COMMON FUNCTIONS + * --------------------------------------------------------------- + */ + // Load Common.php from App then System if (is_file(APPPATH . 'Common.php')) { require_once APPPATH . 'Common.php'; @@ -67,15 +125,18 @@ require_once SYSTEMPATH . 'Common.php'; -// Set environment values that would otherwise stop the framework from functioning during tests. -if (! isset($_SERVER['app.baseURL'])) { - $_SERVER['app.baseURL'] = 'http://example.com/'; -} +/* + * --------------------------------------------------------------- + * LOAD OUR AUTOLOADER + * --------------------------------------------------------------- + * + * The autoloader allows all of the pieces to work together in the + * framework. We have to load it here, though, so that the config + * files can use the path constants. + */ -// Load necessary components require_once SYSTEMPATH . 'Config/AutoloadConfig.php'; require_once APPPATH . 'Config/Autoload.php'; -require_once APPPATH . 'Config/Constants.php'; require_once SYSTEMPATH . 'Modules/Modules.php'; require_once APPPATH . 'Config/Modules.php'; @@ -88,10 +149,20 @@ Services::autoloader()->initialize(new Autoload(), new Modules())->register(); Services::autoloader()->loadHelpers(); -// Setup Exception Handling +/* + * --------------------------------------------------------------- + * SET EXCEPTION AND ERROR HANDLERS + * --------------------------------------------------------------- + */ + Services::exceptions()->initialize(); -// Initialize Kint +/* + * --------------------------------------------------------------- + * INITIALIZE KINT + * --------------------------------------------------------------- + */ + Services::autoloader()->initializeKint(CI_DEBUG); // Now load Composer's if it's available @@ -99,10 +170,10 @@ require_once COMPOSER_PATH; } -// Load environment settings from .env files into $_SERVER and $_ENV -require_once SYSTEMPATH . 'Config/DotEnv.php'; - -$env = new DotEnv(ROOTPATH); -$env->load(); +/* + * --------------------------------------------------------------- + * LOAD ROUTES + * --------------------------------------------------------------- + */ Services::routes()->loadRoutes(); From 3c8b1c32912e539c281382a39d358b24784eb998 Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 19 Feb 2024 07:31:52 +0900 Subject: [PATCH 11/22] refactor: remove `$_SERVER['app.baseURL'] = 'http://example.com/'` The value is set by phpnit.xml.dist, and there is no need to change baseURL. --- system/Test/bootstrap.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/system/Test/bootstrap.php b/system/Test/bootstrap.php index 4c9380b82b67..c5662a2a572c 100644 --- a/system/Test/bootstrap.php +++ b/system/Test/bootstrap.php @@ -52,11 +52,6 @@ require_once $paths->systemDirectory . '/Config/DotEnv.php'; (new DotEnv($paths->appDirectory . '/../'))->load(); -// Set environment values that would otherwise stop the framework from functioning during tests. -if (! isset($_SERVER['app.baseURL'])) { - $_SERVER['app.baseURL'] = 'http://example.com/'; -} - /* * --------------------------------------------------------------- * SETUP OUR PATH CONSTANTS From a1c1be271661d5de819d796794095ebca9fd49ba Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 19 Feb 2024 07:41:55 +0900 Subject: [PATCH 12/22] refactor: remove unneeded `require_once COMPOSER_PATH` It is done in `Services::autoload()->initialize()`. --- system/Test/bootstrap.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/system/Test/bootstrap.php b/system/Test/bootstrap.php index c5662a2a572c..73d894379736 100644 --- a/system/Test/bootstrap.php +++ b/system/Test/bootstrap.php @@ -160,11 +160,6 @@ Services::autoloader()->initializeKint(CI_DEBUG); -// Now load Composer's if it's available -if (is_file(COMPOSER_PATH)) { - require_once COMPOSER_PATH; -} - /* * --------------------------------------------------------------- * LOAD ROUTES From ff6a2d5e4088907db8a33df6fc6e67a9422e15b4 Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 19 Feb 2024 07:51:07 +0900 Subject: [PATCH 13/22] fix: move LOAD ENVIRONMENT BOOTSTRAP to index.php This was in CodeIgniter::initialize(), so it was called only in web. --- public/index.php | 10 ++++++++++ system/bootstrap.php | 21 --------------------- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/public/index.php b/public/index.php index 9df0b8e86a67..c266197e44be 100644 --- a/public/index.php +++ b/public/index.php @@ -52,6 +52,16 @@ require_once $paths->systemDirectory . '/Config/DotEnv.php'; (new CodeIgniter\Config\DotEnv($paths->appDirectory . '/../'))->load(); +// LOAD ENVIRONMENT BOOTSTRAP +if (is_file(APPPATH . 'Config/Boot/' . ENVIRONMENT . '.php')) { + require_once APPPATH . 'Config/Boot/' . ENVIRONMENT . '.php'; +} else { + header('HTTP/1.1 503 Service Unavailable.', true, 503); + echo 'The application environment is not set correctly.'; + + exit(EXIT_ERROR); // EXIT_ERROR +} + // LOAD THE FRAMEWORK BOOTSTRAP FILE require rtrim($paths->systemDirectory, '\\/ ') . DIRECTORY_SEPARATOR . 'bootstrap.php'; diff --git a/system/bootstrap.php b/system/bootstrap.php index 058160dd75b4..ce9765995c61 100644 --- a/system/bootstrap.php +++ b/system/bootstrap.php @@ -66,27 +66,6 @@ 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 From 3f55c98deaef72f90ba4c0d7564a7cd786431c18 Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 19 Feb 2024 08:40:49 +0900 Subject: [PATCH 14/22] fix: move BOOTSTRAP THE APPLICATION down CONFIGPATH was not defined yet. --- system/Test/bootstrap.php | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/system/Test/bootstrap.php b/system/Test/bootstrap.php index 73d894379736..470c3be5909f 100644 --- a/system/Test/bootstrap.php +++ b/system/Test/bootstrap.php @@ -33,25 +33,6 @@ defined('CI_DEBUG') || define('CI_DEBUG', true); -/* - *--------------------------------------------------------------- - * BOOTSTRAP THE APPLICATION - *--------------------------------------------------------------- - * This process sets up the path constants, loads and registers - * our autoloader, along with Composer's, loads our constants - * and fires up an environment-specific bootstrapping. - */ - -// LOAD OUR PATHS CONFIG FILE -// Load framework paths from their config file -require CONFIGPATH . 'Paths.php'; -$paths = new Paths(); - -// LOAD DOTENV FILE -// Load environment settings from .env files into $_SERVER and $_ENV -require_once $paths->systemDirectory . '/Config/DotEnv.php'; -(new DotEnv($paths->appDirectory . '/../'))->load(); - /* * --------------------------------------------------------------- * SETUP OUR PATH CONSTANTS @@ -85,6 +66,25 @@ defined('COMPOSER_PATH') || define('COMPOSER_PATH', (string) realpath(HOMEPATH . 'vendor/autoload.php')); defined('VENDORPATH') || define('VENDORPATH', realpath(HOMEPATH . 'vendor') . DIRECTORY_SEPARATOR); +/* + *--------------------------------------------------------------- + * BOOTSTRAP THE APPLICATION + *--------------------------------------------------------------- + * This process sets up the path constants, loads and registers + * our autoloader, along with Composer's, loads our constants + * and fires up an environment-specific bootstrapping. + */ + +// LOAD OUR PATHS CONFIG FILE +// Load framework paths from their config file +require CONFIGPATH . 'Paths.php'; +$paths = new Paths(); + +// LOAD DOTENV FILE +// Load environment settings from .env files into $_SERVER and $_ENV +require_once $paths->systemDirectory . '/Config/DotEnv.php'; +(new DotEnv($paths->appDirectory . '/../'))->load(); + /* * --------------------------------------------------------------- * LOAD ENVIRONMENT BOOTSTRAP From a3bccfb1264200daa973f3d03b4a9f1c93a0f940 Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 19 Feb 2024 09:19:15 +0900 Subject: [PATCH 15/22] fix: add missing LOAD ENVIRONMENT BOOTSTRAP --- spark | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spark b/spark index 16af4a543c52..a166f32726c2 100755 --- a/spark +++ b/spark @@ -80,6 +80,16 @@ $paths = new Config\Paths(); require_once $paths->systemDirectory . '/Config/DotEnv.php'; (new CodeIgniter\Config\DotEnv($paths->appDirectory . '/../'))->load(); +// LOAD ENVIRONMENT BOOTSTRAP +if (is_file(APPPATH . 'Config/Boot/' . ENVIRONMENT . '.php')) { + require_once APPPATH . 'Config/Boot/' . ENVIRONMENT . '.php'; +} else { + header('HTTP/1.1 503 Service Unavailable.', true, 503); + echo 'The application environment is not set correctly.'; + + exit(EXIT_ERROR); // EXIT_ERROR +} + // LOAD THE FRAMEWORK BOOTSTRAP FILE require rtrim($paths->systemDirectory, '\\/ ') . DIRECTORY_SEPARATOR . 'bootstrap.php'; From 10a60e03bb320a2ed4a85a2fb6fae0286b8e9a36 Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 19 Feb 2024 09:32:06 +0900 Subject: [PATCH 16/22] fix: index.php and spark do not work --- public/index.php | 11 +++++++++-- spark | 11 +++++++++-- system/bootstrap.php | 12 ------------ 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/public/index.php b/public/index.php index c266197e44be..0bfbce2053fd 100644 --- a/public/index.php +++ b/public/index.php @@ -52,9 +52,16 @@ require_once $paths->systemDirectory . '/Config/DotEnv.php'; (new CodeIgniter\Config\DotEnv($paths->appDirectory . '/../'))->load(); +// DEFINE ENVIRONMENT +if (! defined('ENVIRONMENT')) { + $env = $_ENV['CI_ENVIRONMENT'] ?? $_SERVER['CI_ENVIRONMENT'] ?? getenv('CI_ENVIRONMENT'); + define('ENVIRONMENT', ($env !== false) ? $env : 'production'); + unset($env); +} + // LOAD ENVIRONMENT BOOTSTRAP -if (is_file(APPPATH . 'Config/Boot/' . ENVIRONMENT . '.php')) { - require_once APPPATH . 'Config/Boot/' . ENVIRONMENT . '.php'; +if (is_file($paths->appDirectory . '/Config/Boot/' . ENVIRONMENT . '.php')) { + require_once $paths->appDirectory . '/Config/Boot/' . ENVIRONMENT . '.php'; } else { header('HTTP/1.1 503 Service Unavailable.', true, 503); echo 'The application environment is not set correctly.'; diff --git a/spark b/spark index a166f32726c2..6b4034131925 100755 --- a/spark +++ b/spark @@ -80,9 +80,16 @@ $paths = new Config\Paths(); require_once $paths->systemDirectory . '/Config/DotEnv.php'; (new CodeIgniter\Config\DotEnv($paths->appDirectory . '/../'))->load(); +// DEFINE ENVIRONMENT +if (! defined('ENVIRONMENT')) { + $env = $_ENV['CI_ENVIRONMENT'] ?? $_SERVER['CI_ENVIRONMENT'] ?? getenv('CI_ENVIRONMENT'); + define('ENVIRONMENT', ($env !== false) ? $env : 'production'); + unset($env); +} + // LOAD ENVIRONMENT BOOTSTRAP -if (is_file(APPPATH . 'Config/Boot/' . ENVIRONMENT . '.php')) { - require_once APPPATH . 'Config/Boot/' . ENVIRONMENT . '.php'; +if (is_file($paths->appDirectory . '/Config/Boot/' . ENVIRONMENT . '.php')) { + require_once $paths->appDirectory . '/Config/Boot/' . ENVIRONMENT . '.php'; } else { header('HTTP/1.1 503 Service Unavailable.', true, 503); echo 'The application environment is not set correctly.'; diff --git a/system/bootstrap.php b/system/bootstrap.php index ce9765995c61..84d52cef5cbc 100644 --- a/system/bootstrap.php +++ b/system/bootstrap.php @@ -17,18 +17,6 @@ use Config\Paths; use Config\Services; -/* - * --------------------------------------------------------------- - * DEFINE ENVIRONMENT - * --------------------------------------------------------------- - */ - -if (! defined('ENVIRONMENT')) { - $env = $_ENV['CI_ENVIRONMENT'] ?? $_SERVER['CI_ENVIRONMENT'] ?? getenv('CI_ENVIRONMENT'); - define('ENVIRONMENT', ($env !== false) ? $env : 'production'); - unset($env); -} - /* * --------------------------------------------------------------- * SETUP OUR PATH CONSTANTS From 793b57a3c5f1c9dfb71935c6d4769dc6cc6f0099 Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 19 Feb 2024 10:07:25 +0900 Subject: [PATCH 17/22] fix: Undefined variable $paths --- system/Test/bootstrap.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/system/Test/bootstrap.php b/system/Test/bootstrap.php index 470c3be5909f..08c6b2e52519 100644 --- a/system/Test/bootstrap.php +++ b/system/Test/bootstrap.php @@ -52,6 +52,11 @@ defined('PUBLICPATH') || define('PUBLICPATH', realpath($source . 'public') . DIRECTORY_SEPARATOR); unset($source); +// LOAD OUR PATHS CONFIG FILE +// Load framework paths from their config file +require CONFIGPATH . 'Paths.php'; +$paths = new Paths(); + // Define necessary framework path constants defined('APPPATH') || define('APPPATH', realpath(rtrim($paths->appDirectory, '\\/ ')) . DIRECTORY_SEPARATOR); defined('ROOTPATH') || define('ROOTPATH', realpath(APPPATH . '../') . DIRECTORY_SEPARATOR); @@ -75,11 +80,6 @@ * and fires up an environment-specific bootstrapping. */ -// LOAD OUR PATHS CONFIG FILE -// Load framework paths from their config file -require CONFIGPATH . 'Paths.php'; -$paths = new Paths(); - // LOAD DOTENV FILE // Load environment settings from .env files into $_SERVER and $_ENV require_once $paths->systemDirectory . '/Config/DotEnv.php'; From 48307b5b427a50267ba706a33991a13f9edeef0a Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 19 Feb 2024 12:45:20 +0900 Subject: [PATCH 18/22] chore: add exlucde for PHPCPD --- .github/workflows/test-phpcpd.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test-phpcpd.yml b/.github/workflows/test-phpcpd.yml index 5c89eaf4337e..c0bf72f3bf10 100644 --- a/.github/workflows/test-phpcpd.yml +++ b/.github/workflows/test-phpcpd.yml @@ -57,4 +57,5 @@ jobs: --exclude system/Debug/Exceptions.php --exclude system/HTTP/SiteURI.php --exclude system/Validation/Rules.php + --exclude system/Autoloader/Autoloader.php -- app/ public/ system/ From 46230e717b78b90da8fc43894bb2a1f89a6bb99a Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 4 Mar 2024 08:04:43 +0900 Subject: [PATCH 19/22] docs: add user guide --- user_guide_src/source/changelogs/v4.5.0.rst | 16 +++++++++++++-- .../source/installation/upgrade_450.rst | 20 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/user_guide_src/source/changelogs/v4.5.0.rst b/user_guide_src/source/changelogs/v4.5.0.rst index f0b24389f329..caa0a3f296c9 100644 --- a/user_guide_src/source/changelogs/v4.5.0.rst +++ b/user_guide_src/source/changelogs/v4.5.0.rst @@ -451,10 +451,22 @@ Changes Deprecations ************ -- **CodeIgniter:** The ``determinePath()`` method has been deprecated. No longer - used. - **Services:** The ``BaseService::$services`` property has been deprecated. No longer used. +- **CodeIgniter:** + - The ``determinePath()`` method has been deprecated. No longer used. + - The ``resolvePlatformExtensions()`` method has been deprecated. No longer + used. It has been moved to the ``CodeIgniter\Boot::checkMissingExtensions()`` + method. + - The ``bootstrapEnvironment()`` method has been deprecated. No longer used. + It has been moved to the ``CodeIgniter\Boot::loadEnvironmentBootstrap()`` + method. + - The ``initializeKint()`` method has been deprecated. No longer used. It has + been moved to the ``Autoloader``. + - The ``autoloadKint()`` method has been deprecated. No longer used. It has + been moved to the ``Autoloader``. + - The ``configureKint()`` method has been deprecated. No longer used. It has + been moved to the ``Autoloader``. - **Response:** The constructor parameter ``$config`` has been deprecated. No longer used. - **Filters:** diff --git a/user_guide_src/source/installation/upgrade_450.rst b/user_guide_src/source/installation/upgrade_450.rst index 53498a20b301..27fe4bc67593 100644 --- a/user_guide_src/source/installation/upgrade_450.rst +++ b/user_guide_src/source/installation/upgrade_450.rst @@ -15,6 +15,26 @@ Please refer to the upgrade instructions corresponding to your installation meth Mandatory File Changes ********************** +index.php and spark +=================== + +The following files received significant changes and +**you must merge the updated versions** with your application: + +- ``public/index.php`` +- ``spark`` + +.. important:: If you don't update the above files, CodeIgniter will not work + properly after running ``composer update``. + + The upgrade procedure, for example, is as follows: + + .. code-block:: console + + composer update + cp vendor/codeigniter4/framework/public/index.php public/index.php + cp vendor/codeigniter4/framework/spark spark + Breaking Changes **************** From 3dba2bc1bffc7373f3251c1645e47bdd95abce81 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 15 Mar 2024 20:36:51 +0900 Subject: [PATCH 20/22] docs: fix by proofreading Co-authored-by: MGatner --- system/Test/bootstrap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Test/bootstrap.php b/system/Test/bootstrap.php index 08c6b2e52519..47d50d25bb19 100644 --- a/system/Test/bootstrap.php +++ b/system/Test/bootstrap.php @@ -35,7 +35,7 @@ /* * --------------------------------------------------------------- - * SETUP OUR PATH CONSTANTS + * SET UP OUR PATH CONSTANTS * --------------------------------------------------------------- * * The path constants provide convenient access to the folders From e75e128103e0d1e7d07cb6cec0329c724c38826e Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 15 Mar 2024 20:38:41 +0900 Subject: [PATCH 21/22] docs: fix by proofreading Co-authored-by: MGatner --- system/Test/bootstrap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Test/bootstrap.php b/system/Test/bootstrap.php index 47d50d25bb19..776250abfac3 100644 --- a/system/Test/bootstrap.php +++ b/system/Test/bootstrap.php @@ -39,7 +39,7 @@ * --------------------------------------------------------------- * * The path constants provide convenient access to the folders - * throughout the application. We have to setup them up here + * throughout the application. We have to set them up here * so they are available in the config files that are loaded. */ From 458333cf9802f382e3e263c1feee04de19a6ef38 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 15 Mar 2024 20:31:22 +0900 Subject: [PATCH 22/22] docs: add Bootstrap change to changelog --- user_guide_src/source/changelogs/v4.5.0.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/user_guide_src/source/changelogs/v4.5.0.rst b/user_guide_src/source/changelogs/v4.5.0.rst index caa0a3f296c9..d4219c7b0333 100644 --- a/user_guide_src/source/changelogs/v4.5.0.rst +++ b/user_guide_src/source/changelogs/v4.5.0.rst @@ -432,6 +432,8 @@ Message Changes Changes ******* +- **Bootstrap:** The loading of **.env** and defining ``ENVIRONMENT`` have been + moved before loading of **bootstrap.php**. - **Config:** - ``Config\Feature::$multipleFilters`` has been removed, because now :ref:`multiple-filters` are always enabled.