echo-fusion / configmanager
Immutable, deeply merged application configuration with dot-notation access for the EchoFusion framework.
Requires
- php: ~8.1.0 || ~8.2.0 || ~8.3.0
- echo-fusion/contracts: ^1.3 || ^2.0
Requires (Dev)
- echo-fusion/codestandard: ^1.0
- friendsofphp/php-cs-fixer: ^3.64
- phpunit/phpunit: ^9.5
- vimeo/psalm: ^5.26
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-12 12:20:43 UTC
README
ConfigManager is a small, immutable configuration container for PHP applications. It merges any number of config arrays (or PHP config files) and gives you dot-notation access to the result.
It implements EchoFusion\Contracts\ConfigManager\ConfigInterface from echo-fusion/contracts, so other packages can depend on the interface only.
Part of EchoFusion, a modular PHP framework built from small packages.
Installation
composer require echo-fusion/configmanager
Requirements
- PHP 8.1, 8.2 or 8.3
Usage
Merging arrays
Later arrays override earlier ones. Associative arrays are merged recursively; lists are replaced as a whole.
use EchoFusion\ConfigManager\Config; $config = new Config( ['database' => ['host' => 'localhost', 'port' => 3306], 'plugins' => ['a', 'b']], ['database' => ['host' => 'db'], 'plugins' => ['c']], ); $config->get('database.host'); // 'db' $config->get('database.port'); // 3306 $config->get('plugins'); // ['c'] $config->get('database.user', 'root'); // 'root' (default for a missing key) $config->has('database.port'); // true $config->all(); // the full merged array
has() is true for keys whose value is null; get() only returns the default when the key does not exist.
Loading PHP files
Each file must return an array. A missing file, or a file that returns something else, throws EchoFusion\ConfigManager\Exceptions\ConfigException.
$config = Config::fromFiles( __DIR__ . '/config/global.config.php', __DIR__ . '/config/environments/production.config.php', );
Immutability
The object never changes after construction. with() returns a new instance:
$debug = $config->with(['app' => ['debug' => true]]);
Depending on the interface
use EchoFusion\Contracts\ConfigManager\ConfigInterface; final class Mailer { public function __construct(private ConfigInterface $config) {} }
Testing
composer test
Credits
License
The MIT License (MIT). Please see LICENSE for more information.