lukman-ss/config

Standalone PHP configuration repository, env loader, file loader, and cache utility.

Maintainers

Package info

github.com/lukman-ss/config

pkg:composer/lukman-ss/config

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-06-13 10:13 UTC

This package is auto-updated.

Last update: 2026-06-13 10:27:03 UTC


README

Hero Banner

Standalone PHP configuration library with a repository, typed getters, .env loading, PHP config file loading, cache files, and freeze mode.

Requirements

  • PHP 8.2 or higher
  • No runtime dependencies

Installation

composer require lukman-ss/config

Basic Usage

use Lukman\Config\Config;

$config = new Config();

$config
    ->set('app.name', 'Demo')
    ->set('app.debug', true);

$name = $config->string('app.name');
$debug = $config->bool('app.debug');

Repository

use Lukman\Config\Repository;

$repository = new Repository([
    'database' => [
        'host' => '127.0.0.1',
    ],
]);

$repository->set('database.port', 3306);

$host = $repository->get('database.host');
$port = $repository->int('database.port');
$all = $repository->all();

Env Loader

use Lukman\Config\EnvLoader;

$env = new EnvLoader();
$values = $env->load(__DIR__ . '/.env');

Supported scalar parsing:

  • true and false to boolean
  • null to null
  • integers and floats to numeric values
  • quoted values remain strings
  • empty values remain empty strings

Config File Loader

use Lukman\Config\ConfigLoader;

$loader = new ConfigLoader();
$items = $loader->load(__DIR__ . '/config');

Only non-recursive *.php files are loaded. Each file must return an array. The filename becomes the namespace key.

Example config/app.php:

<?php

declare(strict_types=1);

return [
    'name' => 'Demo',
];

Cache

$config->cacheTo(__DIR__ . '/bootstrap/cache/config.php');
$config->loadCache(__DIR__ . '/bootstrap/cache/config.php');

Cache files are plain PHP files that return an array.

Freeze Mode

$config->freeze();

$config->get('app.name');
$config->frozen();

$config->unfreeze();
$config->set('app.name', 'Updated');

Mutation methods throw Lukman\Config\Exception\ConfigException while frozen.

Testing

composer test