PHP config class
composer require roolith/config
Project directory requires a folder (e.g config
) where configuration varibles will be stored.
Default config filename config.php
and environment specific file names are -
development.config.php
production.config.php
<?php
return [
'database' => 'generalDatabase',
'username' => 'generalUsername',
'password' => 'generalPassword',
'test' => true,
];
<?php
return [
'database' => 'productionDatabase',
'username' => 'productionUsername',
'password' => 'productionPassword',
'a' => [
'b' => 'c'
]
];
Note: Checkout demo
folder more details.
<?php
use Roolith\Configuration\Config;
define('ROOLITH_CONFIG_ROOT', __DIR__. '/config');
print_r(Config::get('database')); // generalDatabase
<?php
use Roolith\Configuration\Config;
require_once __DIR__. '/../vendor/autoload.php';
define('ROOLITH_CONFIG_ROOT', __DIR__. '/config');
define('ROOLITH_ENV', 'production'); // set environment varible
// Config::setEnv('development'); // another way to set env
var_dump(Config::get('database')); // result will be `productionDatabase`
var_dump(Config::env()); // production
Config::setEnv('production');
Config::get('a.b'); // c
Config::get('staging.database', true); // true means it will skip auto set environment