mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
feat: add config Cache::$configCacheEnabled
and move code from index.php to Boot class.
This commit is contained in:
parent
39210beb13
commit
c1ca7b7206
@ -168,4 +168,13 @@ class Cache extends BaseConfig
|
||||
'redis' => RedisHandler::class,
|
||||
'wincache' => WincacheHandler::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* --------------------------------------------------------------------------
|
||||
* Config Caching
|
||||
* --------------------------------------------------------------------------
|
||||
*
|
||||
* @see https://codeigniter.com/user_guide/concepts/factories.html#config-caching
|
||||
*/
|
||||
public bool $configCacheEnabled = false;
|
||||
}
|
||||
|
@ -52,42 +52,5 @@ $paths = new Config\Paths();
|
||||
|
||||
// LOAD THE FRAMEWORK BOOTSTRAP FILE
|
||||
require $paths->systemDirectory . '/Boot.php';
|
||||
CodeIgniter\Boot::BootWeb($paths);
|
||||
|
||||
// Load Config Cache
|
||||
// $factoriesCache = new \CodeIgniter\Cache\FactoriesCache();
|
||||
// $factoriesCache->load('config');
|
||||
// ^^^ Uncomment these lines if you want to use Config Caching.
|
||||
|
||||
/*
|
||||
* ---------------------------------------------------------------
|
||||
* GRAB OUR CODEIGNITER INSTANCE
|
||||
* ---------------------------------------------------------------
|
||||
*
|
||||
* The CodeIgniter class contains the core functionality to make
|
||||
* the application run, and does all the dirty work to get
|
||||
* the pieces all working together.
|
||||
*/
|
||||
|
||||
$app = Config\Services::codeigniter();
|
||||
$app->initialize();
|
||||
$context = is_cli() ? 'php-cli' : 'web';
|
||||
$app->setContext($context);
|
||||
|
||||
/*
|
||||
*---------------------------------------------------------------
|
||||
* LAUNCH THE APPLICATION
|
||||
*---------------------------------------------------------------
|
||||
* Now that everything is set up, it's time to actually fire
|
||||
* up the engines and make this app do its thang.
|
||||
*/
|
||||
|
||||
$app->run();
|
||||
|
||||
// Save Config Cache
|
||||
// $factoriesCache->save('config');
|
||||
// ^^^ Uncomment this line if you want to use Config Caching.
|
||||
|
||||
// Exits the application, setting the exit code for CLI-based applications
|
||||
// that might be watching.
|
||||
exit(EXIT_SUCCESS);
|
||||
exit(CodeIgniter\Boot::BootWeb($paths));
|
||||
|
@ -13,8 +13,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace CodeIgniter;
|
||||
|
||||
use CodeIgniter\Cache\FactoriesCache;
|
||||
use CodeIgniter\Config\DotEnv;
|
||||
use Config\Autoload;
|
||||
use Config\Cache;
|
||||
use Config\Modules;
|
||||
use Config\Paths;
|
||||
use Config\Services;
|
||||
@ -32,21 +34,47 @@ class Boot
|
||||
* Context
|
||||
* web: Invoked by HTTP request
|
||||
* php-cli: Invoked by CLI via `php public/index.php`
|
||||
*
|
||||
* @return int Exit code.
|
||||
*/
|
||||
public static function bootWeb(Paths $paths): void
|
||||
public static function bootWeb(Paths $paths): int
|
||||
{
|
||||
static::boot($paths);
|
||||
static::definePathConstants($paths);
|
||||
if (! defined('APP_NAMESPACE')) {
|
||||
static::loadConstants();
|
||||
}
|
||||
static::checkMissingExtensions();
|
||||
|
||||
static::loadDotEnv($paths);
|
||||
static::defineEnvironment();
|
||||
static::loadEnvironmentBootstrap($paths);
|
||||
|
||||
static::loadCommonFunctions();
|
||||
static::loadAutoloader();
|
||||
static::setExceptionHandler();
|
||||
static::initializeKint();
|
||||
|
||||
$configCacheEnabled = (new Cache())->configCacheEnabled ?? false;
|
||||
if ($configCacheEnabled) {
|
||||
$factoriesCache = static::loadConfigCache();
|
||||
}
|
||||
|
||||
$app = static::initializeCodeIgniter();
|
||||
static::runCodeIgniter($app);
|
||||
|
||||
if ($configCacheEnabled) {
|
||||
static::saveConfigCache($factoriesCache);
|
||||
}
|
||||
|
||||
// Exits the application, setting the exit code for CLI-based
|
||||
// applications that might be watching.
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by `spark`
|
||||
*/
|
||||
public static function bootSpark(Paths $paths): void
|
||||
{
|
||||
static::boot($paths);
|
||||
}
|
||||
|
||||
protected static function boot(Paths $paths): void
|
||||
{
|
||||
static::definePathConstants($paths);
|
||||
if (! defined('APP_NAMESPACE')) {
|
||||
@ -234,4 +262,41 @@ class Boot
|
||||
{
|
||||
Services::autoloader()->initializeKint(CI_DEBUG);
|
||||
}
|
||||
|
||||
protected static function loadConfigCache(): FactoriesCache
|
||||
{
|
||||
$factoriesCache = new FactoriesCache();
|
||||
$factoriesCache->load('config');
|
||||
|
||||
return $factoriesCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* The CodeIgniter class contains the core functionality to make
|
||||
* the application run, and does all the dirty work to get
|
||||
* the pieces all working together.
|
||||
*/
|
||||
protected static function initializeCodeIgniter(): CodeIgniter
|
||||
{
|
||||
$app = Config\Services::codeigniter();
|
||||
$app->initialize();
|
||||
$context = is_cli() ? 'php-cli' : 'web';
|
||||
$app->setContext($context);
|
||||
|
||||
return $app;
|
||||
}
|
||||
|
||||
/**
|
||||
* Now that everything is set up, it's time to actually fire
|
||||
* up the engines and make this app do its thang.
|
||||
*/
|
||||
protected static function runCodeIgniter(CodeIgniter $app): void
|
||||
{
|
||||
$app->run();
|
||||
}
|
||||
|
||||
protected static function saveConfigCache(FactoriesCache $factoriesCache): void
|
||||
{
|
||||
$factoriesCache->save('config');
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user