Wednesday, 15 September 2010

php - Laravel 4 class loading and facades -



php - Laravel 4 class loading and facades -

i want know how laravel class loading via facades.

i came across this answer said db alias/facade class loaded code

here /vendor/laravel/framework/src/illuminate/database/connection.php

i tried next advice given in reply , next code index.php not understand how db facade loaded connection class.

i got confused more, because reply had said connection class loaded, class has no connection method. yet documentation says , have been able utilize connection method like,

db::connection('my-connection-name'); here's link docs this

i want know mapped , how loading happen. guessing composer has automated mapping, happening when application boots?

when utilize static db phone call laravel utilize mechanism provided facade class in illuminate\support\facade. magic method __callstatic called , retrieved "original" class provided db facade (here db).

the line 54 in facade.php show utilize $app variable (which static , provided in illuminate\foundation start.php file) object registered db in app container.

return static::$resolvedinstance[$name] = static::$app[$name];

$app['db'] registered in the database service provider.

ah, , able utilize db , not illuminate\support\facades\db because alias created in app config file.

i hope help :)

php laravel laravel-4

No comments:

Post a Comment