Search by

echo-fusion / configmanager

amir-shadanfar

Immutable, deeply merged application configuration with dot-notation access for the EchoFusion framework.

Package info

github.com/echo-fusion/configmanager

pkg:composer/echo-fusion/configmanager

Statistics

Installs: 275

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.1 2026-10-12 12:20 UTC

This package is auto-updated.

Last update: 2026-10-12 12:20:43 UTC


README

CI Packagist PHP License

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.