Provide a simple interface to handle configuration values.
It's a place to store all configuration files under environments represented by sub directories.
A environment represents a directory into directory root.
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:
# 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:
<?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
- include
<?php
include "vendor/autoload.php";
- Create a instance
<?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);
- Access to configuration values
<?php
// ...
// load files
$config->load('default');
// via method call
echo $config->get('system_timezone') . "<br />";
// via magic method
echo $config->system_timezone . "<br />";
// ...