2

So I am examining the code of Laravel

I'm looking at the Storage facade. I think this is the way it's being loaded. Correct me if I am wrong.

  • When ever we access the

    Storage::get('someFile.txt');

  • The Storage is being accessed through the alias in the config am I correct?

    'Storage' => Illuminate\Support\Facades\Storage::class

  • It will then access the this function I believe

protected static function getFacadeAccessor(){

  return 'filesystem';

}
  • And then I think the return filesystem is accessing the filesystem stored on the service container I believe? This is set up in the FilesystemServiceProvider attaching to the container.

protected function registerManager(){

  $this->app->singleton('filesystem', function () {
    return new FilesystemManager($this->app);
  });
}

So overall The Facade is referencing the filesystem on the service container am I correct?

Moppo
  • 18,797
  • 5
  • 65
  • 64
Nello
  • 1,737
  • 3
  • 17
  • 24

1 Answers1

1

Yes, that is true: all the Facades in laravel are a only a convenient way to resolve objects from the Service Container and call methods on them

so, first you register a binding on the Service Container, and once you've done it, instead of doing

$fs = App::make('filesystem');
$file = $fs->get('someFile.txt');

you can simply do:

$file = Storage::get('someFile.txt');
Moppo
  • 18,797
  • 5
  • 65
  • 64