尝试静态方法如何附加到 Laravel 中的 Auth class?

How do attempt static method get attached to the Auth class in Laravel?

我了解到 Laravel 中有一个 Auth::attempt() 静态方法。

但是当我深入底层源码时,我只能找到SessionGuard.php instead of Auth.php中的方法。

该方法是如何“附加”到 Auth class 的?

这是在默认设置中调用 attempt 的方法,因为 SessionGuard 是 'web' 身份验证守卫正在使用的方法。在 Facade Class Reference 中你会看到 Auth 指的是 AuthManager,你可以查看它的源代码以查看通过魔术方法实际使用的对驱动程序的动态调用。

Auth Facade -> AuthManager -> Driver -> attempt()

Facade 上的神奇 __callStatic 方法:https://github.com/laravel/framework/blob/8.x/src/Illuminate/Support/Facades/Facade.php#L253

AuthManager 上的神奇 __call 方法:https://github.com/laravel/framework/blob/8.x/src/Illuminate/Auth/AuthManager.php#L305