ctorh23/configmanager

Configuration management library for PHP applications.

Maintainers

Package info

github.com/ctorh23/configmanager

pkg:composer/ctorh23/configmanager

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.1.0 2026-03-24 11:48 UTC

This package is auto-updated.

Last update: 2026-04-24 12:06:07 UTC


README

ConfigManager is a lightweight library for managing PHP configuration files with support for Dot-Notation, Lazy Loading and Caching.

Installation

The package requires PHP 8.3 or newer.

composer require ctorh23/configmanager

Usage

Configuration File Structure

Create a PHP file, for example app.php, that looks like this:

return [
	'name' => 'My App',
	'env' => $this->env('APP_ENV', 'production'),
	'encryption' => [
		'cipher' => 'AES-256-GCM',
		'key' => $this->env('APP_KEY'),
	],
];

The file must return an array. As you can see, you can use environment variables as configuration settings. The second parameter of the env() method is a default value.

Accessing Configuration Values

Assuming your configuration files are saved in a config/ directory, you must pass the path to this directory to instantiate a ConfigManager object:

use Ctorh23\ConfigManager\ConfigManager;

$confMan = new ConfigManager(__DIR__ . '/config');

echo $confMan->get('app.name'); //Output: My App
echo $confMan->get('app.env'); //Output: production
echo $confMan->get('app.encryption.cipher'); //Output: AES-256-GCM

// Passing a default value as a second parameter
echo $confMan->get('app.logs', 'logs/'); //Output: logs/

You can also dynamically set configuration settings, but you should keep in mind that they are not persisted on the filesystem:

$confMan->set('timezone', 'UTC');
$confMan->set('app.encryption.cipher', 'AES-XTS');

echo $confMan->get('timezone'); //Output: UTC
echo $confMan->get('app.encryption.cipher'); //Output: AES-XTS

Caching

A configuration file is loaded once per request. When you have multiple configuration files, this can cause unnecessary filesystem access. In production, it is recommended to cache the configuration settings. A cache directory must be passed as the second argument to the ConfigManager constructor:

$confMan = new ConfigManager(__DIR__ . '/config', __DIR__ . '/cache');
$confMan->warmUpCache();

With caching enabled, the cached configuration file is loaded only once when a ConfigManager object is instantiated. If you change a setting or add a new configuration file, those changes will not be available until the cache file is deleted.

Call the warmUpCache() method as part of your deployment process. You do not need to manually delete an old cache file beforehand - it will be overwritten.