PHPackages                             ckr/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. ckr/config

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

ckr/config
==========

Simple access to multi dimensional arrays, useful for configuration data

v1.x-dev(10y ago)194MITPHPPHP &gt;=5.5.0CI failing

Since Dec 10Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/ckressibucher/config)[ Packagist](https://packagist.org/packages/ckr/config)[ RSS](/packages/ckr-config/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (6)Used By (0)

Configuration Library
=====================

[](#configuration-library)

[![Build Status](https://camo.githubusercontent.com/7944822ce9eb303a0773cb1139d500fa93cd74794538529b94f9971287caee43/68747470733a2f2f7472617669732d63692e6f72672f636b72657373696275636865722f636f6e6669672e737667)](https://travis-ci.org/ckressibucher/config)

Update 2026
-----------

[](#update-2026)

**CAUTION:** this project is not maintained anymore! **DO NOT USE IN PRODUCTION**.

Description
-----------

[](#description)

This package provides a class to manage *hierarchical data*. A common use case is configuration data.

Note that this package does not provide any readers or writers for config files of different formats. Instead it wraps php arrays and *provides easier access to its values*.

Why?
----

[](#why)

I was tired of using too many `isset` throghout all my code. The main advantage of this library is, that you can request an arbitrary deeply nested value, and provide a default value which should be returned in case the requested value does not exist:

```
$myConfig = [
  'root' => [
    'specific' => ['key' => 'val'],
  ],
];

// plain php is a bit ugly...
$theSpecific = isset($myConfig['root']['specific']['key']) ?
     $myConfig['root']['specific']['key'] : null;

$theGeneral = isset($myConfig['root']['key']) ?
     $myConfig['root']['key'] : false;

// ... but with a `Config` it looks nicer:
$config = new Ckr\Config\Config($myConfig);
$theSpecific = $config->get('root/specific/key');
$theGeneral = $config->get('root/key', false);
```

Actually, if you're using PHP7, this problem is solved:

```
// valid code in PHP7
$theSpecific= $myConfig['root']['specific']['key'] ?? null;
$theGeneral = $myConfig['root']['key'] ?? false;
```

However, as I prefer to specify the path as `root/specific/key` instead of `['root']['specific']['key']`, I still use this library in my PHP7 projects.

Usage
-----

[](#usage)

You start with a hierarchical data structure, defined as multi dimensional array:

```
$myConfig = [
  'mode' => 'production',
  'logging' => [
    'factory' => 'Your\\Logging\\Factory',
    'loggers' => [
      [
        'type' => 'file',
        'path' => '/path/to/logs',
        'level' => 'warn',
      ],
      [
        'type' => 'email',
        'addr' => 'someone@somewhere.com',
        'level' => 'critical',
      ]
    ],
  ]
];
```

Then you can wrap it in a `Config` object:

```
use Ckr\Config\Config;

$c = new Config($myConfig);

```

You can ask for a simple value with `get`:

```
$mode = $c->get('mode', 'dev');
```

In the example above, "dev" is the default mode. It is returned, if the key 'mode' does not exist in the config data.

You can ask for a value which is nested in a child array by providing a *path* of keys, separated by a Slash `/`:

```
$loggingFactoryClass = $c->get('logging/factory');
```

If any of the used path parts (keys) don't exist, the default value (`null` if not explicitly specified) is returned.

Say you want to use all of the *logging* data, e.g. to instantiate your logging instance. For this, you can get a child config object:

```
$loggingConfig = $c->child('logging'); /* @var $loggingConfig Config */

// we can now provide only the relevant data to thr logging factory
$myLoggingFactory = new $loggingFactoryClass;
$logger = $myLoggingFactory->create($loggingConfig);

// the logging factory "sees" only the data of the "logging" child array
public function create(Config $cfg)
{
  $loggers = $cfg->get('loggers'); // $loggers is an array
  foreach ($loggers as $logger) { /* ... */ }
  // ...
}
```

To summarize:

- `Config::get` will *always* return the value as it was defined originally. No matter, if the value is an array, a class instance, a function or a scalar value.
- `Config::child` expects the given path to point to an (associative) array. It wraps this array in a `Config` and returns that object.

A new value can be set using `Config::set`:

```
$newConfig = $c->set('logging/factory', 'AnotherFactoryClass');
```

This method returns *a new instance* with a specific part of the config updated (or newly set). This may be useful if you want to construct a complete configuration object in multiple steps from different parts of your code, e.g. to allow different modules to register their configuration or factories. In the above example, `$newConfig` has a value of `'AnotherFactoryClass'` at the path *logging/factory*, where the `$c` instance is *not* modified and still has the old value. (Note that this behaviour is new in Version 2.0, former versions did update the data in place).

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance59

Moderate activity, may be stable

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 92.9% 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 ~29 days

Total

5

Last Release

3697d ago

Major Versions

1.0.0-RC2 → 2.0.0-beta.12016-03-10

v1.x-dev → 2.0.0-beta.22016-04-03

### Community

Maintainers

![](https://www.gravatar.com/avatar/81e52f2fb24def14cbf90069f298696540f5268e48efff17ab0d53df1ac41137?d=identicon)[ckressibucher](/maintainers/ckressibucher)

---

Top Contributors

[![ckressibucher](https://avatars.githubusercontent.com/u/3111098?v=4)](https://github.com/ckressibucher "ckressibucher (26 commits)")[![ckrjq](https://avatars.githubusercontent.com/u/38033946?v=4)](https://github.com/ckrjq "ckrjq (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[drupal-code-builder/drupal-code-builder

Code generator for Drupal

27241.1k1](/packages/drupal-code-builder-drupal-code-builder)

PHPackages © 2026

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