roolith / config
PHP config class
Installs: 70
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
pkg:composer/roolith/config
Requires (Dev)
- phpunit/phpunit: ^9.2
This package is auto-updated.
Last update: 2025-09-29 02:29:03 UTC
README
PHP config class
Install
composer require roolith/config
Doc
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
config.php
<?php return [ 'database' => 'generalDatabase', 'username' => 'generalUsername', 'password' => 'generalPassword', 'test' => true, ];
production.config.php
<?php return [ 'database' => 'productionDatabase', 'username' => 'productionUsername', 'password' => 'productionPassword', 'a' => [ 'b' => 'c' ] ];
Note: Checkout demo
folder more details.
Usage
<?php use Roolith\Configuration\Config; define('ROOLITH_CONFIG_ROOT', __DIR__. '/config'); print_r(Config::get('database')); // generalDatabase
Once environment variable is set
<?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
More usage
Config::setEnv('production'); Config::get('a.b'); // c Config::get('staging.database', true); // true means it will skip auto set environment