- 入口文件中引入app.php
- app.php中创建app的实例
- app类定义根目录,继承自容器,可以使用容器的操作
- registerBaseBindings 注册基本绑定
- registerBaseServiders 注册基本服务提供者
- registerContainerAliases 注册容器核心别名
- 然后使用其集成容器的功能,绑定Http类、Console类、Exception类
- 实例化Http Kernel时主要对中间件和中间件组进行了加载
- 利用reuqest = Illuminate\Http\Request::capture()); 对请求进行处理,$requrest是获取请求实例
三个核心方法 registerBaseBindings registerBaseServiders registerContainerAliases
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/11/14 0014
* Time: 16:05
*/
//application 类
namespace Slaravel\Foundation;
use Slaravel\Container\Container;
use Slaravel\Support\Facades\Facade;
class Application extends Container
{
protected $basePath;
/**
* Application constructor.
* @param string $basePath 用于设置项目根目录
*/
public function __construct($basePath = '')
{
if($basePath){
$this->setBasePath($basePath);
}
$this->registerBaseBindings();
//$this->register
//给Facade注入application类,laravel中是封装在了服务中心, 在registerBaseServiders中
Facade::setFacadeApplication($this);
//注册核心的容器别名
$this->registerCoreContainerAliases();
}
/**
* 设置根目录
* @param string $basePath
*/
public function setBasePath($basePath){
//设置的路径不包含最后一个斜杠
$this->basePath = rtrim($basePath,'\/');
}
/**
* 获取项目根路径
* @return mixed
*/
public function getBasePath(){
return $this->basePath;
}
/**
* 绑定自己到容器
*/
public function registerBaseBindings(){
$this->instance('app',$this);
}
/**
* 核心容器绑定
*/
public function registerCoreContainerAliases(){
$binds = [
'FacadeTest' => \Slaravel\Support\Facades\FacadeTest::class,
'Config' => \Slaravel\Config\Config::class, //加载配置类
];
foreach ($binds as $name => $class){
$this->bind($name,$class);
}
}
}
网友评论