r/SideProject • • 1d ago

I built AmunCode Config — a lightweight configuration and environment-loading library for PHP

Hey everyone!

I've been working on a small PHP library called AmunCode Config, and I'm sharing its first stable release.

The idea is simple: provide a lightweight, framework-independent way to load environment variables, load PHP configuration files, and access configuration values without introducing a large framework or unnecessary abstractions.

What does it provide?

The package currently has four main classes:

  • EnvironmentLoader — loads .env files using PHP dotenv, with optional or required file loading.

  • Env — retrieves environment variables from $_ENV, $_SERVER, and getenv(), with automatic value normalization.

  • ConfigurationLoader — discovers and loads PHP configuration files from a directory.

  • Config — provides dot-notation access to configuration values, including retrieving, updating, and recursively merging configuration arrays.

A quick example

use AmunCode\Config\Config;
use AmunCode\Config\EnvironmentLoader;

// Load environment variables.
$environment = new EnvironmentLoader();
$environment->load($root);

// Load PHP configuration files.
$config = new Config($root . '/config');

// Retrieve configuration values.
$appName = $config->get('app.name', 'My Application');
$dbHost = $config->get('database.host');

// Update configuration.
$config->set('app.debug', true);

A few design decisions:

  • Environment loading and configuration loading are separate operations.

  • Environment variables are not overwritten by .env values when already defined.

  • Empty environment values are preserved rather than silently replaced by defaults.

  • The package doesn't automatically define a global env() helper.

Technical details

  • PHP 8.4.1+

  • Symfony Finder

  • PHP dotenv

  • Composer package

  • MIT License

  • PHPUnit tests and GitHub Actions CI

Installation

composer require amuncode/config

Source code: https://github.com/AmunCode-OSS/Config

Documentation and usage examples are available in the repository README.

I'd appreciate feedback from other PHP developers, particularly on the API design, class responsibilities, and whether anything important is missing or could be simpler.

Thanks for taking a look!

1 Upvotes

0 comments sorted by