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

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

tomwright/php-config
====================

A simple class to make configs easy.

1.0.2(8y ago)33851PHP

Since Nov 10Pushed 8y ago1 watchersCompare

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

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

Config
======

[](#config)

[![Build Status](https://camo.githubusercontent.com/9bb13ea8389ff633f540ea0044541f6b805026d23308de812e9fe113e04776f2/68747470733a2f2f7472617669732d63692e6f72672f546f6d5772696768742f504850436f6e6669672e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/TomWright/PHPConfig)[![Test Coverage](https://camo.githubusercontent.com/938bae54f093e47d0466bdc7504e3b169c1621c65d46a4c85f7db6e4754884f7/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f546f6d5772696768742f504850436f6e6669672f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/TomWright/PHPConfig/coverage)[![Latest Stable Version](https://camo.githubusercontent.com/fedb82fedfc371b86befb0b35b252d96d15451ea6c81cc884698a19541dd8bc0/68747470733a2f2f706f7365722e707567782e6f72672f746f6d7772696768742f7068702d636f6e6669672f762f737461626c65)](https://packagist.org/packages/tomwright/php-config)[![Total Downloads](https://camo.githubusercontent.com/96b38f5313f4fe217503f9ca27fc8dfa356b455ab67747aba591bd5d4b08c339/68747470733a2f2f706f7365722e707567782e6f72672f746f6d7772696768742f7068702d636f6e6669672f646f776e6c6f616473)](https://packagist.org/packages/tomwright/php-config)[![Monthly Downloads](https://camo.githubusercontent.com/385c987a54cfcb0490321b4d337c8cd5a925d561e860ce96e887ffe530e65f82/68747470733a2f2f706f7365722e707567782e6f72672f746f6d7772696768742f7068702d636f6e6669672f642f6d6f6e74686c79)](https://packagist.org/packages/tomwright/php-config)[![Daily Downloads](https://camo.githubusercontent.com/158a8ad43eda1db6620082b789c9c5623939dd4b125e4b1f4ddec63399a49aa8/68747470733a2f2f706f7365722e707567782e6f72672f746f6d7772696768742f7068702d636f6e6669672f642f6461696c79)](https://packagist.org/packages/tomwright/php-config)[![License](https://camo.githubusercontent.com/cf208712f932a1aae1c480dc864597b235997d52bdf9956fbd0bc6f096c0b232/68747470733a2f2f706f7365722e707567782e6f72672f746f6d7772696768742f7068702d636f6e6669672f6c6963656e73652e737667)](https://packagist.org/packages/tomwright/php-config)

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

[](#installation)

```
composer require tomwright/php-config

```

General Usage
-------------

[](#general-usage)

Create an instance of `Config` to get going:

```
$config = new Config();
```

### Add values to the config as follows

[](#add-values-to-the-config-as-follows)

```
$config->put('key', 'value');
```

### Get values from the config as follows

[](#get-values-from-the-config-as-follows)

```
$value = $config->get('key');
```

Storing Data
------------

[](#storing-data)

You can add separators to the `key` string in order to have the data stored slightly differently.

For example, let's say we have a contact name and email address. You can set this in any of the following ways:

```
$config->put('contact', [
    'name' => 'Tom',
    'email' => 'contact@tomwright.me',
]);

$config->put('contact.name', 'Tom');
$config->put('contact.email', 'contact@tomwright.me');
```

You can even mix and match between the above:

```
$config->put('contact', [
    'name' => 'Tom',
]);

$config->put('contact.email', 'contact@tomwright.me');
```

Fetching Data
-------------

[](#fetching-data)

You can use the dot separators in a similar way to the above when fetching data too.

Assuming we have the same contact details stored, let's look at the following:

```
$config->get('contact'); // [ 'name' => 'Tom', 'email' => 'contact@tomwright.me' ]

$config->get('contact.name'); // Tom
$config->get('contact.email'); // contact@tomwright.me
```

Separators
----------

[](#separators)

You can use as many separators in the key as you would like. The following will end up working in the same way as the above, just with a deeper level of storage.

```
$config->put('company.person.tom.email', 'contact@tomwright.me');
$config->put('company.person.jim.email', 'jim@tomwright.me');

$config->get('company');
/*
[
    'person' => [
        'tom' => [ 'email' => 'contact@tomwright.me' ],
        'jim' => [ 'email' => 'jim@tomwright.me' ],
    ]
]
*/

```

If you would like to use a separator other than the `.` character, you may set one using the `setSeparator()` method, or by passing it in in the Config constructor.

```
$config = new Config([
    'separator' => '|', // Equal
]);
$config->setSeparator('|'); // Equal

$config->put('contact', [
    'contact' => [
        'name' => 'Tom',
        'email' => 'contact@tomwright.me',
    ],
]);

$config->get('contact|name'); // Tom
$config->get('contact.email'); // NULL
```

Config Readers
--------------

[](#config-readers)

Config readers are classes to help you auto-populate the config object with values. To use a Config Reader, simply pass it into `$config->read()`.

```
$config = new Config();
$config->read(new SomeConfigReader());
$config->get('some.value.from.my.reader');

```

You can also pass an array of Config Readers into the Config constructor:

```
$config = new Config([
    'readers' => [
        new SomeConfigReader(),
    ],
]);
$config->get('some.value.from.my.reader');

```

### Existing Config Readers

[](#existing-config-readers)

If you would like to create a Config Reader please feel free. The only requirement is that you implement the `ConfigReader` interface. If you have already created a Config Reader and would like it to appear here, please submit a pull request.

- [PHPFileReader](/docs/PHPFileReader.md)
- [JSONFileReader](/docs/JSONFileReader.md)

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity67

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

Total

5

Last Release

3143d ago

Major Versions

0.0.2 → 1.0.02017-11-21

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/935867?v=4)[Tom Wright](/maintainers/TomWright)[@TomWright](https://github.com/TomWright)

---

Top Contributors

[![TomWright](https://avatars.githubusercontent.com/u/935867?v=4)](https://github.com/TomWright "TomWright (17 commits)")

---

Tags

configphpphp-7

### Embed Badge

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

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

###  Alternatives

[pestphp/pest

The elegant PHP Testing Framework.

11.6k72.2M19.7k](/packages/pestphp-pest)[drupal/core-dev

require-dev dependencies from drupal/drupal; use in addition to drupal/core-recommended to run tests from drupal/core.

2022.6M335](/packages/drupal-core-dev)[ec-europa/toolkit

Toolkit packaged for Drupal projects based on Robo.

40252.8k34](/packages/ec-europa-toolkit)

PHPackages © 2026

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