php - Laravel: how does it register the configuration service?
How does Laravel register the configuration service (the one handling Config facade and config() helper)? I can't find it anywhere in config/app.php @ providers and documentation says nothing about its registration.
Answer
Solution:
- All the config methods(get, set, has..) are located in
Illuminate\Config\Repositoryand this class implementsIlluminate\Contracts\Config\Repositoryinterface. - This class and interface is located in
Illuminate\Foundation\Applicationwhich is the container of application please check registerCoreContainerAliases. - After the registration, the framework needs to initialize/load configurations and
Illuminate\Foundation\Bootstrap\LoadConfigurationis responsible for this. Please checkbootstrapandloadConfigurationFilesmethods - The class responsible for registration is used in
Illuminate\Foundation\Http\Kernel.
This class is used in Illuminate\Foundation\Http\Kernel, here is the list of bootstrappers.
// list of framework related bootstrappers to make application ready when application is up
protected $bootstrappers = [
\Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables::class,
\Illuminate\Foundation\Bootstrap\LoadConfiguration::class,
\Illuminate\Foundation\Bootstrap\HandleExceptions::class,
\Illuminate\Foundation\Bootstrap\RegisterFacades::class,
\Illuminate\Foundation\Bootstrap\RegisterProviders::class,
\Illuminate\Foundation\Bootstrap\BootProviders::class,
];
- The Config facade is just a static proxy between you and container.
- config helper is just using service locator to get
configinstance out of bind services.