4

I've had this problem for a while, and it's really been bugging me, so I figured I'd ask. In Laravel, how are they able to allow access to facades with two namespaces? If you don't understand what I mean, here's an example. Both of the following statements will work when using the session facade:

use Session;
use Illuminate\Support\Facades\Session;

I've searched all over the web and I still have yet to find an answer for this problem.

Thanks for any help!

Dastur
  • 684
  • 6
  • 23
  • 1
    https://www.sitepoint.com/how-laravel-facades-work-and-how-to-use-them-elsewhere/ - facade aliases are in config/app.php, see link for more info on autoloader – apoq Jul 21 '16 at 23:30
  • Thanks that is exactly what I was looking for. – Dastur Jul 22 '16 at 00:04

1 Answers1

3

In the "config\app.php" file there is an aliases array which is used in Illuminate\Foundation\AliasLoader. Then Illuminate\Foundation\AliasLoader calls class_alias method for making an alias in the global namespace. The actual flow is a little bit complicated because of lazy loading.

Serdar Saygılı
  • 461
  • 3
  • 13