在bootstrap/app.php

/**
* 对于其中的instance register singleton 方法到时候单独拎出来说明
*
* 1.设置基础路径
* 2.使用instance 方法 绑定app 和Illuminate\Foundation\Application类的关系
* 3.使用instance 方法 绑定Container 和Illuminate\Foundation\Application类的关系
* 4.app变量中注册事件服务EventServiceProvider
* 5.app变量中注册日志服务LogServiceProvider
* 6.app变量中注册路由服务RoutingServiceProvider
* 7.别名的注册(vendor/laravel/framework/src/Illuminate/Foundation/Application.php文件中的 registerCoreContainerAliases 方法)
*/
$app = new Illuminate\Foundation\Application(
realpath(__DIR__.'/../')
);

实例化 vendor/laravel/framework/src/Illuminate/Foundation/Application.php类  该类的魔术方法

    public function __construct($basePath = null)
{
/**
* 如果有传地址 设置基础路径 设置
* path $this->path()
* path.base $this->basePath()
* path.lang $this->langPath()
* path.config $this->configPath()
* path.public $this->publicPath()
* path.storage $this->storagePath()
* path.database $this->databasePath()
* path.resources $this->resourcePath()
* path.bootstrap $this->bootstrapPath()
*/
if ($basePath) {
$this->setBasePath($basePath);
} /**
* 注册 app 和container到 instances数组中
*/
$this->registerBaseBindings(); /**
* 注册EventServiceProvider LogServiceProvider RoutingServiceProvider
*/
$this->registerBaseServiceProviders(); /**
* 设置核心类的别名
*/
$this->registerCoreContainerAliases();
}

查看注册 app 和container到 instances数组中

    protected function registerBaseBindings()
{
static::setInstance($this); /**
* 由于初始化中 app没有添加到instances数组中 所以 不会执行build函数 只做了 instances数组中记录了app和$this
*/
$this->instance('app', $this); /**
* 由于初始化中 Container没有添加到instances数组中 所以 不会执行build函数 只做了 instances数组中记录了app和$this
*/
$this->instance(Container::class, $this);
}

查看今天主要的方法 instance

流程图

 public function instance($abstract, $instance)
{ /**
* 如果aliases 数组总存在 则游离abstractAliases 数组 删除其中的存在的值
*/
$this->removeAbstractAlias($abstract); /**
* 判断 在bindings aliases instances其中有一个存现 则返回true
*/
$isBound = $this->bound($abstract); /**
* 删除别名数组中对于的建
*/
unset($this->aliases[$abstract]); // We'll check to determine if this type has been bound before, and if it has
// we will fire the rebound callbacks registered with the container and it
// can be updated with consuming classes that have gotten resolved here.
/**
* 在instances 数组中添加对于的建
*/
$this->instances[$abstract] = $instance; /**
* 如果之前存在实例化 则运行
*/
if ($isBound) {
$this->rebound($abstract);
}
}

第一个方法  removeAbstractAlias

    /**
* Remove an alias from the contextual binding alias cache.
*
* @param string $searched
* @return void
*/
protected function removeAbstractAlias($searched)
{
/**
* 如果在别名数组中不存在则直接返回
*/
if (! isset($this->aliases[$searched])) {
return;
} /**
* 游离抽象别名 吧存在抽象类别名数组中的存在的删除
* @example abstractAliases = ['nameabstract'=>['aliase1','aliases2']]
*/
foreach ($this->abstractAliases as $abstract => $aliases) {
foreach ($aliases as $index => $alias) {
if ($alias == $searched) {
unset($this->abstractAliases[$abstract][$index]);
}
}
}
}

第二个方法:  bound

    /**
* Determine if the given abstract type has been bound.
*
* @param string $abstract
* @return bool
*/
public function bound($abstract)
{
return isset($this->bindings[$abstract]) ||
isset($this->instances[$abstract]) ||
$this->isAlias($abstract);
}

第三个方法: rebound

 /**
* Fire the "rebound" callbacks for the given abstract type.
*
* @param string $abstract
* @return void
*/
protected function rebound($abstract)
{
/**
* 主要实现的功能为 build 方法 实例化制定的类 并且返回该类
*/
$instance = $this->make($abstract); /**
* 查看reboundCallbacks 数组中是否存在该别名创建完成之后需要调用的方法数组
* 存在返回需要调用的方法数组 并且逐个执行
*/
foreach ($this->getReboundCallbacks($abstract) as $callback) {
call_user_func($callback, $this, $instance);
}
}

Laravel (5.5.33) 加载过程---instance方法(二)的更多相关文章

  1. Laravel (5.5.33) 加载过程---make方法(四)

    /** * Resolve the given type from the container. * * @param string $abstract * @return mixed */ publ ...

  2. Laravel (5.5.33) 加载过程(一)

    说明:  由于公司项目使用Laravel 框架  也是第一次接触此框架  作为一个新手 记录使用过程的一些事情  以及对于框架源码分析的记录  整理自己的思路 也希望对大家有帮助  如果那里不对的地方 ...

  3. Laravel (5.5.33) 加载过程(二)

    本次说明代码 /* |-------------------------------------------------------------------------- | Turn On The ...

  4. Spring IOC bean加载过程

    首先我们不要在学习Spring的开始产生畏难情绪.Spring没有臆想的那么高深,相反,它帮我们再项目开发中制定项目框架,简化项目开发.它的主要功能是将项目开发中繁琐的过程流程化,模式化,使用户仅在固 ...

  5. mybatis的sqlSessionFactory的加载过程

    使用过SSM的框架的都知道mybatis这个持久层框架,今天小编就来简单说说这个框架的核心工厂类sqlSessionFactory的加载过程,一般的SSM框架我们都会在spring的applicati ...

  6. Dubbo源码分析之ExtensionLoader加载过程解析

    ExtensionLoader加载机制阅读: Dubbo的类加载机制是模仿jdk的spi加载机制:  Jdk的SPI扩展加载机制:约定是当服务的提供者每增加一个接口的实现类时,需要在jar包的META ...

  7. 重温.NET下Assembly的加载过程 ASP.NET Core Web API下事件驱动型架构的实现(三):基于RabbitMQ的事件总线

    重温.NET下Assembly的加载过程   最近在工作中牵涉到了.NET下的一个古老的问题:Assembly的加载过程.虽然网上有很多文章介绍这部分内容,很多文章也是很久以前就已经出现了,但阅读之后 ...

  8. Tomcat源码分析三:Tomcat启动加载过程(一)的源码解析

    Tomcat启动加载过程(一)的源码解析 今天,我将分享用源码的方式讲解Tomcat启动的加载过程,关于Tomcat的架构请参阅<Tomcat源码分析二:先看看Tomcat的整体架构>一文 ...

  9. Dubbo源码解析之SPI(一):扩展类的加载过程

    Dubbo是一款开源的.高性能且轻量级的Java RPC框架,它提供了三大核心能力:面向接口的远程方法调用.智能容错和负载均衡,以及服务自动注册和发现. Dubbo最早是阿里公司内部的RPC框架,于 ...

随机推荐

  1. 高性能网络编程(1)—accept建立连接‍(转载,作者:陶辉)

    编 写服务器时,许多程序员习惯于使用高层次的组件.中间件(例如OO(面向对象)层层封装过的开源组件),相比于服务器的运行效率而言,他们更关注程序开发 的效率,追求更快的完成项目功能点.希望应用代码完全 ...

  2. [数据分析工具] Pandas 功能介绍(一)

    如果你在使用 Pandas(Python Data Analysis Library) 的话,下面介绍的对你一定会有帮助的. 首先我们先介绍一些简单的概念 DataFrame:行列数据,类似 Exce ...

  3. 《图解http》知识点笔记

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica } p.p2 { margin: 0.0px 0.0px 0.0px 0. ...

  4. Spark算子--partitionBy

    转载请标明出处http://www.cnblogs.com/haozhengfei/p/923b11fce561e82748baa016bcfb8421.html partitionBy--Trans ...

  5. bat脚本设置系统环境变量即时生效

    关于bat的资料多但零碎,记录一下. 1.设置环境变量即时生效:通过重启explorer来实现即时生效(亲测有效) @echo off set curPath=%cd% wmic ENVIRONMEN ...

  6. dedecsm系统(企业简介)类单栏目模版如何修改和调用整理

    作者:佚名 字体:[增加 减小] 来源:互联网 时间:01-15 17:33:07 我要评论 我们的模版里应该都有article_article.htm这个模版;article_article.htm ...

  7. Bootstrap中data-src无法显示图片,但是src可以

    在学习bootstrap时,书中的源码是用的data-src来定义图像位置,但是我在使用的时候无法显示图片:data-src可以在img标签中使用来显示图片吗?我使用src可以,而是用data-src ...

  8. 【JDBC】Java 连接 MySQL 基本过程以及封装数据库工具类

    一. 常用的JDBC API 1. DriverManager类 : 数据库管理类,用于管理一组JDBC驱动程序的基本服务.应用程序和数据库之间可以通过此类建立连接.常用的静态方法如下 static ...

  9. jenkins插件之如何优雅的生成版本号

    一.简介 在持续集成中,版本管理是非常重要的一部分,本章将介绍如何Version Number Plug插件生成优雅的版本号. 二.安装 系统管理-->插件管理 搜索 Version Numbe ...

  10. js中this详解

    this对象是在闭包一节中提到的,书上的原话是:"this对象是在运行时基于函数的执行环境绑定的,在全局函数中,this等于window,而当函数作为某个对象的方法调用时,this等于那个对 ...