PHPackages                             time2split/time2configure - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. time2split/time2configure

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

time2split/time2configure
=========================

Tree shaped configuration with text interpolation

v0.1.3(2mo ago)064MITPHPPHP &gt;=8.2CI passing

Since Dec 19Pushed 2mo agoCompare

[ Source](https://github.com/time2split/php-time2configure)[ Packagist](https://packagist.org/packages/time2split/time2configure)[ RSS](/packages/time2split-time2configure/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (4)Versions (5)Used By (0)

Time2Configure
==============

[](#time2configure)

[![License: MIT](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](https://opensource.org/licenses/MIT)[![Latest Stable Version](https://camo.githubusercontent.com/7a3a6544ab8af35a00fce8e5bf2d738a33a687b05f745becc7040643ccdc8eb4/68747470733a2f2f706f7365722e707567782e6f72672f74696d653273706c69742f74696d653268656c702f76)](https://packagist.org/packages/time2split/time2configure)[![Latest Unstable Version](https://camo.githubusercontent.com/bae17d79a48d3389e721584529b3dac0d517dfc5fb0f2796cb62c5ca18b5cab4/68747470733a2f2f706f7365722e707567782e6f72672f74696d653273706c69742f74696d653268656c702f762f756e737461626c65)](https://packagist.org/packages/time2split/time2configure)

Time2Configure is a php library implementing the concept of tree configuration with value interpolations.

Configuring a program consists to get some entries from the external world, for instance by entering some command line arguments, and then to use theses entries inside the program. Most of the time, the program does the reading of a formatted configuration (`json`, `ini`, etc) with some specialized format reader and then uses directly the obtained result as the program configuration. Usefull formats for configuration storage may be `json`, `php` array, or other tree shapped formats. Even a flat format like `ini` or `csv` can allows the usage of a hierarchical notation (eg. `parent.child`) that finally defines a tree-shapped configuration. Tree is a natural way to represent a configuration.

Time2Configure proposes a general abstraction of [tree configuration](https://time2split.net/php-time2configure/classes/Time2Split-Config-Configuration.html), not focused on any format but rather on storage and features. Moreover, these tree configurations have the very usefull ability to use complex value interpolation languages.

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

[](#installation)

The library is distributed as a Composer project.

```
$ composer require time2split/time2configure
```

Documentation
-------------

[](#documentation)

- [API documentation](https://time2split.net/php-time2configure)

Some examples
-------------

[](#some-examples)

To have a very first taste of the library in action let's give a first example:

```
use Time2Split\Config\Configurations;

// Some configuration possibly loaded from an external file
$loadedConfig = [
    'text' => [
        'locale' => 'en_US',
        'encoding' => 'UTF-8'
    ],
    'database' => [
        'driver' => 'mysql',
        'port' => 3306,
        'database' => 'db',
        'username' => 'zuri',
        'password' => 'xxx',
    ],
];
$config = Configurations::ofTree($loadedConfig);

echo $config['text.locale'], "\n";
echo $config['database.driver'], "\n";
```

```
### Output ###
en_US
mysql
```

Because the configuration is a tree we are able reduce the visibility of some part of a program to a specific sub-tree.

```
$view = $config->subTreeView('database');
print_r($view->toArray());
```

```
### Output ###
Array
(
    [driver] => mysql
    [port] => 3306
    [database] => db
    [username] => zuri
    [password] => xxx
)
```

The library consider that each node of the tree can store a value, not only leaves.

```
$config['database.driver'] = 'sqlite';
$config['database'] = 'an internal value';
print_r($config->toArray());
```

```
### Output ###
Array(
    [text.locale] => en_US
    [text.encoding] => UTF-8
    [database] => an internal value
    [database.driver] => sqlite
    [database.port] => 3306
    [database.database] => db
    [database.username] => zuri
    [database.password] => xxx
)
```

Value interpolation
-------------------

[](#value-interpolation)

The second main feature, over the tree aspect is the value interpolation.

Value interpolation permits to compile automatically an entries's value to generate dynamically another value when the entry is accessed. Here is an example using the previous example's $config:

```
// Get a new configuration instance with an interpolator
$iconfig = Configurations::treeCopyOf($config, Interpolators::recursive());

$iconfig['interpolated'] = '${text.locale} and ${text.encoding}';
echo $iconfig['interpolated'], "\n";

$iconfig['text.locale'] = 'UTF-16';
echo $iconfig['interpolated'], "\n";
```

```
### Output ###
en_US and UTF-8
UTF-16 and UTF-8
```

In this example we used the provided interpolator [Interpolators::recursive()](https://time2split.net/php-time2configure/classes/Time2Split-Config-Interpolators.html)which substitute every ${key} token encountered in a text value by the actual $config\['key'\] value stored. (For now, this is the only interpolator provided by the library.)

More complex interpolated language can be made. For instance, the [pcp](https://github.com/time2split/pcp)project defines a more complex language with the help of the great [parsica-php/parsica](https://github.com/parsica-php/parsica) project. The pcp interpolated languagepermits to use operators based expressions (assignments, boolean) and is even able to parse command line arguments.

The interpolation principe is simple, but let the ability to create very complex languages.

Features
--------

[](#features)

- [Tree shapped configurations](https://time2split.net/php-time2configure/packages/time2configure-configuration.html)
- [Fluent tree builder](https://time2split.net/php-time2configure/classes/Time2Split-Config-TreeConfigurationBuilder.html)
- [Interpolated values](https://time2split.net/php-time2configure/packages/time2configure-interpolation.html)
- [Hierarchical configurations](https://time2split.net/php-time2configure/classes/Time2Split-Config-Configurations.html#method_hierarchy)
- [Operations and decorators to add more complex behaviours](https://time2split.net/php-time2configure/classes/Time2Split-Config-Configurations.html)

### Hierarchy of configurations

[](#hierarchy-of-configurations)

In many scenarios there is a default base configuration that the user can modify to create the final one. Time2Configure provides a solution to create a list of configurations where only the last one can be effectively modified.

```
$default = [
   'text' => [
       'locale' => 'en_US',
       'encoding' => 'UTF-8'
   ]
];
$default = Configurations::ofTree($default);
/*
   $default is the config to search for
   the unexistant entries of $config.
*/
$config = Configurations::emptyChild($default);

echo $config['text.locale'], "\n";

$config['text.locale'] = 'override';
echo $config['text.locale'], "\n";

$config['text.locale'] = null;
echo $config['text.locale'], "\n";

unset($config['text.locale']);
echo $config['text.locale'], "\n";
```

```
### Output ###
en_US
override

en_US
```

More generally, this is a very usefull feature that permits to a process to immunize its configuration against modification by a sub-process without the need of copying.

### Decorators

[](#decorators)

Decorators are usefull to add more behaviour to a configuration. Fo instance, the decorator [Configurations::doOnRead()](https://time2split.net/php-time2configure/classes/Time2Split-Config-Configurations.html#method_doOnRead)is able to do an action when a value is accessed.

```
$tree = [
   'text' => [
       'locale' => 'en_US',
       'encoding' => 'UTF-8'
   ]
];
$config = Configurations::ofTree($tree);
$doEcho = Entries::consumeEntry(function ($key, $val) {
   echo "$key=$val\n";
});
$echoConfig = Configurations::doOnRead($config, $doEcho);

$echoConfig['text.locale'];
iterator_to_array($echoConfig);
```

```
### Output ###
text.locale=en_US
text.locale=en_US
text.encoding=UTF-8
```

There is also some mapping decorators that can uses the original entry values to makes new one. Here is a new examples:

```
$config = Configurations::ofTree();
$config['url.php'] = 'https://www.php.net/support';

// Dereference an url and retrieves the header
$getHeader = Entries::mapValue(function ($value, $key) {

   if (\str_starts_with($key, 'url'))
       return \get_headers($value, true);

   return $value;
});
$deref = Configurations::mapOnRead($config, $getHeader);

print_r($deref['url.php']);
```

```
### Output ###
Array
(
   [0] => HTTP/1.1 200 OK
   [Server] => myracloud
   [Date] => Mon, 08 Apr 2024 20:00:43 GMT
   [Content-Type] => text/html; charset=utf-8
   [Transfer-Encoding] => chunked
   [Connection] => close
   [Content-language] => en
   [Permissions-Policy] => interest-cohort=()
   [X-Frame-Options] => SAMEORIGIN
   [Link] => ; rel=shorturl
   [Expires] => Mon, 08 Apr 2024 20:00:43 GMT
   [Cache-Control] => max-age=0
   [ETag] => "myra-3087d513"
)
```

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance83

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity44

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 ~143 days

Total

4

Last Release

84d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b7b266ae57fafb9b9e19f58ca7bccef0bf210a253c345946140e4c6a834b75e0?d=identicon)[zuri-TTS](/maintainers/zuri-TTS)

---

Top Contributors

[![zuri-TTS](https://avatars.githubusercontent.com/u/32542593?v=4)](https://github.com/zuri-TTS "zuri-TTS (60 commits)")

---

Tags

configurationtreeinterpolation

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/time2split-time2configure/health.svg)

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

###  Alternatives

[symfony/options-resolver

Provides an improved replacement for the array\_replace PHP function

3.2k493.9M1.6k](/packages/symfony-options-resolver)[knplabs/knp-menu

An object oriented menu library

1.4k55.8M287](/packages/knplabs-knp-menu)[league/config

Define configuration arrays with strict schemas and access values with dot notation

564302.2M24](/packages/league-config)[cuyz/valinor

Dependency free PHP library that helps to map any input into a strongly-typed structure.

1.5k9.2M108](/packages/cuyz-valinor)[josegonzalez/dotenv

dotenv file parsing for PHP

2799.8M137](/packages/josegonzalez-dotenv)[symfony/requirements-checker

Check Symfony requirements and give recommendations

2014.7M29](/packages/symfony-requirements-checker)

PHPackages © 2026

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