亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 學院 > 開發設計 > 正文

laravel5源碼講解整理

2019-11-14 14:39:51
字體:
來源:轉載
供稿:網友

來源:http://yuez.me/laravel-yuan-ma-jie-du/?utm_source=tuicool&utm_medium=referral

目錄

 

入口文件 index.php

一個基于Laravel的應用,當WEB服務器接受到來自外部的請求后,會將這個這個請求解析到 應用根目錄的 public/index.php 中。

Laravel源碼解讀-index.php (laravel_index.php)download

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
<?php/** * Laravel - A PHP Framework For Web Artisans * * @package  Laravel * @author   Taylor Otwell <taylorotwell@Gmail.com> *//*|--------------------------------------------------------------------------| Register The Auto Loader|--------------------------------------------------------------------------|| Composer provides a convenient, automatically generated class loader for| our application. We just need to utilize it! We'll simply require it| into the script here so that we don't have to worry about manual| loading any of our classes later on. It feels nice to relax.|*/require __DIR__.'/../bootstrap/autoload.php';/*|--------------------------------------------------------------------------| Turn On The Lights|--------------------------------------------------------------------------|| We need to illuminate PHP development, so let us turn on the lights.| This bootstraps the framework and gets it ready for use, then it| will load up this application so that we can run it and send| the responses back to the browser and delight our users.|*/$app = require_once __DIR__.'/../bootstrap/app.php';/*|--------------------------------------------------------------------------| Run The Application|--------------------------------------------------------------------------|| Once we have the application, we can handle the incoming request| through the kernel, and send the associated response back to| the client's browser allowing them to enjoy the creative| and wonderful application we have prepared for them.|*/$kernel = $app->make(Illuminate/Contracts/Http/Kernel::class);$response = $kernel->handle(    $request = Illuminate/Http/Request::capture());$response->send();$kernel->terminate($request, $response);

第二十一行代碼

1
require __DIR__.'/../bootstrap/autoload.php';

為Laravel應用引入了由Composer提供的類加載器,這樣Laravel應用便無需再手動加載任 何的類。其加載原理不是此次探究的目標,所以僅僅這樣使用就好了。接下的代碼,便是重 點。

 

Illuminate/Foundation/Application 類

該類的繼承結構如下:

類繼承結構

第三十五行代碼

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

它將我的視線引入到了另外一個文件中,去看看到底發生了什么吧。

Laravel源碼解讀-app.php (laravel_app.php)download

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
<?php/*|--------------------------------------------------------------------------| Create The Application|--------------------------------------------------------------------------|| The first thing we will do is create a new Laravel application instance| which serves as the "glue" for all the components of Laravel, and is| the IoC container for the system binding all of the various parts.|*/$app = new Illuminate/Foundation/Application(    realpath(__DIR__.'/../'));/*|--------------------------------------------------------------------------| Bind Important Interfaces|--------------------------------------------------------------------------|| Next, we need to bind some important interfaces into the container so| we will be able to resolve them when needed. The kernels serve the| incoming requests to this application from both the web and CLI.|*/$app->singleton(    Illuminate/Contracts/Http/Kernel::class,    App/Http/Kernel::class);$app->singleton(    Illuminate/Contracts/Console/Kernel::class,    App/Console/Kernel::class);$app->singleton(    Illuminate/Contracts/Debug/ExceptionHandler::class,    App/Exceptions/Handler::class);/*|--------------------------------------------------------------------------| Return The Application|--------------------------------------------------------------------------|| This script returns the application instance. The instance is given to| the calling script so we can separate the building of the instances| from the actual running of the application and sending responses.|*/return $app;

看第十四行,原來$app是一個 Illuminate/Foundation/Application 對象,那么在創 建這個對象的時候又發生了什么呢?

從它的構造方法看起:

Illuminate/Foundation/Application 構造方法

123456789101112131415161718
/** * Create a new Illuminate application instance. * * @param  string|null  $basePath * @return void */public function __construct($basePath = null){    $this->registerBaseBindings();    $this->registerBaseServiceProviders();    $this->registerCoreContainerAliases();    if ($basePath) {        $this->setBasePath($basePath);    }}

順著函數調用,往下看。在這個構造函數中,首先調用了registerBaseBindings方法。

Illuminate/Foundation/Application#registerBaseBindings

12345678910111213
/**  * Register the basic bindings into the container.  *  * @return void  */protected function registerBaseBindings(){    static::setInstance($this);    $this->instance('app', $this);    $this->instance('Illuminate/Container/Container', $this);}

這段代碼,是將實例對象注入到容器中。那么,這個容器是什么呢?答案還是要從這段調用 中去尋找。

static::setInstance($this) 所做的就是將 $this 賦值給自身的 instance 靜態變 量。重點看 $this->instance('app', $this)

instance 函數的作用是綁定一個已有對象到容器中,這個對象在容器中共享并且可以通 過鍵獲取。

Illuminate/Container/Container#instance

1234567891011121314151617181920212223242526272829
/**  * Register an existing instance as shared in the container.  *  * @param  string  $abstract  * @param  mixed   $instance  * @return void  */public function instance($abstract, $instance){    if (is_array($abstract)) {        // $abstract 是這樣的一個數組 ['actual key' => 'alias']        list($abstract, $alias) = $this->extractAlias($abstract);        // 實際上的行為是 $this->aliases[$alias] = $abstract;        $this->alias($abstract, $alias);    }    unset($this->aliases[$abstract]);    // 檢查是否有這個鍵是否已經注冊到容器中    // $bound 是一個boolean值    $bound = $this->bound($abstract);    $this->instances[$abstract] = $instance;    if ($bound) {        $this->rebound($abstract);    }}

視線重新回到Application類中,接下來調用了這個方法 $this->registerBaseServiceProviders(),

Illuminate/Foundation/Application#registerBaseServiceProviders

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
/**  * Register all of the base service providers.  *  * @return void  */protected function registerBaseServiceProviders(){    $this->register(new EventServiceProvider($this));    $this->register(new RoutingServiceProvider($this));}/**  * Register a service provider with the application.  *  * @param  /Illuminate/Support/ServiceProvider|string  $provider  * @param  array  $options  * @param  bool   $force  * @return /Illuminate/Support/ServiceProvider  */public function register($provider, $options = [], $force = false){    if ($registered = $this->getProvider($provider) && !$force) {        return $registered;    }    // If the given "provider" is a string, we will resolve it, passing in the    // application instance automatically for the developer. This is simply    // a more convenient way of specifying your service provider classes.    if (is_string($provider)) {        $provider = $this->resolveProviderClass($provider);    }    $provider->register();    // Once we have registered the service we will iterate through the options    // and set each of them on the application so they will be available on    // the actual loading of the service objects and for developer usage.    foreach ($options as $key => $value) {        $this[$key] = $value;    }    $this->markAsRegistered($provider);    // If the application has already booted, we will call this boot method on    // the provider class so it has an opportunity to do its boot logic and    // will be ready for any usage by the developer's application logics.    if ($this->booted) {        $this->bootProvider($provider);    }    return $provider;}

其中,EventServiceProvider和RoutingServiceProvider分別是

  • Illuminate/Events/EventServiceProvider
  • Illuminate/Routing/RoutingServiceProvider

這些ServiceProvider是 Illuminate/Support/ServiceProvider 的子類,它接受一個 Application 對象作為構造函數參數,存儲在實例變量 $app 中。

 

注入所有基礎 Service Provider

在 register 方法中,每個ServiceProvider被調用了自身的 register 方法。首先看 看 EventServiceProvider 中的吧。

Illuminate/Events/EventServiceProvider#register

12345678
public function register(){    $this->app->singleton('events', function ($app) {        return (new Dispatcher($app))->setQueueResolver(function () use ($app) {            return $app->make('Illuminate/Contracts/Queue/Factory');        });    });}

上面方法體將一個 Illuminate/Events/Dispatcher 對象以鍵 events 綁定到了容器 中,它負責實現事件的調度。

再看看 Illuminate/Routing/RoutingServiceProvider:

Illuminate/Routing/RoutingServiceProvider#register

1234567891011121314
public function register(){    $this->registerRouter();    $this->registerUrlGenerator();    $this->registerRedirector();    $this->registerPsrRequest();    $this->registerPsrResponse();    $this->registerResponseFactory();}

首頁是在Laravel中接觸的最多的 route 被注冊,它是 Illuminate/Routing/Router 對象。

 

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

其他好文

http://www.49028c.com/wish123/p/4756669.html

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
国产亚洲一区精品| 韩国三级电影久久久久久| 亚洲理论在线a中文字幕| 日韩av一区在线观看| 精品久久久久久久中文字幕| 欧美午夜性色大片在线观看| 亚洲一区美女视频在线观看免费| 亚洲色图激情小说| 国产亚洲视频在线观看| 91免费精品国偷自产在线| www.日韩.com| 91美女高潮出水| 成人久久精品视频| 欧美另类老女人| 国产精品27p| 中文字幕日韩欧美精品在线观看| 国产精品女主播视频| 欧美精品久久久久a| 亚洲欧美国产日韩中文字幕| 最新69国产成人精品视频免费| 久久精品影视伊人网| 亚洲精品99久久久久中文字幕| 国产精品久久久久久久久影视| 欧美在线一区二区三区四| 国产精品久久综合av爱欲tv| 4444欧美成人kkkk| 国产亚洲人成网站在线观看| 九九精品视频在线观看| 国产美女搞久久| 97视频免费在线看| 欧美性高潮在线| 亚洲一区二区三区四区在线播放| 日韩在线免费视频| 亚洲淫片在线视频| 68精品国产免费久久久久久婷婷| 国产精品日韩久久久久| 日韩一区二区三区在线播放| 97视频在线免费观看| 成人在线一区二区| 日韩欧美中文第一页| 日韩欧美在线视频免费观看| 91精品在线观看视频| 中文字幕精品www乱入免费视频| 久久久久久噜噜噜久久久精品| 国产成人涩涩涩视频在线观看| 国产一区二区三区三区在线观看| 一本色道久久88亚洲综合88| 在线视频一区二区| 国产极品jizzhd欧美| 日韩在线播放视频| 国产精品国产三级国产专播精品人| 6080yy精品一区二区三区| xx视频.9999.com| 伊人久久男人天堂| 91av福利视频| 88国产精品欧美一区二区三区| 亚洲有声小说3d| 日日摸夜夜添一区| 国产精品美乳在线观看| 日韩在线中文视频| 国产成人av在线播放| www.日韩系列| 国产精品精品视频一区二区三区| 中文字幕少妇一区二区三区| 久久视频免费观看| 日日骚av一区| 在线观看视频亚洲| 久久久这里只有精品视频| 日韩视频免费看| 岛国av午夜精品| 欧美亚洲另类激情另类| 国产91色在线播放| 日韩成人在线电影网| 日韩精品中文字| 亚洲欧美日韩国产成人| 午夜免费日韩视频| 国产日韩欧美在线| 亚洲精品久久久久中文字幕欢迎你| 不卡毛片在线看| 人人澡人人澡人人看欧美| 美女久久久久久久久久久| 91高清视频在线免费观看| 色综合老司机第九色激情| 欧美在线一区二区视频| 丝袜一区二区三区| 亚洲精品综合精品自拍| 欧美巨猛xxxx猛交黑人97人| 欧美极品少妇xxxxⅹ喷水| 一区二区在线免费视频| 欧美激情中文网| 亚洲久久久久久久久久| 日韩女优在线播放| 亚洲精品视频免费| 国产在线精品播放| 欧美性xxxx极品高清hd直播| 亚洲成人黄色在线| 欧美交受高潮1| 欧美老女人性视频| 欧美一级电影免费在线观看| 69精品小视频| 国产精品88a∨| 国产伦精品一区二区三区精品视频| 日韩精品久久久久久久玫瑰园| 亚洲综合色激情五月| 中文字幕亚洲第一| 亚洲天堂av在线免费观看| 欧美与黑人午夜性猛交久久久| 欧美精品在线观看91| 91精品国产高清久久久久久久久| 色悠久久久久综合先锋影音下载| 午夜精品一区二区三区视频免费看| 久久久久久久一区二区三区| 久久视频在线直播| 精品国产一区二区三区久久| 亚洲精品国产精品乱码不99按摩| 国产精品久久久久久久av大片| 日韩欧美精品网站| 欧美日本啪啪无遮挡网站| 91香蕉国产在线观看| 日韩中文综合网| 国产精品久久99久久| 午夜精品久久久久久久久久久久久| 狠狠躁18三区二区一区| 国产精品专区h在线观看| 日韩成人久久久| 国产成人精品一区二区| 清纯唯美亚洲激情| 国产精品高清在线观看| 国产精品高潮在线| 成人av.网址在线网站| 国产精品久久久久久av下载红粉| 中国人与牲禽动交精品| 日韩精品在线视频| 欧美日韩国内自拍| 国产不卡视频在线| 亚洲激情在线观看| 国产日韩在线视频| 国内外成人免费激情在线视频| 热99精品里视频精品| 国产视频精品va久久久久久| 日韩综合中文字幕| 国产成人中文字幕| 久久久久久有精品国产| 亚洲精品不卡在线| 久久人人看视频| 国产精品自产拍在线观看中文| 午夜精品一区二区三区视频免费看| 91精品国产自产在线老师啪| 久久久免费高清电视剧观看| 成人黄色短视频在线观看| 久久久成人精品| 国产日韩中文字幕| 免费av在线一区| 97久久精品人人澡人人爽缅北| 一区二区三区高清国产| 亚洲精品综合精品自拍| 91久久精品国产91久久性色| 国产精品日韩在线| 久久久999成人| 97精品一区二区三区| 日韩小视频网址| 色yeye香蕉凹凸一区二区av| 午夜精品久久久久久99热| 精品视频在线导航|