clagiordano/weblibs-configmanager
A lightweight PHP configuration manager that loads and merges settings from arrays, INI, JSON, YAML and database sources, with dot-notation access, defaults and caching, so applications can keep environment-specific config organized behind one simple, consistent API.
Install via Composer and confirm the autoload namespace matches the source tree before writing any code:
composer require clagiordano/weblibs-configmanager
Then look, in this order:
composer.json — check the autoload PSR-4 prefix and the PHP constraint. This library predates PHP 8.1 and its constraint may block installation on modern stacks.src/ — the package is small (a handful of classes); reading the manager class end to end takes minutes and is faster than guessing the API from the README.tests/ — the tests are the most reliable specification of behaviour for edge cases like missing keys and nested access.README.md — quickstart examples, but verify against src/ since documentation may lag behind the last 2021 release.The first realistic use case is a plain PHP project with a config.php that returns an array:
// config/app.php
return ['db' => ['host' => '127.0.0.1', 'port' => 3306]];
// bootstrap
$config = new ConfigManager();
$config->load(__DIR__ . '/config/app.php');
echo $config->get('db.host'); // confirm dot-notation support in src/
If you need runtime persistence (write a value back to the file), that is the second use case and the reason to choose this over a plain require — treat it as the differentiator and validate it early with a scratch file.
Wrap it, don't scatter it. Bind the manager behind a small interface so the rest of the codebase never sees the package API directly. This is the single most valuable pattern given the package's age and 16-star footprint — it makes replacement trivial.
final class AppConfig
{
public function __construct(private ConfigManager $manager) {}
public function get(string $key, mixed $default = null): mixed
{
return $this->manager->has($key) ? $this->manager->get($key) : $default;
}
}
Laravel integration. Register a singleton in a service provider and publish the config file path from config/:
$this->app->singleton(ConfigManager::class, function () {
$manager = new ConfigManager();
$manager->load(config_path('app.php'));
return $manager;
});
Prefer injecting ConfigManager (or your wrapper) over resolving it from the container inside methods — it keeps tests fast and explicit.
Environment layering. Keep a base config/app.php and overlay per-environment files by loading base first, then the environment file. Whether the manager merges or replaces on repeated load()/set() calls is a behaviour you must confirm in src/; if it replaces, do the merge yourself before handing the array over.
Write path as a controlled operation. When persisting, build the full array, write to a temp file, then rename() — atomic on the same filesystem. Never let the library write directly over a live config if multiple processes read it.
Testing. Point the manager at a fixture directory (or vfsStream for virtual files) and assert both read and round-trip write behaviour. A thin wrapper makes these tests independent of the package's internals.
vlucas/phpdotenv-style config or Laravel's own repository stays cheap.is_writable() before attempting persistence and fail loudly.get('a.b.c'), others require array access get(['a','b','c']), and some treat dots as literal characters in keys. Read the accessor implementation before designing your key convention around it.get() returns null, throws, or triggers a notice for an absent key — this drives whether your wrapper's default-value path is safe.null will produce confusing failures. Keep config files free of <?php trailing output and closing tags.opcache_invalidate($path, true) if you rewrite files in a long-running process (Octane, queue workers).var_export-style array (e.g. objects, closures). Store scalars and arrays only.var_export() the entire loaded array first; it distinguishes "key not loaded" from "key lookup broken" in one step.How can I help you explore Laravel packages today?