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

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

theiconic/config
================

configuration handler for file based configuration

v1.0.5(8y ago)318.0k—5.7%1[1 issues](https://github.com/theiconic/config/issues)MITPHPPHP &gt;=7.1CI failing

Since Jun 6Pushed 8y ago81 watchersCompare

[ Source](https://github.com/theiconic/config)[ Packagist](https://packagist.org/packages/theiconic/config)[ RSS](/packages/theiconic-config/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (3)Versions (12)Used By (0)

theiconic/config
================

[](#theiconicconfig)

General purpose config manager for file-based configuration.

[![Build Status](https://camo.githubusercontent.com/010bad262318216f150467d797ae2a5be0140082cf08ba1d6a3762643fe481b4/68747470733a2f2f7472617669732d63692e6f72672f74686569636f6e69632f636f6e6669672e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/theiconic/config)[![Coverage Status](https://camo.githubusercontent.com/5dc524bb9220772c953cbf6105f0b0e6183356cf300ae5bee2ec3bd98fb8122f/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f74686569636f6e69632f636f6e6669672f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/theiconic/config?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/bb48b822ee98d21cfd6e1ef0b1bb1b296a7cd52a01e0f455737e6074f7523976/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f74686569636f6e69632f636f6e6669672f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/theiconic/config/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/65cf1bfdea9db302a043e3f1a09ddd3da24bff5a23aa90cc7461dca78857dc50/68747470733a2f2f706f7365722e707567782e6f72672f74686569636f6e69632f636f6e6669672f762f737461626c65)](https://packagist.org/packages/theiconic/config)[![Total Downloads](https://camo.githubusercontent.com/c1dfe901b9d756a2d58aaf7ac67bd34f630c39bc35b15bff19ab175e11fee790/68747470733a2f2f706f7365722e707567782e6f72672f74686569636f6e69632f636f6e6669672f646f776e6c6f616473)](https://packagist.org/packages/theiconic/config)[![License](https://camo.githubusercontent.com/c075df89ff08b883cf5401016381702e212a8c44cd9cfde5b54791e45d7f86fd/68747470733a2f2f706f7365722e707567782e6f72672f74686569636f6e69632f636f6e6669672f6c6963656e7365)](https://packagist.org/packages/theiconic/config)[![Dependency Status](https://camo.githubusercontent.com/6264b81eb5b4cf5d5392dbaad094db6b2a974045cbc7954145c6ff06f708100b/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3539323761393839663561396136303034386335613332362f62616467652e7376673f7374796c653d666c6174)](https://www.versioneye.com/user/projects/5927a989f5a9a60048c5a326)

Setup
-----

[](#setup)

```
composer require theiconic/config

```

Concepts
--------

[](#concepts)

### Spaces

[](#spaces)

Configuration is grouped into configuration spaces. Spaces are managed by the configuration factory.

### Multi-file &amp; multi-section configuration

[](#multi-file--multi-section-configuration)

A configuration space can read configuration from several files. The configuration is merged and then flattened by section.

### Placeholders

[](#placeholders)

During parsing, pre-defined placeholders will be replaced with the configured replacement values.

### Example

[](#example)

So the basic setup looks something like this (modified example based on alice):

```
// get the factory instance
$factory = Factory::getInstance();

// set the current environment
$factory->setEnvironment(APPLICATION_ENV);

// configure cache path
$factory->setCachePath(sprintf('%s/config', APPLICATION_TMP));

// instanciate and configure the application config space
$factory->getSpace('application')
    ->setPaths([
        '/etc/iconic.ini',
        $basePath . 'application.ini',
        $basePath . 'application.local.ini',
    ])
    ->setSections([
        'default',
        'production',
    ])
    ->setPlaceholders([
        '%APPLICATION_ENV%' => APPLICATION_ENV,
        '%APPLICATION_ROOT%' => APPLICATION_ROOT,
        '%APPLICATION_TMP%' => APPLICATION_TMP,
    ]);

```

Multi-section config format
---------------------------

[](#multi-section-config-format)

Configuration files must contain configuration sections. This is the sections in .ini files and the first level array/object items in .php or .json config files.

No sections are pre-selected by default. You will need to explicitly state the sections in code, like so:

```
$factory->getSpace('myConfig')
    ->setSections(['main', 'development', 'testing']);

```

Sections will be merged in the order specified, i.e. entries in later sections will override those in earlier sections.

Caching
-------

[](#caching)

All configuration is parsed into multidimensional PHP arrays. The arrays are then stored in cache files so that expensive parsing is bypassed.

Cache keys are determined based on

- the list of source files names
- the list on section names.

Cache is automatically validated based on file modification timestamps. Hence, the cache will automatically update itself whenever any of the source configuration files changes.

Parsing
-------

[](#parsing)

Extendable parsers are used to parse different file formats. Currently implemented parsers are:

- Ini (for .ini files)
- Json (for .json files)
- Php (for .php files)
- Autodetect (automatically picks the right parser based on extension)
- Dummy (for unit tests etc.)

Accessing configuration values
------------------------------

[](#accessing-configuration-values)

Configuration can be accessed via dot-paths. These paths are dynamically resolved against the internal array-representation of configuration. This allows retrieving individual entries as well as collections of entries.

```
Factory::getInstance()->getSpace('application')->get('redis.retries', 3);
Factory::getInstance()->getSpace('application')->get('redis.hosts', 'localhost');

Factory::getInstance()->getSpace('application')->get('redis', ['retries': 3, 'hosts': 'localhost]);

```

You can also retrieve the configuration as a flat array of dot-path to value mappings:

```
Factory::getInstance()->getSpace('application')->flatten();

```

Using environment variables
---------------------------

[](#using-environment-variables)

There is no explicit functionality to handle environment variables, however they can be dynamically used in the configurations via the placeholders mechanism:

```
$space = Factory::getInstance()->getSpace('application');
foreach ($_ENV as $key => $value) {
    $placeholder = sprintf('%%ENV_%s%%', strtoupper(str_replace('%', '_', $key)));
    $space->addPlaceholder($placeholder, $value);
}

```

With these few lines in place, a configuration file could look like this:

```
[main]
user.name = %ENV_USER%
user.home = %ENV_HOME%

```

License
-------

[](#license)

THE ICONIC config library for PHP is released under the MIT License.

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance13

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity65

Established project with proven stability

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

Recently: every ~80 days

Total

12

Last Release

3003d ago

Major Versions

v0.2.0 → v1.0.02017-05-24

PHP version history (2 changes)v1.0.1PHP &gt;=7.0

v1.0.5PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/69ecbb50b3565cc040b7bb0431f1437f8b8358d906d4a23a71e47232dc3d49b3?d=identicon)[wyrfel](/maintainers/wyrfel)

---

Top Contributors

[![wyrfel](https://avatars.githubusercontent.com/u/425403?v=4)](https://github.com/wyrfel "wyrfel (40 commits)")

---

Tags

configurationlibraryphpphp7

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[droptica/droopler-project

Project template for Droopler with Composer

5010.1k](/packages/droptica-droopler-project)

PHPackages © 2026

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