我有点看看Laravel 4 幕墙下面发生了什么.
我们以此Facade为例:
File::get(someArgs);
Run Code Online (Sandbox Code Playgroud)
如果我没有弄错的话,一步一步(过度简化)的调用将是:
//static method invocation which are all extended from Facade class
File::__callStatic(get, someArgs)
//returns an instance of FileSystem
File::resolveFacedeInstance('files')
FileSystem->get(someArgs)
Run Code Online (Sandbox Code Playgroud)
我感到困惑的是在下面的方法File :: resolveFacadeInstance()的注释行中:
protected static function resolveFacadeInstance($name)
{
if (is_object($name)) return $name;
if (isset(static::$resolvedInstance[$name]))
{
return static::$resolvedInstance[$name];
}
/**
* The line that i'm confused about
*/
return static::$resolvedInstance[$name] = static::$app[$name];
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:
如果File :: get()是被调用的Facade
static :: $ app [$ name]将解析为我认为Application ['files']或Application->文件,它们又调用Application - …
我是Laravel的新手,不理解为什么Laravel有服务提供商。我们为什么使用服务提供商以及何时使用。