• Facade 请求时,一定要用静态调用,比如:hash::make(password),因为Facade基类实现了__callStatic方法,子类Facade 中必须实现getFacadeAccessor 方法,此方法返回Container中绑定的关键字【其实是解析时用到的key】
  • 基类中返回了Container中key相关的实例,用hash举例,当调用hash::make时,在基类中先返回Container中与hash对应的实例,但此时Container中并没有hash对应的实例,返回实例时调用了resolveFacadeInstance方法,此方法返回return static::resolvedInstance[resolvedInstance[name] = static::app[app[name]这个实例,当调用static::app[app[name]时,因为实例key【hash】并不存在,所以无法获取
  • 但是当调用hash::make(password)是可以对password加密的,原因是在Container中实现了ArrayAccess接口中的offsetGet方法,此方法return this>make(this->make(key),即此时根据key做了一次make【在Application中 的make方法】Deep into Laravel Facade
  • 这里执行了hash对应的service provider注册过程,从而实现的根据key提取实例的最终逻辑

相关文章:

  • 2022-12-23
  • 2021-12-19
  • 2022-01-18
  • 2021-11-25
  • 2021-10-27
  • 2022-12-23
  • 2021-07-17
猜你喜欢
  • 2021-10-12
  • 2022-12-23
  • 2022-12-23
  • 2021-04-19
  • 2021-10-03
  • 2021-12-24
  • 2022-02-03
相关资源
相似解决方案