该外墙如何工作
我正在与Laravel 5.8合作,这是其他程序员编写的在线商店项目。
基本上,我面临着从未见过的怪异的东西。
假设我们在控制器方法中有这个:
$payment = CourseRegistrationFacade::insertCourseRegisterInformation($courseId,$date,$memberId,$userId);
然后我们得到了 courseregistrationfacade
,它是这样的:
class CourseRegistrationFacade extends BaseFacade
{
}
所以整个班级都是空的,但它扩展了另一个<代码> BaseFacade ,它是这样的:
class BaseFacade extends Facade
{
protected static function getFacadeAccessor()
{
return static::class;
}
protected static function shouldProxyTo($class)
{
app()->bind(self::getFacadeAccessor(), $class)
}
}
就是这样!
我真的不知道治愈在哪里 insertCoursereGisterInformation
!
因此,如果您知道该立面是如何工作的,请让我知道...
这是 basefacade.php
的完整代码:
namespace App\Facades;
use Illuminate\Support\Facades\Facade;
class BaseFacade extends Facade
{
protected static function getFacadeAccessor()
{
return static::class;
}
public static function shouldProxyTo($class)
{
app()->bind(self::getFacadeAccessor(), $class);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在代码中搜索:
最有可能在服务提供商中搜索该行在某个地方注册该类别的柜台的某个地方。然后检查类的内容(参数传递给了应该二氧基)。
在该类中,应该有一种称为InsertCourSereGisterInformation的方法。
立面的工作方式是他们从容器中解析了班级,然后呼叫您静态调用的方法。
因此,例如,假设您有一个带有方法寄存器()的userService.php,并且该类映射到userervicefacade.php。当您执行UserviceFacade :: register()时,__ callstatic将从容器中获取立面登录器(实际类),然后调用该类的寄存器()方法。
您可以通过检查__ callstatatic Inside.php来更好地理解。
从本质上讲,UserserviceFacade :: register()与做法相同:
通过使用外墙,您可以隐藏具体的实现,并可能通过单个位置更改将来将其切换到其他东西。
Search in the code for:
Most likely in the service provider that line is somewhere registering that facade to some concrete implementation of a class. Then check the contents of the class (the argument passed to shouldProxyTo).
Inside that class there should be a method called insertCourseRegisterInformation.
The way facades work is they resolve the class out of the container and then call the method you call statically.
So for example, let's say you have a UserService.php with a method register() and that class is mapped to a UserServiceFacade.php. When you do UserServiceFacade::register(), __callStatic will get the facade accessor (actual class) from the container, then call the register() method of that class.
You can understand better by inspecting __callStatic inside Facade.php.
Essentially UserServiceFacade::register() is the same as doing:
By using the facade you can hide the concrete implementation and could possibly switch it to something else in the future by just changing it in a single place.
我认为必须有一个
提供商
,该facade
必须初始化其关联类,intertCourSereGisterInformation
方法>必须在其中声明。请找到该提供商,然后您会从该提供商
代码找到其关联的类
。我认为您可以从config/app.php
找到所有注册的提供商,这些参考文章可能会对您有所帮助。
参考文献1:
参考2: http://www.expertphp.in/article/how-to-to-to-to-create-custom-custom-facade-in-laravel-in-laravel-52
I think there must be a
Provider
exists for thatFacade
which is initializing its associated class andinsertCourseRegisterInformation
method definition must be declared in it. Please find that provider and then you'll find itsassociated class
from thatProvider
code. I think you can find all registered providers fromconfig/app.php
These reference articles might help you.
Reference 1:
https://grafxflow.co.uk/blog/mvc/adding-global-custom-class-facades-laravel-5
Reference 2: http://www.expertphp.in/article/how-to-create-custom-facade-in-laravel-52