PHPackages                             kairos-project/configuration - 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. kairos-project/configuration

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

kairos-project/configuration
============================

A processor system for configuration structure

07PHP

Since May 20Pushed 7y ago1 watchersCompare

[ Source](https://github.com/kairosProject/configuration)[ Packagist](https://packagist.org/packages/kairos-project/configuration)[ RSS](/packages/kairos-project-configuration/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

configuration
=============

[](#configuration)

A processor for configuration structure

Key concept
-----------

[](#key-concept)

The key concept of the configuration is to append elements inside another, following composite structure pattern.

Each configuration element will specify a list of allowed type inside.

```
$config = new Configuration();
$config->setAllowedTypes(['string']);

echo $config->process('There is a string'); // will return the acceptable input 'There is a string'

$config->process(12); // will throw an exception
```

As composite nested elements, it's possible to add childs to an array node.

```
$config = new Configuration();
$config->addAllowedType('array');

$config->addChild('balance', new Configuration());
$config->getChild('balance')->addAllowedType('int');

$config->process(['balance' => 12]);
```

### Validation

[](#validation)

It's possible to add a list of validation for each elements. This validation can execute more than one action :

- Change the element value
- Remove the element from parent

By this way, the validation MUST return the element value.

The validation can be a callback or a n instance of object implementing the `Kairos\Config\Validation\ValidationInterface`.

```
$config = new Configuration();

$config->addValidation(function($element){
	return is_array($element) ? $element : [$element];
});
```

With object :

```
class EmbedAsArray implements ValidationInterface
{
    /**
     * Validate
     *
     * Validate the element
     *
     * @param mixed $element The element to validate
     *
     * @return mixed
     */
    public function validate($element)
    {
    	return is_array($element) ? $element : [$element];
    }
}
```

### Require element and default

[](#require-element-and-default)

The element can be set as required element to ensure the presence in the result. By default, the element can be skipped and will not be present in the result.

```
$config = new Configuration();
$config->setRequired(true);
```

It's also possible to define a default value.

```
$config = new Configuration();
$config->setDefaultValue('default_value');
$config->setDefaultValue(null);
```

### Post process validation

[](#post-process-validation)

To interact with the complete result of the process, the element can define a post validation. This validation must be an object implementing the PostValidationInterface.

```
class ConflictWithAlt implements PostValidationInterface
{
	private $originalNode;

    /**
     * Validate
     *
     * Validate the element
     *
     * @param mixed $element The element to validate
     *
     * @return mixed
     */
    public function validate($element)
    {
    	if (isset($element['alt'])) {
    		throw new LogicException('Something as a conflict with "alt" element');
    	}
    	return $element;
    }

    /**
     * Set original node
     *
     * Set up the original validation node
     *
     * @param Configuration $node The original node
     *
     * @return $this
     */
    public function setOriginalNode(Configuration $node) : PostValidationInterface
    {
    	$this->originalNode = $node;
    	return $this;
    }
}
```

```
$config = new Configuration();
$config->addPostValidation(new ConflictWithAlt());
```

### Predefined elements

[](#predefined-elements)

#### Nodes

[](#nodes)

Some predefined nodes exists. These nodes are `Configuration` elements, with predefined allowed types, or decoration logic.

##### RootNode

[](#rootnode)

The first node of a tree, store the PostValidations and execute them. Extends `ArrayNode`.

##### ArrayNode

[](#arraynode)

Allow array type, can be a prototype.

##### ScalarNode

[](#scalarnode)

Allow integer, string, float, double and boolean value.

##### IntegerNode

[](#integernode)

Allow integer value.

##### StringNode

[](#stringnode)

Allow string value.

#### Validation

[](#validation-1)

Some predefined validations exists. These validations are `ValidationInterface` implementations.

##### AllowedValues

[](#allowedvalues)

Validate that the given value is allowed.

```
$config = new StringNode();
$config->addValidation(new AllowedValue('mysql', 'oracle'));

$config->process('mysql'); // Work
$config->process('oracle'); // Work
$config->process('mongodb'); // Fail
```

##### IsActivable

[](#isactivable)

Transform a boolean 'true' value to something. Note 'bool' type must be allowed

```
$config = new ArrayNode();
$config->addAllowedType('bool');
$config->addValidation(new IsActivable(['debug' => true, 'env' => 'test']));

$config->process(['debug' => true, 'env' => 'dev']); // Will return the input
$config->process(true); // Will return the IsActivable constructor argument
```

##### IsDisableable

[](#isdisableable)

Transform a boolean 'false' value by removing the current key.

```
$root = new RootNode();

$config = new ArrayNode();
$config->addAllowedType('bool');
$config->addValidation(new IsDisableable());

$root->addChild('manager', $config);

$root->process(['manager' => ['a', 'b', 'c']]); // Will return the input
$root->process(['manager' => false]); // Will return an empty array
```

##### IsType

[](#istype)

Validate the given element as allowed type. Usefull with concordance of IsActivable or IsDisableable

```
$config = new ArrayNode();
$config->addAllowedType('bool');
$config->addValidation(new IsActivable(['debug' => true, 'env' => 'test']));
$config->addValidation(new IsType(['array']));

$config->process(false); // Will fail due to type validation
```

### Prototype

[](#prototype)

An array node can also be a prototype. The difference is that a prototype will take all first level elements and apply the childs to each parts.

```
$config = new ArrayNode();
$config->addChild('class', new StringNode());
$config->addChild('args', new ArrayNode());

$config->getChild('class')->setRequired(true);

$config->process([
	'user' => [
		'class' => 'MyClass'
	],
	'dispatcher' => [
		'class' => 'EventDispatcher',
		'args' => [1, 2, 3]
	]
]);
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/12436206?v=4)[cscfa](/maintainers/cscfa)[@cscfa](https://github.com/cscfa)

---

Top Contributors

[![matthieu88160](https://avatars.githubusercontent.com/u/11874266?v=4)](https://github.com/matthieu88160 "matthieu88160 (7 commits)")

### Embed Badge

![Health badge](/badges/kairos-project-configuration/health.svg)

```
[![Health](https://phpackages.com/badges/kairos-project-configuration/health.svg)](https://phpackages.com/packages/kairos-project-configuration)
```

PHPackages © 2026

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