Skip to content

Commit

Permalink
refactor: use Boot class in Test/bootstrap.php
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Feb 19, 2024
1 parent 9c54901 commit 72138c7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 89 deletions.
35 changes: 28 additions & 7 deletions system/Boot.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public static function bootWeb(Paths $paths): void
static::defineEnvironment();
static::loadEnvironmentBootstrap($paths);
static::definePathConstant($paths);
static::loadConstants();
if (! defined('APP_NAMESPACE')) {
static::loadConstants();
}
static::loadCommonFunctions();
static::loadAutoloader();
static::setExceptionHandler();
Expand All @@ -52,6 +54,23 @@ public static function bootSpark(Paths $paths): void
static::defineEnvironment();
static::loadEnvironmentBootstrap($paths);
static::definePathConstant($paths);
if (! defined('APP_NAMESPACE')) {
static::loadConstants();
}
static::loadCommonFunctions();
static::loadAutoloader();
static::setExceptionHandler();
static::checkMissingExtensions();
static::initializeKint();
}

/**
* @used-by system/Test/bootstrap.php
*/
public static function bootTest(Paths $paths): void
{
static::loadDotEnv($paths);
static::loadEnvironmentBootstrap($paths, false);
static::loadConstants();
static::loadCommonFunctions();
static::loadAutoloader();
Expand All @@ -78,15 +97,19 @@ protected static function defineEnvironment(): void
}
}

protected static function loadEnvironmentBootstrap(Paths $paths): void
protected static function loadEnvironmentBootstrap(Paths $paths, bool $exit = true): void
{
if (is_file($paths->appDirectory . '/Config/Boot/' . ENVIRONMENT . '.php')) {
require_once $paths->appDirectory . '/Config/Boot/' . ENVIRONMENT . '.php';
} else {

return;
}

if ($exit) {
header('HTTP/1.1 503 Service Unavailable.', true, 503);
echo 'The application environment is not set correctly.';

exit(EXIT_ERROR); // EXIT_ERROR
exit(EXIT_ERROR);
}
}

Expand Down Expand Up @@ -125,9 +148,7 @@ protected static function definePathConstant(Paths $paths): void

protected static function loadConstants(): void
{
if (! defined('APP_NAMESPACE')) {
require_once APPPATH . 'Config/Constants.php';
}
require_once APPPATH . 'Config/Constants.php';
}

protected static function loadCommonFunctions(): void
Expand Down
85 changes: 3 additions & 82 deletions system/Test/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
* the LICENSE file that was distributed with this source code.
*/

use CodeIgniter\Config\DotEnv;
use Config\Autoload;
use Config\Modules;
use Config\Paths;
use Config\Services;

Expand Down Expand Up @@ -80,85 +77,9 @@
* and fires up an environment-specific bootstrapping.
*/

// 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
* ---------------------------------------------------------------
*
* 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';
}

require_once SYSTEMPATH . 'Common.php';

/*
* ---------------------------------------------------------------
* 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.
*/

require_once SYSTEMPATH . 'Config/AutoloadConfig.php';
require_once APPPATH . 'Config/Autoload.php';
require_once SYSTEMPATH . 'Modules/Modules.php';
require_once APPPATH . 'Config/Modules.php';

require_once SYSTEMPATH . 'Autoloader/Autoloader.php';
require_once SYSTEMPATH . 'Config/BaseService.php';
require_once SYSTEMPATH . 'Config/Services.php';
require_once APPPATH . 'Config/Services.php';

// 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);
// LOAD THE FRAMEWORK BOOTSTRAP FILE
require rtrim($paths->systemDirectory, '\\/ ') . DIRECTORY_SEPARATOR . 'Boot.php';
CodeIgniter\Boot::BootTest($paths);

Check failure on line 82 in system/Test/bootstrap.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis

Call to static method CodeIgniter\Boot::bootTest() with incorrect case: BootTest

/*
* ---------------------------------------------------------------
Expand Down

0 comments on commit 72138c7

Please sign in to comment.