<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 架構 —— 門面(Facades) ## 1、簡介 門面為應用的服務容器中的有效類提供了一個“靜態”接口。Laravel附帶了很多門面,你可能在不知道的情況下正在使用它們。Laravel的門面作為服務容器中的底層類的“靜態代理”,相比于傳統靜態方法,在維護時能夠提供更加易于測試、更加靈活的、簡明且富有表現力的語法。 ## 2、使用門面 在Laravel應用的上下文中,門面就是一個提供訪問容器中對象的類。該機制原理由`Facade`類實現,Laravel自帶的門面,以及創建的自定義門面,都會繼承自`Illuminate\Support\Facades\Facade`基類。 門面類只需要實現一個方法:`getFacadeAccessor`。正是`getFacadeAccessor`方法定義了從容器中解析什么,然后`Facade`基類使用魔術方法從你的門面中調用解析對象。 下面的例子中,我們將會調用Laravel的緩存系統,瀏覽代碼后,也許你會覺得我們調用了`Cache`的靜態方法`get`: ~~~ <?php namespace App\Http\Controllers; use Cache; use App\Http\Controllers\Controller; class UserController extends Controller{ /** * 為指定用戶顯示屬性 * * @param int $id * @return Response */ public function showProfile($id) { $user = Cache::get('user:'.$id); return view('profile', ['user' => $user]); } } ~~~ 注意我們在頂部位置引入了Cache門面。該門面作為代理訪問底層`Illuminate\Contracts\Cache\Factory`接口的實現。我們對門面的所有調用都會被傳遞給Laravel緩存服務的底層實例。 如果我們查看`Illuminate\Support\Facades\Cache`類的源碼,將會發現其中并沒有靜態方法`get`: ~~~ class Cache extends Facade{ /** * 獲取組件注冊名稱 * * @return string */ protected static function getFacadeAccessor() { return 'cache'; } } ~~~ `Cache`門面繼承`Facade`基類并定義了`getFacadeAccessor`方法,該方法的工作就是返回服務容器綁定類的別名,當用戶引用`Cache`類的任何靜態方法時,Laravel從服務容器中解析cache綁定,然后在解析出的對象上調用所有請求方法(本例中是get)。 > 擴展閱讀:[實例教程 —— 創建自定義Facades類](http://laravelacademy.org/post/817.html) ## 3、門面類列表 下面列出了每個門面及其對應的底層類,這對深入給定根門面的API[文檔](http://laravelacademy.org/tags/%e6%96%87%e6%a1%a3 "View all posts in 文檔")而言是個很有用的工具。服務容器綁定鍵也被包含進來: | 門面 | 類 | 服務容器綁定別名 | | --- | --- | --- | | App | [Illuminate\Foundation\Application](http://laravel.com/api/5.1/Illuminate/Foundation/Application.html) | `app` | | Artisan | [Illuminate\Console\Application](http://laravel.com/api/5.1/Illuminate/Console/Application.html) | `artisan` | | Auth | [Illuminate\Auth\AuthManager](http://laravel.com/api/5.1/Illuminate/Auth/AuthManager.html) | `auth` | | Auth (Instance) | [Illuminate\Auth\Guard](http://laravel.com/api/5.1/Illuminate/Auth/Guard.html) | | | Blade | [Illuminate\View\Compilers\BladeCompiler](http://laravel.com/api/5.1/Illuminate/View/Compilers/BladeCompiler.html) | `blade.compiler` | | Bus | [Illuminate\Contracts\Bus\Dispatcher](http://laravel.com/api/5.1/Illuminate/Contracts/Bus/Dispatcher.html) | | | Cache | [Illuminate\Cache\Repository](http://laravel.com/api/5.1/Illuminate/Cache/Repository.html) | `cache` | | Config | [Illuminate\Config\Repository](http://laravel.com/api/5.1/Illuminate/Config/Repository.html) | `config` | | Cookie | [Illuminate\Cookie\CookieJar](http://laravel.com/api/5.1/Illuminate/Cookie/CookieJar.html) | `cookie` | | Crypt | [Illuminate\Encryption\Encrypter](http://laravel.com/api/5.1/Illuminate/Encryption/Encrypter.html) | `encrypter` | | DB | [Illuminate\Database\DatabaseManager](http://laravel.com/api/5.1/Illuminate/Database/DatabaseManager.html) | `db` | | DB (Instance) | [Illuminate\Database\Connection](http://laravel.com/api/5.1/Illuminate/Database/Connection.html) | | | Event | [Illuminate\Events\Dispatcher](http://laravel.com/api/5.1/Illuminate/Events/Dispatcher.html) | `events` | | File | [Illuminate\Filesystem\Filesystem](http://laravel.com/api/5.1/Illuminate/Filesystem/Filesystem.html) | `files` | | Hash | [Illuminate\Contracts\Hashing\Hasher](http://laravel.com/api/5.1/Illuminate/Contracts/Hashing/Hasher.html) | `hash` | | Input | [Illuminate\Http\Request](http://laravel.com/api/5.1/Illuminate/Http/Request.html) | `request` | | Lang | [Illuminate\Translation\Translator](http://laravel.com/api/5.1/Illuminate/Translation/Translator.html) | `translator` | | Log | [Illuminate\Log\Writer](http://laravel.com/api/5.1/Illuminate/Log/Writer.html) | `log` | | Mail | [Illuminate\Mail\Mailer](http://laravel.com/api/5.1/Illuminate/Mail/Mailer.html) | `mailer` | | Password | [Illuminate\Auth\Passwords\PasswordBroker](http://laravel.com/api/5.1/Illuminate/Auth/Passwords/PasswordBroker.html) | `auth.password` | | Queue | [Illuminate\Queue\QueueManager](http://laravel.com/api/5.1/Illuminate/Queue/QueueManager.html) | `queue` | | Queue (Instance) | [Illuminate\Queue\QueueInterface](http://laravel.com/api/5.1/Illuminate/Queue/QueueInterface.html) | | | Queue (Base Class) | [Illuminate\Queue\Queue](http://laravel.com/api/5.1/Illuminate/Queue/Queue.html) | | | Redirect | [Illuminate\Routing\Redirector](http://laravel.com/api/5.1/Illuminate/Routing/Redirector.html) | `redirect` | | Redis | [Illuminate\Redis\Database](http://laravel.com/api/5.1/Illuminate/Redis/Database.html) | `redis` | | Request | [Illuminate\Http\Request](http://laravel.com/api/5.1/Illuminate/Http/Request.html) | `request` | | Response | [Illuminate\Contracts\Routing\ResponseFactory](http://laravel.com/api/5.1/Illuminate/Contracts/Routing/ResponseFactory.html) | | | Route | [Illuminate\Routing\Router](http://laravel.com/api/5.1/Illuminate/Routing/Router.html) | `router` | | Schema | [Illuminate\Database\Schema\Blueprint](http://laravel.com/api/5.1/Illuminate/Database/Schema/Blueprint.html) | | | Session | [Illuminate\Session\SessionManager](http://laravel.com/api/5.1/Illuminate/Session/SessionManager.html) | `session` | | Session (Instance) | [Illuminate\Session\Store](http://laravel.com/api/5.1/Illuminate/Session/Store.html) | | | Storage | [Illuminate\Contracts\Filesystem\Factory](http://laravel.com/api/5.1/Illuminate/Contracts/Filesystem/Factory.html) | `filesystem` | | URL | [Illuminate\Routing\UrlGenerator](http://laravel.com/api/5.1/Illuminate/Routing/UrlGenerator.html) | `url` | | Validator | [Illuminate\Validation\Factory](http://laravel.com/api/5.1/Illuminate/Validation/Factory.html) | `validator` | | Validator (Instance) | [Illuminate\Validation\Validator](http://laravel.com/api/5.1/Illuminate/Validation/Validator.html) | | | View | [Illuminate\View\Factory](http://laravel.com/api/5.1/Illuminate/View/Factory.html) | `view` | | View (Instance) | [Illuminate\View\View](http://laravel.com/api/5.1/Illuminate/View/View.html) |
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看