码迷,mamicode.com
首页 > 移动开发 > 详细

laravel5.5源码阅读草稿——application

时间:2018-09-07 01:04:22      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:redirect   manifest   gem   response   loaded   路径   ali   dispatch   request   

构建方法传入整个项目根目录路径(public文件夹上一级)将其设为基础路径(存在本类basePath属性中)。
__construct > setBasePath > bindPathsInContainer 在容器中绑定路径
 
bindPathsInContainer > instance 在容器中注册已有实例
{
$this->removeAbstractAlias($abstract);这个方法先删除了容器中的对应实例别名
(abstractAliases与aliases有区别,存疑)
$this->rebound 然后如果该键名在bindings属性instances属性aliases属性中任意一个存在,
则运行之前注册该实例时绑定的回调函数进行更新
$this->instances[$abstract] = $instance 最后将路径添加至instances属性
}
 
__construct > registerBaseBindings
{
static::setInstance($this)将application实例注册至Container抽象基类使其全局可用
将Illuminate\Container\Container绑定为application类
绑定了PackageManifest类,vendor路径与bootstrap/cache/packages.php里的服务提供者路径
}
 
__construct > registerBaseServiceProviders 注册了event、日志、路由的服务提供者
传入相应的provider实例,并调用其register方法,将application实例传入provider作为参数进行回调。
RoutingServiceProvider在实例化的时候,又注册了router、urlGenerator、redirector、request、response、dispatcher等类的实例。
将已注册的provider进行标记$this->serviceProviders、$this->loadedProviders[get_class($provider)]
最后追踪到container类的bind方法,也只是把回调函数加入了bindings属性,并设置了是否共享而已
$app->singleton
__construct > registerCoreContainerAliases 将核心类路径存入$this->aliases(别名为键,类名为值)与$this->abstractAliases(类名为键,路径组成的数组为值)中,保存别名

 

laravel5.5源码阅读草稿——application

标签:redirect   manifest   gem   response   loaded   路径   ali   dispatch   request   

原文地址:https://www.cnblogs.com/wyycc/p/9601947.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!