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\Repository and this class implements Illuminate\Contracts\Config\Repository interface.
  • This class and interface is located in Illuminate\Foundation\Application which is the container of application please check registerCoreContainerAliases.
  • After the registration, the framework needs to initialize/load configurations and Illuminate\Foundation\Bootstrap\LoadConfiguration is responsible for this. Please check bootstrap and loadConfigurationFiles methods
  • 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 config instance out of bind services.

Source