您的位置 首页 php

laravel门面契约(facades)与契约(contracts)

下面由Laravel框架教程栏目给大家介绍laravel门面契约(facades)与契约(contracts),希望对需要的朋友有所帮助!

1. 如何定义 Laravel 的门面?

所有的门面都定义在 Illuminate\Support\Facades 命名空间当中。

2. 契约(facades)的理解

facades 是什么?

Facades(读音:/fəˈsäd/ )为应用程序的 服务容器 中可用的类提供了一个「静态」接口。你不必 use 一大串的命名空间,也不用实例化对象,就能访问对象的具体方法。

facades 如何 注册使用?

同样 facades 需要 注册与 启动的。

laravel 很喜欢,注册(register) 启动(bootstrap)

Facade 的启动引导是在 Illuminate\Foundation\Bootstrap\RegisterFacades 中注册的。

    /**     * 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 方便了我们什么操作?

文章来源:智云一二三科技

文章标题:laravel门面契约(facades)与契约(contracts)

文章地址:https://www.zhihuclub.com/25869.shtml

关于作者: 智云科技

热门文章

网站地图