Search by

webware / webware-configmanager

tyrsson

Nested object property based access to configuration data, with pluggable readers, writers and processors.

Package info

github.com/webinertia/webware-configmanager

Homepage

Chat

pkg:composer/webware/webware-configmanager

Statistics

Installs: 2 654

Dependents: 3

Suggesters: 0

Stars: 0

Open Issues: 1

1.0.0-alpha.6 2026-11-22 09:29 UTC

This package is auto-updated.

Last update: 2026-12-05 19:07:50 UTC


README

PHP Version Latest Version License Continuous Integration codecov Mutation testing badge

Nested object property based access to configuration data, with pluggable readers, writers and processors.

This package is the fork of laminas/laminas-config and a drop-in replacement for laminas/laminas-config-aggregator, so one package supplies both the aggregator and the configuration object it produces.

Installation

composer require webware/webware-configmanager

Documentation

The 1.0 release line is documented under docs/1.0:

Usage

use Webware\ConfigManager\Config;
use Webware\ConfigManager\Factory;

$config = new Config([
    'db' => [
        'host' => '127.0.0.1',
        'name' => 'webware',
    ],
]);

echo $config->db->host; // 127.0.0.1

Factory reads and writes .ini, .json, .xml, .yaml/.yml, .properties and .php files, and merges several files into one configuration:

$config = Factory::fromFiles(['config/autoload/global.php', 'config/autoload/local.php'], true);

Readers and writers are resolved through ReaderPluginManager and WriterPluginManager when laminas/laminas-servicemanager is installed, and through the standalone plugin managers otherwise. Both resolve a plugin by fully qualified class name and by file extension; ConfigProvider declares those aliases, and the extension map Factory uses is read from the same declarations.

Replacing laminas-config-aggregator

ConfigAggregator takes the same arguments in the same order and getMergedConfig() returns the same array, so replacing the aggregator is a class name change. ArrayProvider and PhpFileProvider are here too.

use Webware\ConfigManager\ConfigAggregator;
use Webware\ConfigManager\Provider\PhpFileProvider;

$aggregator = new ConfigAggregator(
    [
        \Mezzio\ConfigProvider::class,
        new PhpFileProvider(realpath(__DIR__) . '/autoload/{{,*.}global,{,*.}local}.php'),
    ],
    'data/cache/config-cache.php',
);

return $aggregator->getMergedConfig();

Because ConfigAggregator extends Config, the merged result is the configuration rather than an array that has to be wrapped: get(), array access, iteration and toArray() all work on it. getMergedConfig() remains for the aggregator's own signature. The ENABLE_CACHE and CACHE_FILEMODE constants are redeclared on it, so existing references keep resolving. For the deprecated LaminasConfigProvider, use Factory::fromFiles().

Declaring merge order

A provider can declare its position instead of relying on where it appears in the list, which matters because laminas-component-installer prepends what it writes, so a package installed last lands first and loses every key it shares with a package it builds on.

use Webware\ConfigManager\Attribute\LoadAfter;

#[LoadAfter(OtherProvider::class)]
final class ConfigProvider
{
    /** @return array<array-key, mixed> */
    public function __invoke(): array
    {
        return [];
    }
}

#[LoadBefore] is the counterpart and both accept several targets. A provider that declares nothing keeps the position it was given, a target that is not installed is ignored, and a cycle is reported as an exception naming its participants.

Attribution

This package exists because of the Laminas team's work. What it derives from the two Laminas packages below is credited first, and what it replaces is stated plainly too, because the boundary is not where the names might suggest.

Forked: laminas/laminas-config

Forked from laminas/laminas-config 3.12.x, which the Laminas TSC has archived. What came across is Config, Factory, Reader\*, and the format serializers in Writer\*: their file formats, escaping rules, error messages and edge-case behaviour. The original copyright notice is retained in COPYRIGHT.md and LICENSE.md.

Replaced: the file writing itself

The writers do not fork laminas-config's file handling. Upstream Writer\AbstractWriter::toFile() calls file_put_contents() under LOCK_EX with a set_error_handler() wrapper. This package delegates to webware/webware-filewriter instead, which is this project's own package and contains no Laminas code: it writes an exclusive temporary file beside the destination, carries the mode, owner and group over, and renames it into place, so a reader never sees a partial document. See Atomic writes for why.

Two consequences worth stating plainly, because neither matches laminas-config:

  • WriterInterface::toFile() and AbstractWriter::toFile() throw Webware\FileWriter\Exception types, not Webware\ConfigManager\Exception ones, for a file that cannot be written. They are distinct classes, so a catch written against the Laminas hierarchy does not catch the write failure here.
  • There is no $exclusiveLock parameter. An advisory lock protects nothing when readers take none, and the atomic rename is what makes a partial write unobservable.

Replicated: laminas/laminas-config-aggregator

laminas-config-aggregator is not a dependency of this package. The aggregation behaviour is reimplemented here so that one package can supply both the aggregator and the configuration object, and so that providers can declare their own merge order. The following files reproduce logic from that package, and the shape of the behaviour, the argument order, the merge rules and the failure modes are all theirs:

This package Reimplemented from
src/ConfigAggregator.php Laminas\ConfigAggregator\ConfigAggregator
src/Provider/ConfigProviderResolver.php ConfigAggregator::loadConfigFromProviders(), resolveProvider(), validateNoDuplicateProviders()
src/Provider/ArrayProvider.php Laminas\ConfigAggregator\ArrayProvider
src/Provider/PhpFileProvider.php Laminas\ConfigAggregator\PhpFileProvider
src/Cache/ConfigCache.php ConfigAggregator::cacheConfig(), loadConfigFromCache(), writeCache()
src/Merge/ConfigMerger.php Laminas\Stdlib\ArrayUtils::merge() and ConfigAggregator::mergeArray()
src/Merge/MergeDirective.php Laminas\Stdlib\ArrayUtils\MergeRemoveKey / MergeReplaceKey

laminas/laminas-config-aggregator is installed as a development dependency, so the test suite can assert behavioural parity against it directly rather than against a checked-in expectation. Anything this package adds is additive: the ordering attributes, and ConfigAggregator extending Config so the merged result is the configuration rather than an array that has to be wrapped.

Both upstreams are BSD-3-Clause, copyright the Laminas Project a Series of LF Projects, LLC. See LICENSE.md and COPYRIGHT.md.