Working with confguration values¶
Minicli provides a confguration manager through the
Config class. At the same time, the
Config class is a built-in service (by implementing
ServiceInterface) resgistered as a service when the
Appclass is instanciated, allowing it to be used inside each command controller.
Getting Configuration values¶
It is expected for any application to depend on configuration values. They can be provided by static files or even from environment variables. As long as the
App instance is accessible, the entire configuration definition will be available and just like retrieving services from the
App container, the configuration keys will be available via
__get magic method:
In the case of a certain configuration key is not set,
null will be returned instead.
In your controllers, you can access the configuration values via the
Command Controller Example¶
Service class example¶
Check if configuration exists via
As mentioned, if the configuration name does not exists, then null will be returned. When it is required to validate if a configuration key exists, the
has() method is the right one.
Setting configuration values¶
arrayof configuration values can be defined when instanciating the
App class, given that its
__construct will use it to create the
Config service and add it to the app container.
Custom configuration from external sources¶
Another approach is using the magic
__set() method from the
Config class to add configuration values.
Consider the scenario in which configs are available on
environment variables or in a