学习ing2017-07-05 10:04:01
归根结底是通过 魔术方法 __callStatic
实现的
IlluminateSupportFacadesFacade
代码最下方
https://github.com/illuminate...
/**
* Handle dynamic, static calls to the object.
*
* @param string $method
* @param array $args
* @return mixed
*
* @throws \RuntimeException
*/
public static function __callStatic($method, $args)
{
$instance = static::getFacadeRoot();
if (! $instance) {
throw new RuntimeException('A facade root has not been set.');
}
return $instance->$method(...$args);
}
关于 Facade
是 Lavavel
比较重要的特性之一,可以详细了解下它的实现。