laravel門面契約(facades)與契約(contracts)

下面由laravel框架教程欄目給大家介紹laravel門面契約(facades)與契約(contracts),希望對需要的朋友有所幫助!

1. 如何定義 Laravel 的門面?

所有的門面都定義在 IlluminateSupportFacades 命名空間當中。

2. 契約(facades)的理解

facades 是什么?

Facades(讀音:/f??s?d/ )為應用程序的 服務容器 中可用的類提供了一個「靜態」接口。你不必 use 一大串的命名空間,也不用實例化對象,就能訪問對象的具體方法。

facades 如何 注冊使用?

同樣 facades 需要 注冊與 啟動的。

laravel 很喜歡,注冊(register) 啟動(bootstrap)

Facade 的啟動引導是在 IlluminateFoundationBootstrapRegisterFacades 中注冊的。

    /**      * Prepend the load method to the auto-loader stack.      *      * @return void      */     protected function register()     {         if (! $this->registered) {             spl_autoload_register([$this, 'load'], true, true);              $this->registered = true;         }     }

具體實現邏輯 大家可以 查看原文:Laravel Facade 的加載過程及原理

3. 解釋 Laravel 中契約的概念

它們是 Laravel 框架的接口集合。 這些契約提供核心服務。 Laravel 中的契約包括相應的框架實現。

思考

  1. facades Contracts怎么讀的?
  2. facades 是如何注冊與加載的?
  3. facades 方便了我們什么操作?

以上就是

? 版權聲明
THE END
喜歡就支持一下吧
點贊11 分享