PHPackages                             phrity/config - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. phrity/config

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

phrity/config
=============

Configuration interface, class, and factories

1.5.2(7mo ago)13.4k↑228.6%MITPHPPHP ^8.1CI passing

Since Apr 4Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/sirn-se/phrity-config)[ Packagist](https://packagist.org/packages/phrity/config)[ Docs](https://phrity.sirn.se/net-uri)[ RSS](/packages/phrity-config/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (9)Dependencies (10)Versions (10)Used By (0)

[![Phrity Config](docs/logotype.png)](docs/logotype.png)

[![Build Status](https://github.com/sirn-se/phrity-config/actions/workflows/acceptance.yml/badge.svg)](https://github.com/sirn-se/phrity-config/actions)[![Coverage Status](https://camo.githubusercontent.com/348ed4be542d42394c179f13844cb197bceb8adc238dee231baf6b44ce01bd6f/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f7369726e2d73652f7068726974792d636f6e6669672f62616467652e7376673f6272616e63683d6d61696e)](https://coveralls.io/github/sirn-se/phrity-config?branch=main)

Introduction
============

[](#introduction)

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

Installation
------------

[](#installation)

Install with [Composer](https://getcomposer.org/);

```
composer require phrity/config

```

The `ConfigurationInterface` interface
--------------------------------------

[](#the-configurationinterface-interface)

The `Phrity\Config\ConfigurationInterface` extends [PSR-11 ContainerInterface](https://www.php-fig.org/psr/psr-11/) and [JsonSerializable](https://www.php.net/manual/en/class.jsonserializable) interfaces.

```
// ContainerInterface implementation
public function get(string $id): mixed;
public function has(string $id): bool;

// JsonSerializable implementation
public function jsonSerialize(): mixed;

// Additional methods
public function __construct(object|array $config);
public function merge(ConfigurationInterface $config): ConfigurationInterface;
```

The `Configuration` class
-------------------------

[](#the-configuration-class)

The `Phrity\Config\Configuration` class implements the `ConfigurationInterface`.

```
use Phrity\Config\Configuration;

// Initiate with object or associative array
$config = new Configuration([
    'a' => 23,
    'b' => [
        'bb' => 66,
    ],
]);

// Check and get (case insensitive) from configuration
$config->has('a'); // => true
$config->get('a'); // => 23

// Trying to get non-exising configuration will throw exception
$config->has('c'); // => false
$config->get('c'); // throws NotFoundException
```

### Accessing by path

[](#accessing-by-path)

```
// It is possible to access by path
$config->has('b/bb'); // => true
$config->get('b/bb'); // => 66
```

### Specifying default

[](#specifying-default)

```
// If default is specified, non-exising configuration will return that value instead of throwing exception
$config->get('a', default: 99); // => 23
$config->get('c', default: 99); // => 99
```

### Type coercion

[](#type-coercion)

```
// Some types can be coerced into another type
$config->get('a', coerce: 'string'); // => "23"
```

See [Transformers](https://github.com/sirn-se/phrity-util-transformer) for coerscion options. Any coercion not specified will cause a `CoercionException`.

### Merging configurations

[](#merging-configurations)

```
// Configurations can be merged (immutable, new instance will be returned)
$additional = new Configuration(['c' => 12, 'b' => ['bc' => 13]]);
$merged = $config->merge($additional);
```

The Reader classes
------------------

[](#the-reader-classes)

A number of configuration readers are available.

- [DataReader](docs/Data.md) - Reader for PHP data input
- [EnvReader and EnvFileReader](docs/Env.md) - Readers for ENV input (file reader requires `symfony/dotenv`)
- [JsonReader and JsonFileReader](docs/Json.md) - Readers for JSON input
- [NeonReader and NeonFileReader](docs/Neon.md) - Reader for NEON input (requires `nette/neon`)
- [YamlReader and YamlFileReader](docs/Yaml.md) - Readers for YAML input (requires `symfony/yaml`)

The `ConfigurationFactory` class
--------------------------------

[](#the-configurationfactory-class)

The `Phrity\Config\ConfigurationFactory` provides shortcuts to create and merge configurations.

```
$factory = new Phrity\Config\ConfigurationFactory();

$configData = $factory->fromData(data: ['a' => 23]);
$configJson = $factory->fromJson(json: '{"a": 23}');
$configJsonFile = $factory->fromJsonFile(path: 'path/to/config.json');
$configYaml = $factory->fromYaml(yaml: 'n: 23');
$configYamlFile = $factory->fromYamlFile(path: 'path/to/config.yaml');
$configNeon = $factory->fromNeon(neon: 'n: 23');
$configNeonFile = $factory->fromNeonFile(path: 'path/to/config.neon');
$configEnv = $factory->fromEnv();
$configEnvFile = $factory->fromEnvFile('.env');

$configMerged = $factory->merge(
    $configData,
    $configJson,
    $configJsonFile,
    $configYaml,
    $configYamlFile,
    $configNeon,
    $configNeonFile,
    $configEnv,
    $configEnvFile,
);
```

Versions
--------

[](#versions)

VersionPHP`1.5``^8.1`Readers (neon, neon-file), improved transformer`1.4``^8.1`Transfomers`1.3``^8.1`Coerce option`1.2``^8.1`Reader (data), all file-readers get `optional` option`1.1``^8.1`Readers (yaml, env-file)`1.0``^8.1`Interface, implementation, readers (json, json-file, yaml-file, env), factory

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance65

Regular maintenance activity

Popularity23

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~76 days

Recently: every ~84 days

Total

9

Last Release

211d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4255391?v=4)[Sören Jensen](/maintainers/sirn-se)[@sirn-se](https://github.com/sirn-se)

---

Top Contributors

[![sirn-se](https://avatars.githubusercontent.com/u/4255391?v=4)](https://github.com/sirn-se "sirn-se (40 commits)")

---

Tags

configurationphpphp-libraryjsonconfigurationconfigyamlneonenv

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phrity-config/health.svg)

```
[![Health](https://phpackages.com/badges/phrity-config/health.svg)](https://phpackages.com/packages/phrity-config)
```

###  Alternatives

[hassankhan/config

Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files

1.0k13.8M187](/packages/hassankhan-config)[symfony/json-streamer

Provides powerful methods to read/write data structures from/into JSON streams.

18641.1k32](/packages/symfony-json-streamer)[thewunder/conphigure

Framework Agnostic Configuration Library

3120.6k](/packages/thewunder-conphigure)[yosymfony/config-loader

Configuration file loader

11111.5k3](/packages/yosymfony-config-loader)[m1/vars

Vars is a simple to use and easily extendable configuration loader with in built loaders for ini, json, PHP, toml, XML and yaml/yml file types. It also comes with in built support for Silex and more frameworks to come soon.

69124.3k1](/packages/m1-vars)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
