Config
, (*1)
The Config package helps you manage the configuration of your application., (*2)
, (*3)
Installation
If you are working on an Asgard project you don't need to install this library as it is already part of the standard libraries., (*4)
composer require asgard/config 0.*
, (*5)
Usage in the Asgard Framework
$config = $container['config'];
The container is often accessible as a method parameter or through a ContainerAware object. You can also use the singleton but it is not recommended., (*6)
, (*7)
Usage outside the Asgard Framework
$config = new \Asgard\Config\Config;
, (*8)
Methods
Config inherits \Asgard\Common\Bag to access its data., (*9)
Besides, you can load a configuration with:, (*10)
$config->loadFile('file.yml');
Or a whole directory:, (*11)
$config->loadDir('config/');
This will load files that in the directory., (*12)
Local files, (*13)
If you want to add configuration specific to your local setup, name the file as such:, (*14)
config.local.yml
The file will be loaded after others, and is ignored by default by the Asgard application .gitignore file., (*15)
Environment files, (*16)
If you want to make configuration files specific to environments, name them as such:, (*17)
config_[env].yml
With [env] being the name of the environment., (*18)
Calling:, (*19)
$config->loadDir('config/', 'prod');
Will load default configuration files, plus all *_prod.yml files, while ignoring files like *_dev.yml, (*20)
, (*21)
Configuration file structure
A configuration file, like config.yml contains an array of parameters in YAML format:, (*22)
database:
host: localhost
user: root
password:
database: asgard
Each key can be acessed like:, (*23)
$config->get('database.user');
#or
$config['database.user'];
#or
$config['database']['user'];
, (*24)
Commands
Init
Initialize the configuration files., (*25)
Usage:, (*26)
php console config:init
Contributing
Please submit all issues and pull requests to the asgardphp/asgard repository., (*27)
License
The Asgard framework is open-sourced software licensed under the MIT license, (*28)