zoukankan      html  css  js  c++  java
  • Laravel 流程分析——应用程序初始化

    在整体分析中,我们看到Laravel首先会进行一个app的初始化,代码如下:

    $app = require_once __DIR__.'/../bootstrap/app.php';

    我们具体看看app.php做了什么,以下代码去掉了源代码的注释,添加了我自己的理解

    /*
    * 创建一个app实例,包括以下动作
    * 1.$this->registerBaseBindings();注册基本的绑定对象到容器
    * 2.$this->registerBaseServiceProviders();注册基本的服务提供者,包括服务提供者的依赖
    * 3.$this->registerCoreContainerAliases();注册一些核心对象别名
    * 4.$this->setBasePath($basePath);设置应用基本路径
    */
    $app = new IlluminateFoundationApplication(
        realpath(__DIR__.'/../')
    );
    
    /*
    * 绑定Http内核对象到容器
    */
    $app->singleton(
        IlluminateContractsHttpKernel::class,
        AppHttpKernel::class
    );
    
    /*
    * 绑定Console内核对象到容器
    */
    $app->singleton(
        IlluminateContractsConsoleKernel::class,
        AppConsoleKernel::class
    );
    
    /*
    * 绑定异常处理对象到容器
    */
    $app->singleton(
        IlluminateContractsDebugExceptionHandler::class,
        AppExceptionsHandler::class
    );
    
    return $app;

    我们看到Laravel程序的初始化基本就是注册对象到容器,容器成为了整个Laravel的核心,要理解Lavavel,首先得弄清楚容器的概念。

  • 相关阅读:
    IDEA提交项目到SVN
    动态代理
    eclipse安装svn,初次提交项目到svn
    异常信息:java.lang.IllegalStateException: Cannot forward after response has been committed
    网上商城订单
    学生选课系统
    分页
    用户注册登录 和 数据写入文件的注册登录
    第一次考试(基础部分)
    小数和质数问题
  • 原文地址:https://www.cnblogs.com/hjyang2012/p/5547771.html
Copyright © 2011-2022 走看看