[TOC]
:-: **1 初始化前加载的文件**
>[info] base.php (index.php文件中加载)
> Loader.php (base.php文件中加载)
> convention.php (base.php文件中加载)
* * * * *
:-: **2 初始化前各个文件的作用**
>[info] 1 base.php 框架基础环境搭建 注册自动加载,注册错误处理,加载默认配置
>2 Loader.php 自动加载
>3 convention.php 默认配置
* * * * *
:-: **3 base.php源代码分析**
~~~
namespace think;
// 载入Loader类
require __DIR__ . '/library/think/Loader.php';
// 注册自动加载
Loader::register();
// 注册错误和异常处理机制
Error::register();
// 实现日志接口
if (interface_exists('Psr\Log\LoggerInterface')) {
interface LoggerInterface extends \Psr\Log\LoggerInterface
{}
} else {
interface LoggerInterface
{}
}
// 注册核心类到容器
Container::getInstance()->bind([
'app' => App::class,
'build' => Build::class,
'cache' => Cache::class,
'config' => Config::class,
'cookie' => Cookie::class,
'debug' => Debug::class,
'env' => Env::class,
'hook' => Hook::class,
'lang' => Lang::class,
'log' => Log::class,
'request' => Request::class,
'response' => Response::class,
'route' => Route::class,
'session' => Session::class,
'url' => Url::class,
'validate' => Validate::class,
'view' => View::class,
'rule_name' => route\RuleName::class,
'middlewareDispatcher' => http\middleware\Dispatcher::class,
// 接口依赖注入
'think\LoggerInterface' => Log::class,
]);
// 注册核心类的静态代理
Facade::bind([
facade\App::class => App::class,
facade\Build::class => Build::class,
facade\Cache::class => Cache::class,
facade\Config::class => Config::class,
facade\Cookie::class => Cookie::class,
facade\Debug::class => Debug::class,
facade\Env::class => Env::class,
facade\Hook::class => Hook::class,
facade\Lang::class => Lang::class,
facade\Log::class => Log::class,
facade\Request::class => Request::class,
facade\Response::class => Response::class,
facade\Route::class => Route::class,
facade\Session::class => Session::class,
facade\Url::class => Url::class,
facade\Validate::class => Validate::class,
facade\View::class => View::class,
]);
// 注册类库别名
Loader::addClassAlias([
'App' => facade\App::class,
'Build' => facade\Build::class,
'Cache' => facade\Cache::class,
'Config' => facade\Config::class,
'Cookie' => facade\Cookie::class,
'Db' => Db::class,
'Debug' => facade\Debug::class,
'Env' => facade\Env::class,
'Facade' => Facade::class,
'Hook' => facade\Hook::class,
'Lang' => facade\Lang::class,
'Log' => facade\Log::class,
'Request' => facade\Request::class,
'Response' => facade\Response::class,
'Route' => facade\Route::class,
'Session' => facade\Session::class,
'Url' => facade\Url::class,
'Validate' => facade\Validate::class,
'View' => facade\View::class,
]);
// 加载惯例配置文件
facade\Config::set(include __DIR__ . '/convention.php');
// 加载composer autofile文件
Loader::loadComposerAutoloadFiles();
~~~
>[info] 1 注册自动加载
> **自动加载见 框架工具 自动加载**
> 2 注册错误处理
> **错误处理见 框架工具 异常错误**
> 3 注册Psr日志接口
> 4 注册核心类 Container::getInstance()->bind()
> 5 注册核心类的静态代理 Facade::bind()
>
> **容器和门面 见 框架核心 容器与门面**
* * * * * *
:-: **4 convention.php默认配置**
* * * * *
>[info] 主要包含 thinkphp运行的默认配置内容
> 其中的配置字段可以在config目录下进行自定义配置
>[warning] 配置的内容一级分类包含
> app 应用运行配置
> template 模板解析配置
> log 日志记录配置
> trace trace调试配置
> cache 缓存存储配置
> session session存储配置
> cookie cookie存储配置
> databse 数据库连接配置
> paginate 分页配置