marek-baron/config

There is no license information available for the latest version (0.0.1) of this package.

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

0.0.1 2025-10-22 20:15 UTC

This package is auto-updated.

Last update: 2025-10-22 20:36:06 UTC


README

CI

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

PHPUnit Packagist License