CodeIgniter4/system/bootstrap.php

160 lines
4.2 KiB
PHP
Raw Normal View History

<?php
2017-01-20 00:57:53 -08:00
/**
2020-10-24 16:38:41 +08:00
* This file is part of the CodeIgniter 4 framework.
2017-01-20 00:57:53 -08:00
*
2020-10-24 16:38:41 +08:00
* (c) CodeIgniter Foundation <admin@codeigniter.com>
2017-01-20 00:57:53 -08:00
*
2020-10-24 16:38:41 +08:00
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
2017-01-20 00:57:53 -08:00
*/
use CodeIgniter\Config\DotEnv;
use Config\Autoload;
use Config\Modules;
2021-01-05 22:20:17 +07:00
use Config\Paths;
2020-11-03 19:46:10 +02:00
use Config\Services;
/*
* ---------------------------------------------------------------
* 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.
*/
2020-08-28 19:29:52 +08:00
// The path to the application directory.
2018-12-03 17:31:31 -02:00
if (! defined('APPPATH'))
{
2021-06-04 22:51:52 +08:00
/**
* @var Paths $paths
*/
define('APPPATH', realpath(rtrim($paths->appDirectory, '\\/ ')) . DIRECTORY_SEPARATOR);
}
2020-08-28 19:29:52 +08:00
// The path to the project root directory. Just above APPPATH.
2018-12-03 17:31:31 -02:00
if (! defined('ROOTPATH'))
{
2021-06-04 22:51:52 +08:00
define('ROOTPATH', realpath(APPPATH . '../') . DIRECTORY_SEPARATOR);
}
2020-08-28 19:29:52 +08:00
// The path to the system directory.
2018-12-07 17:44:44 -02:00
if (! defined('SYSTEMPATH'))
{
2021-06-04 22:51:52 +08:00
/**
* @var Paths $paths
*/
define('SYSTEMPATH', realpath(rtrim($paths->systemDirectory, '\\/ ')) . DIRECTORY_SEPARATOR);
}
2020-08-28 19:29:52 +08:00
// The path to the writable directory.
if (! defined('WRITEPATH'))
{
2021-06-04 22:51:52 +08:00
/**
* @var Paths $paths
*/
define('WRITEPATH', realpath(rtrim($paths->writableDirectory, '\\/ ')) . DIRECTORY_SEPARATOR);
}
2020-08-28 19:29:52 +08:00
// The path to the tests directory
if (! defined('TESTPATH'))
{
2021-06-04 22:51:52 +08:00
/**
* @var Paths $paths
*/
define('TESTPATH', realpath(rtrim($paths->testsDirectory, '\\/ ')) . DIRECTORY_SEPARATOR);
}
/*
* ---------------------------------------------------------------
* GRAB OUR CONSTANTS & COMMON
* ---------------------------------------------------------------
*/
if (! defined('APP_NAMESPACE'))
{
2021-06-04 22:51:52 +08:00
require_once APPPATH . 'Config/Constants.php';
}
// Require app/Common.php file if exists.
if (is_file(APPPATH . 'Common.php'))
2019-08-27 23:00:26 -05:00
{
2021-06-04 22:51:52 +08:00
require_once APPPATH . 'Common.php';
}
// Require system/Common.php
2018-12-07 17:44:44 -02:00
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.
*/
2020-08-28 19:29:52 +08:00
if (! class_exists('Config\Autoload', false))
{
2021-06-04 22:51:52 +08:00
require_once SYSTEMPATH . 'Config/AutoloadConfig.php';
require_once APPPATH . 'Config/Autoload.php';
require_once SYSTEMPATH . 'Modules/Modules.php';
require_once APPPATH . 'Config/Modules.php';
}
2018-12-07 17:44:44 -02:00
require_once SYSTEMPATH . 'Autoloader/Autoloader.php';
require_once SYSTEMPATH . 'Config/BaseService.php';
2020-11-03 19:46:10 +02:00
require_once SYSTEMPATH . 'Config/Services.php';
require_once APPPATH . 'Config/Services.php';
// Use Config\Services as CodeIgniter\Services
if (! class_exists('CodeIgniter\Services', false))
{
2021-06-04 22:51:52 +08:00
class_alias('Config\Services', 'CodeIgniter\Services');
2020-11-03 19:46:10 +02:00
}
// Initialize and register the loader with the SPL autoloader stack.
2020-11-03 19:46:10 +02:00
Services::autoloader()->initialize(new Autoload(), new Modules())->register();
// Now load Composer's if it's available
if (is_file(COMPOSER_PATH))
{
2021-06-04 22:51:52 +08:00
/*
* The path to the vendor directory.
*
* We do not want to enforce this, so set the constant if Composer was used.
*/
if (! defined('VENDORPATH'))
{
define('VENDORPATH', realpath(ROOTPATH . 'vendor') . DIRECTORY_SEPARATOR);
}
require_once COMPOSER_PATH;
}
// Load environment settings from .env files into $_SERVER and $_ENV
2018-12-07 17:44:44 -02:00
require_once SYSTEMPATH . 'Config/DotEnv.php';
2020-10-04 00:27:56 +07:00
$env = new DotEnv(ROOTPATH);
$env->load();
// Always load the URL helper, it should be used in most of apps.
helper('url');
/*
* ---------------------------------------------------------------
* GRAB OUR CODEIGNITER INSTANCE
* ---------------------------------------------------------------
*
* The CodeIgniter class contains the core functionality to make
* the application run, and does all of the dirty work to get
* the pieces all working together.
*/
2021-03-01 20:44:40 +02:00
$app = Services::codeigniter();
$app->initialize();
return $app;