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 config property:
Command Controller Example¶
| PHP | |
|---|---|
Service class example¶
| PHP | |
|---|---|
Check if configuration exists via has method¶
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¶
When instantiating App (deprecated - Use method below)¶
An 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.
| PHP | |
|---|---|
Using config files¶
In the root of your project, create a config folder (if you're using any of our official templates this is already done for you).
You can create multiple files to organize your configuration values. For example, you can create a database.php file to store your database connection information.
Each of these files must return an array of configuration values. For example:
| PHP | |
|---|---|
All these configurations will be available via the config property of the App instance or in the config property of your command controllers.