Search by

phrity / config

sirn-se

Configuration interface, class, readers, writers, and factory

1.7.0 2026-10-15 11:28 UTC

This package is auto-updated.

Last update: 2026-10-15 11:29:13 UTC


README

Phrity Config

Build Status

Introduction

Tools for handling configuration. Interfaces, implementation classes, various readers, writers and a factory.

Installation

Install with Composer;

composer require phrity/config

Documentation

Configuration

Implements PSR-11 ContainerInterface, providing get() and has() methods.

$config = new Configuration(['opt1' => 11, 'opt2' => 22]);
$config->has('opt1'); // -> true
$config->get('opt1'); // -> 11

Support path access, default value and type coercion.

$config->has('a/b/c');
$config->get('a/b/c', default: 99, coerce: 'string');

Support merging.

$merged = $config->merge(new Configuration($data));

Read more on Configuration.

Writable configuration

Identical to Configuration but also support writing values on the configuration.

$config = new WritableConfiguration(['opt1' => 11, 'opt2' => 22]);
$config->set('opt1', 123);
$config->with('opt1', 123);

Read more on WritableConfiguration.

Reader classes

Classes that create configuration instance from various sources.

$reader = new JsonFileReader();
$config = $reader->createConfiguration(path: 'path/to/file.json');

List of available readers:

Writer classes

Classes that write configuration to file.

$reader = new JsonFileWriter();
$config = $reader->writeConfiguration($config, 'path/to/file.json');

List of available writers:

Factory

A factory that provides shortcuts to create and merge configurations.

$factory = new ConfigurationFactory();
$config = $factory->fromJsonFile(path: 'path/to/config.json');

Read more on ConfigurationFactory.