Laravel中使用了什么Facades? [英] What is Facades used in Laravel?

查看:108
本文介绍了Laravel中使用了什么Facades?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Laravel提供的立面感到困惑.

I'm confused by the Facades offered by Laravel.

Laravel文档指出:

外观为应用程序的服务容器中可用的类提供了静态"接口. Laravel附带了许多外墙,可以访问Laravel的几乎所有功能. Laravel外观作为服务容器中基础类的静态代理",提供了简洁,表达性强的语法的优点,同时保持了比传统静态方法更高的可测试性和灵活性.

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.

请帮助我了解

  1. 为什么我们真的使用use Illuminate\Support\Facades?
  2. 如何创建自定义外观?

推荐答案

感谢

Thanks sitepoint for sharing such informative and helpful knowledge about FACADE (FACADE in Laravel)

FACADE :- The Facade pattern is a software design pattern which is often used in object oriented programming. A facade is, in fact, a class wrapping a complex library to provide a simpler and more readable interface to it.

Laravel中的外观:-外观为应用程序的服务容器中可用的类提供了静态"接口. Laravel附带了许多外墙,可以访问Laravel的几乎所有功能. Laravel外观作为服务容器中基础类的静态代理",提供了简洁,表达性强的语法的优点,同时保持了比传统静态方法更高的可测试性和灵活性.

Facades in Laravel :- 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.

如何在Laravel中实现外观

您可能知道,容器内的每个服务都有一个唯一的名称.在Laravel应用程序中,要直接从容器访问服务,我们可以使用App::make()方法或app()帮助函数.

As you probably know, every service inside the container has a unique name. In a Laravel application, to access a service directly from the container, we can use the App::make() method or the app() helper function.

<?php

App::make('some_service')->methodName();

在Laravel中,所有服务都有一个Facade类.这些Facade类扩展了基础Facade类,该基础Facade类是Illuminate/Support包的一部分.他们唯一需要实现的就是getFacadeAccessor方法,该方法返回容器内的服务名称.

In Laravel, all services have a facade class. These facade classes extend the base Facade class which is part of the Illuminate/Support package. The only thing that they need to implement is the getFacadeAccessor method, which returns the service name inside the container.

这篇关于Laravel中使用了什么Facades?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆