laravel Contracts 的理解与分析

这里以```Illuminate\Contracts\Auth\Guard```为例,

contracts作为对象接口,规定实现Guard接口的类必须实现的一些方法。

接下来看```Illuminate\Auth\TokenGuard```类,

在```namespace Illuminate\Auth;```中定义了`GuardHelpers`这个trait,对```Illuminate\Contracts\Auth\Guard```中规定的方法进行实现,同时在接口`Guard`接口的众多实现中继承这个trait,如需对这其中的方法进行自定义,可以对方法进行重写。

这样一来,在```Illuminate\Auth\TokenGuard```等`Guard`的实现类中,只需要写每个模块中特有的方法即可。

---未完待续

猜你喜欢

转载自www.cnblogs.com/yfw07/p/12117353.html