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

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

ghostwriter/config
==================

Provides an object that maps configuration keys to values.

2.1.3(3mo ago)05.0M↑42.9%15BSD-3-ClausePHPPHP ~8.4.0 || ~8.5.0CI failing

Since Jan 2Pushed 4w ago1 watchersCompare

[ Source](https://github.com/ghostwriter/config)[ Packagist](https://packagist.org/packages/ghostwriter/config)[ Docs](https://github.com/ghostwriter/config)[ GitHub Sponsors](https://github.com/sponsors/ghostwriter)[ RSS](/packages/ghostwriter-config/feed)WikiDiscussions 2.1.x Synced 2w ago

READMEChangelog (10)Dependencies (10)Versions (89)Used By (15)

Config
======

[](#config)

[![Automation](https://github.com/ghostwriter/config/actions/workflows/automation.yml/badge.svg)](https://github.com/ghostwriter/config/actions/workflows/automation.yml)[![PHP Version](https://camo.githubusercontent.com/ba4b1ccee7dc6f3e06b470c5aa3ba3cad0733271dbb19b495e6da3a8ffd796a3/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f7068702f67686f73747772697465722f636f6e6669673f636f6c6f723d373737424234)](https://www.php.net/supported-versions)[![Packagist Downloads](https://camo.githubusercontent.com/bac7ed8dae60a6776af2c4acea428c8250117c183cf06111350d5adfb55ccd86/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f64742f67686f73747772697465722f636f6e6669673f636f6c6f723d463238443141)](https://packagist.org/packages/ghostwriter/config)[![PayPal](https://camo.githubusercontent.com/1efa90a77ba349664622c6961afafb52d3aaa44e609dfe3f3e262c7634f29efd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70617970616c2d40636f6465706f65742d3030373943313f6c6f676f3d64617461253341696d616765253246737667253242786d6c25334262617365363425324350484e325a79423261575633516d393450534977494441674d6a51674d6a5169494868746247357a50534a6f644852774f693876643364334c6e637a4c6d39795a7938794d4441774c334e325a794925324250484268644767675a443069545445354c6a63784e5341324c6a457a4d324d754d6a51354c5445754f445932494441744d7934784d5330754f546b354c5451754d6a5932517a45334c6a597a4e4334324d6a49674d5455754e7a4978494441674d544d754d7a4133494442494e6934794d7a566a4c5334304d5467674d4330754f5445324c6a51304e433078494334344f446c4d4d69347a4d6a4d674d6a41754e6a4979597a41674c6a4d314e6934794e5334344c6a59324e533434614451754d7a4934624330754d6a55674d5334354e545a6a4c5334774f4451754d7a55314c6a45324e6934324d6a49754e446b344c6a59794d6d677a4c6a59324d324d754e444533494441674c6a677a4d6930754d6a59334c6a6b784e5330754e7a4578646930754d6a5933624334334e446b744e4334324d6a4a324c5334784e7a686a4c6a41344d7930754e4451304c6a55744c6a67754f5445314c53343461433431597a4d754e546334494441674e69347a4d6a55744d5334314d5341334c6a45314e6930314c6a6b314e5334304d5467744d5334344e6a63754d6a55794c544d754d7a63344c5334334e4463744e4334304e4455744c6a49314c53347a4e5455744c6a59324e6930754e6a49794c5445744c6a67344f5349675a6d6c7362443069497a41774f574e6b5a534976506a78775958526f49475139496b30784f5334334d5455674e6934784d7a4e6a4c6a49304f5330784c6a67324e6941774c544d754d5445744c6a6b354f5330304c6a49324e6b4d784e7934324d7a51754e6a4979494445314c6a63794d5341774944457a4c6a4d774e794177534459754d6a4d31597930754e444534494441744c6a6b784e6934304e4451744d5341754f446735544449754d7a497a494449774c6a59794d6d4d774943347a4e5459754d6a55754f4334324e6a55754f4767304c6a4d794f4777784c6a45324e4330334c6a4d334f4330754d44677a4c6a49324e324d754d4467304c5334314d7a4d754e5330754f4467354c6a6b354f4330754f446735614449754d44686a4e4334774e7a6b674d4341334c6a49304d5330784c6a63334f4341344c6a49304c5459754e7a55314c5334774f444d744c6a49324e7941774c53347a4e5459674d4330754e544d304969426d615778735053496a4d4445794d54593549693825324250484268644767675a44306954546b754e54597a494459754d544d7a597934774f4449744c6a49324e6934794e5330754e544d7a4c6a51354f4330754e7a45754d545932494441674c6a49314c5334774f5334304d5459744c6a4135614455754e446b30597934324e6a59674d4341784c6a4d7a4c6a4135494445754f444d754d5463344c6a45324e6941774943347a4d7a4d674d4341754e446b344c6a41344f5334784e6a67754d4467354c6a4d7a4e4334774f446b754e4445344c6a45334f4767754d6a566a4c6a49304f4334774f446b754e446b334c6a49324e6934334e4467754d7a55314c6a49304f4330784c6a67324e6941774c544d754d5445744c6a6b354f5330304c6a4d314e554d784e7934334d5463754e544d7a494445314c6a67774e4341774944457a4c6a4d35494442494e6934794d7a566a4c5334304d5467674d4330754f5445324c6a4d314e693078494334344f446c4d4d69347a4d6a4d674d6a41754e6a4979597a41674c6a4d314e6934794e5334344c6a59324e533434614451754d7a4934624445754d5459304c5463754d7a6334494445754d4467304c5463754f5446364969426d615778735053496a4d44417a4d4467334969382532425043397a646d63253242)](https://paypal.me/codepoet)[![Sponsors via GitHub](https://camo.githubusercontent.com/772d7f4f0f2d5c2f18f3e0f79ad866b148c0b7f8621039d628224c7d3254299e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73706f6e736f72732f67686f73747772697465723f6c6162656c3d53706f6e736f722b4067686f73747772697465722f636f6e666967266c6f676f3d4769744875622b53706f6e736f7273)](https://github.com/sponsors/ghostwriter)

Provides an object that maps configuration keys to values.

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

[](#installation)

You can install the package via composer:

```
composer require ghostwriter/config
```

### Star ⭐️ this repo if you find it useful

[](#star-️-this-repo-if-you-find-it-useful)

You can also star (🌟) this repo to find it easier later.

Features
--------

[](#features)

- 🔑 **Dot Notation**: Access nested configuration using dot, forward slash, or backslash separators
- 🔄 **Flexible Merging**: Merge arrays, files, or directories
- 🔧 **Array Operations**: Append and prepend values to configuration arrays
- 🎯 **Scoped Configuration**: Wrap nested configuration into isolated instances

API
---

[](#api)

```
/**
 * @template T of (array|bool|float|int|null|string)
 */
interface ConfigurationInterface
{
    /** @throws ConfigurationExceptionInterface */
    public function append(string $key, mixed $value): void;

    /** @throws ConfigurationExceptionInterface */
    public function get(string $key, mixed $default = null): mixed;

    /** @throws ConfigurationExceptionInterface */
    public function has(string $key): bool;

    /**
     * @param array $options
     * @throws ConfigurationExceptionInterface
     */
    public function merge(array $options): void;

    /** @throws ConfigurationExceptionInterface */
    public function mergeDirectory(string $directory): void;

    /** @throws ConfigurationExceptionInterface */
    public function mergeFile(string $file, ?string $key = null): void;

    /** @throws ConfigurationExceptionInterface */
    public function prepend(string $key, mixed $value): void;

    public function reset(): void;

    /** @throws ConfigurationExceptionInterface */
    public function set(string $key, mixed $value): void;

    /** @return array */
    public function toArray(): array;

    /** @throws ConfigurationExceptionInterface */
    public function unset(string $key): void;

    /**
     * @param array $default
     * @throws ConfigurationExceptionInterface
     */
    public function wrap(string $key, array $default = []): self;
}
```

Usage
-----

[](#usage)

Given the following configuration directory structure

- `path/to/config/directory/app.php`
- `path/to/config/directory/database.php`
- `path/to/config/directory/file.php`

```
$directory = 'path/to/config/directory';
$file = 'path/to/config/directory/file.php';
$options = [
    'settings' => [
        'enable' => true,
    ],
];

$configuration = Configuration::new($options);
$configuration->has('settings.disabled'); // false
$configuration->get('settings.disabled'); // null
$configuration->get('settings.disabled', 'default'); // 'default'

$configuration->set('settings.disabled', false);

$configuration->has('settings.disabled'); // true
$configuration->get('settings.disabled'); // false

$configuration->toArray(); // ['settings' => ['enable'=>true,'disabled'=>false]]

$configuration->unset('settings.disabled');

$configuration->get('settings.disabled'); // null
$configuration->get('settings.disabled', 'default'); // 'default'

$configuration->toArray(); // ['settings' => ['enable'=>true]]
```

```
// from an array
$configuration = Configuration::new($options);
$configuration->toArray(); // ['settings' => ['enable'=>true]]
```

```
// merge additional config options
$additionalOptions = [
    'settings' => [
        'disabled' => false,
    ],
];
$configuration = Configuration::new($options);
$configuration->merge($additionalOptions);
$configuration->toArray(); // ['settings' => ['enable'=>true,'disabled'=>false]]
```

```
// from an array with dot notation
$configuration = Configuration::new($options);
$configuration->toArray(); // ['settings' => ['enable'=>true]]

$configuration->has('settings'); // true
$configuration->has('settings.enable'); // true
$configuration->get('settings.enable'); // true
```

```
// from a directory
$configuration = Configuration::new();

$configuration->mergeDirectory($directory);

$configuration->toArray(); // output below
// [
//      'app' => ['name'=>'App','version'=>'1.0.0'],
//      'database' => ['host'=>'localhost','port'=>3306],
//      'file' => ['path'=>'/path/to/file']
// ]
```

```
// from a file
$configuration = Configuration::new();
$configuration->mergeFile($file);
$configuration->toArray(); // ['path'=>'/path/to/file']

// from a file with a namespace key
$configuration = Configuration::new();
$configuration->mergeFile($file, 'custom');
$configuration->toArray(); // ['custom' => ['path'=>'/path/to/file']]
```

```
// append values
$configuration = Configuration::new($options);
$configuration->append('settings', ['key' => 'value']);
$configuration->toArray(); // ['settings' => ['enable'=>true,'key'=>'value']]
```

```
// prepend values
$configuration = Configuration::new($options);
$configuration->prepend('settings', ['key' => 'value']);
$configuration->toArray(); // ['settings' => ['key'=>'value','enable'=>true]]
```

```
// wrap configuration into a new scoped instance
$configuration = Configuration::new([
    'database' => [
        'host' => 'localhost',
        'port' => 3306,
    ],
]);

$dbConfig = $configuration->wrap('database');
$dbConfig->get('host'); // 'localhost'
$dbConfig->toArray(); // ['host' => 'localhost', 'port' => 3306]

// wrap with default values when key doesn't exist
$cacheConfig = $configuration->wrap('cache', ['driver' => 'redis']);
$cacheConfig->toArray(); // ['driver' => 'redis']
```

```
// reset configuration
$configuration = Configuration::new(['key' => 'value']);
$configuration->toArray(); // ['key' => 'value']

$configuration->reset();
$configuration->toArray(); // []
```

```
// mixed separators support (dot, forward slash, backslash)
$configuration = Configuration::new();
$configuration->set('app.name', 'MyApp');
$configuration->get('app.name'); // 'MyApp'
$configuration->get('app/name'); // 'MyApp' (forward slash)
$configuration->get('app\name'); // 'MyApp' (backslash)

$configuration->has('app.name'); // true
$configuration->has('app/name'); // true
$configuration->has('app\name'); // true
```

```
// append/prepend to nested keys
$configuration = Configuration::new();
$configuration->append('list.items', 'first');
$configuration->append('list.items', 'second');
$configuration->toArray(); // ['list' => ['items' => ['first', 'second']]]

$configuration->prepend('list.items', 'zero');
$configuration->toArray(); // ['list' => ['items' => ['zero', 'first', 'second']]]
```

```
// automatic array promotion
$configuration = Configuration::new();
$configuration->set('parent', 'scalar');
$configuration->set('parent.child', 'value'); // 'parent' is promoted to array
$configuration->toArray(); // ['parent' => ['child' => 'value']]
```

### Changelog

[](#changelog)

Please see [CHANGELOG.md](./CHANGELOG.md) for more information on what has changed recently.

### Credits

[](#credits)

- [Nathanael Esayeas](https://github.com/ghostwriter)
- [All Contributors](https://github.com/ghostwriter/config/contributors)

### License

[](#license)

Please see [LICENSE](./LICENSE) for more information on the license that applies to this project.

### Security

[](#security)

Please see [SECURITY.md](./SECURITY.md) for more information on security disclosure process.

###  Health Score

61

—

FairBetter than 99% of packages

Maintenance87

Actively maintained with recent releases

Popularity43

Moderate usage in the ecosystem

Community18

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

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

Recently: every ~22 days

Total

23

Last Release

29d ago

Major Versions

0.4.x-dev → 1.0.02025-01-07

1.1.x-dev → 2.0.02025-11-01

1.0.x-dev → 2.0.12025-11-19

2.2.x-dev → 3.0.x-dev2026-06-14

PHP version history (7 changes)0.1.0PHP &gt;=8.1,&lt;8.3

0.4.0PHP &gt;=8.1 &lt;8.3

0.4.1PHP &gt;=8.1 &lt;8.4

1.0.0PHP &gt;=8.4

1.1.x-devPHP ^8.4

2.0.0PHP ~8.4.0 || ~8.5.0

2.2.x-devPHP ~8.4.0 || ~8.5.0 || ~8.6.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/1dbb0131801cc451dad9917ab29aa823b25d7eebc9f3875a9d481d109bdb44ee?d=identicon)[ghostwriter](/maintainers/ghostwriter)

---

Top Contributors

[![ghostwriter](https://avatars.githubusercontent.com/u/9754361?v=4)](https://github.com/ghostwriter "ghostwriter (1586 commits)")

---

Tags

configconfigurationghostwriterconfigghostwriter

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[symfony/options-resolver

Provides an improved replacement for the array\_replace PHP function

3.2k537.3M2.1k](/packages/symfony-options-resolver)[league/config

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

567347.0M41](/packages/league-config)[m1/env

Env is a lightweight library bringing .env file parser compatibility to PHP. In short - it enables you to read .env files with PHP.

6413.0M25](/packages/m1-env)

PHPackages © 2026

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