- 首先Cache类继承于Facade类
- Cache类中实现
getFacadeAccessor
这个静态方法,并返回服务容器中已经注册好的实例名(这里实例名就是和laravel的服务容器绑定了的$abstract)
class Cache extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'cache';
}
}
- 当外界调用
Cache::get('test')
的时候,就会触发Facade类的魔术方法__callStatic
(因为Facade类中,不存在get方法) - 在魔术方法中,实例化之前绑定的‘cache’类后调用其‘get’方法
public static function __callStatic($method, $args)
{
$instance = static::