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,首先得弄清楚容器的概念。

  • 相关阅读:
    小球与盒子的故事
    2020.1.11 考试总结
    P4249 [WC2007]剪刀石头布
    P3825 [NOI2017]游戏
    BZOJ 2238 Mst
    P4240 毒瘤之神的考验
    生成函数(严重残缺)
    Min_25
    P3455 [POI2007]ZAP-Queries
    P3233 [HNOI2014]世界树
  • 原文地址:https://www.cnblogs.com/hjyang2012/p/5547771.html
Copyright © 2011-2022 走看看