这个类里面有很这样的使用例如$this->hook->import(); $this->config->get(); $this->request->init();等等
你知道这个对象怎么来的吗?不急,亮仔一一道来:
- app类会继承容器Container(这是关键)
- 容器有个魔术方法很重要 例如当调用$this->hook时找不到会调用魔术方法
public function __get($name)
{
return $this->make($name);
}
3.接着就是容器Container里面的make方法 ,这个make方法里面就是搞事情返回对象
public function make($abstract, $vars = [], $newInstance = false)
{
if (true === $vars) {
// 总是创建新的实例化对象
$newInstance = true;
$vars = [];
}
//容器标识别名有没有
$abstract = isset($this->name[$abstract]) ? $this->name[$abstr