所以我正在检查Laravel 的代码
我在看仓库的正面。我想这就是装载的方式。如果我错了,请纠正我。
-
当我们访问时
Storage::get('someFile.txt');
-
正在通过配置中的别名访问存储,我正确吗?
'Storage' => Illuminate'Support'Facades'Storage::class
-
然后它会访问这个功能,我相信
protected static function getFacadeAccessor(){
return 'filesystem';
}
- 然后我认为返回的文件系统正在访问我认为存储在服务容器上的文件系统?这是在附加到容器的FilesystemServiceProvider中设置的
protected function registerManager(){
$this->app->singleton('filesystem', function () {
return new FilesystemManager($this->app);
});
}
总的来说,Facade引用的是服务容器上的文件系统,我说得对吗?
是的,这是真的:laravel中的所有Facades都是从服务容器中解析对象并调用其上的方法的唯一方便方法
因此,首先在服务容器上注册绑定,一旦完成,就不用进行
$fs = App::make('filesystem');
$file = $fs->get('someFile.txt');
你可以简单地做:
$file = Storage::get('someFile.txt');