marek-baron / config
Lightweight PHP configuration library.
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/marek-baron/config
Requires
- php: ^8.1
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.5
- squizlabs/php_codesniffer: ^4.0
README
Lightweight, dependency-free PHP configuration library.
Features
- Simple key access using dot notation (db.host)
- Immutable config (with() returns a cloned instance)
- Merge multiple config sources via ConfigAggregator
- Provider support for files, callables, classes, or arrays
- No external dependencies
Installation
composer require marek-baron/config
Config example
$config = new Config([ 'db' => ['host' => 'localhost', 'port' => 3306], 'app' => ['debug' => false], ]); echo $config->get('db.host'); $newConfig = $config->with('app.debug', true); //Immutable! var_dump($config->get('app.debug')); // false var_dump($newConfig->get('app.debug')); // true
ConfigAggregator example
use MarekBaron\Config\ConfigAggregator; $aggregator = new ConfigAggregator([ __DIR__ . '/config/global.php', __DIR__ . '/config/local.php', fn() => ['cache' => ['enabled' => true]], ]); $config = $aggregator->load(); echo $config->get('cache.enabled'); // true
ConfigProviderInterface example
namespace App\Domain\Module; use MarekBaron\Config\ConfigProviderInterface; class ConfigProvider implements ConfigProviderInterface { public function __invoke(): array { return [ 'factories' => [ UserLoginHandler::class => UserLoginHandlerFactory::class, ], 'routes' => [ // your routes ], // anything else ]; } }
Development (optional)
A Dockerfile and docker-compose.yml are included for local development. They are excluded from Packagist via .gitattributes.
docker compose run --rm dev composer check
License
MIT License © Marek Baron