A simple config system
Provide a simple interface to handle configuration values., (*1)
It's a place to store all configuration files under environments represented by sub directories., (*2)
A environment represents a directory into directory root., (*3)
By default the selected environment is ConfigLoader::ENV_PRODUCTION ("production"), to override this, you can put into config root directory a file named ENVIRONMENT.txt that contains a environment name, or, configure $_SERVER['ENVIRONMENT'] var through http server. For example, you can set this var on apache adding the line below:, (*4)
# httpd.conf or .htaccess SetEnv ENVIRONMENT 'development'
A config file is a pure php file that contains an array named $config with the specific scope values. Example:, (*5)
<?php // [config root dir]/[selected environment]/default.php file $config['system_timezone'] = 'Americas/Santo_Domingo';
php composer.phar require "jomisacu/configloader"
Use this package require atleast the below steps, (*6)
<?php include "vendor/autoload.php";
<?php // for specific environment values. // represents a sub directory on config files root directory // it's a string and can exists any number of environments $environment = \Jomisacu\ConfigLoader::ENV_DEVELOPMENT; // directory where resides configuration environments dirs // -+ config (config root) // |-- development // |-- production // |-- testing // |-- qa // |-- example // |-- ... $configFilesRootDir = __DIR__ . '/config'; // configuration files to be loaded automatically $autoloadFiles = ['default']; $config = \Jomisacu\ConfigLoaderFactory::create($configFilesRootDir, $environment, $autoloadFiles);
```php <?php, (*7)
// ..., (*8)
// load files $config->load('default');, (*9)
// via method call
echo $config->get('system_timezone') . "
";, (*10)
// via magic method
echo $config->system_timezone . "
";, (*11)
// ..., (*12)