我对 Laravel 提供的 Facades 感到困惑。
Laravel documentation状态:
Facades provide a "static" interface to classes that are available in the application's service container. Laravel ships with many facades which provide access to almost all of Laravel's features. Laravel facades serve as "static proxies" to underlying classes in the service container, providing the benefit of a terse, expressive syntax while maintaining more testability and flexibility than traditional static methods.
请帮助我理解:
use Illuminate\Support\Facades ? 请您参考如下方法:
支持 SitePoint分享有关 Laravel 外观的信息和有用的知识。
门面图案是一种软件设计模式,经常用于面向对象的编程中。
门面是一个包装复杂库的类,为它提供更简单、更易读的接口(interface)。
Laravel 中的外墙
外观为应用程序服务容器中可用的类提供“静态”接口(interface)。 Laravel 附带了许多外观,它们提供了对 Laravel 几乎所有功能的访问。 Laravel 外观充当服务容器中底层类的“静态代理”,提供简洁、富有表现力的语法的好处,同时保持比传统静态方法更多的可测试性和灵 active 。
Laravel 如何实现 Facades
容器内的每个服务都有一个唯一的名称。在 Laravel 应用程序中,要直接从容器访问服务,我们可以使用 App::make()方法或 app() 辅助函数。
<?php
App::make('some_service')->methodName();
在 Laravel 中,所有服务都有一个外观类。这些外观类扩展了基础 Facade 类,它是
Illuminate/Support 的一部分。包裹。他们唯一需要实现的是 getFacadeAccessor 方法,该方法返回容器内的服务名称。




