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

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

inanepain/config
================

Configuration helpers.

0.4.0(3mo ago)1121UnlicensePHPPHP &gt;=8.4

Since Oct 10Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/inanepain/config)[ Packagist](https://packagist.org/packages/inanepain/config)[ Docs](https://git.cathedral.co.za:3000/inanepain/config)[ RSS](/packages/inanepain-config/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelogDependencies (1)Versions (6)Used By (1)

inanepain/config [![icon](./icon.png "inanepain/xxx")](./icon.png)
==================================================================

[](#inanepainconfig-)

Table of Contents

- [![icon](./icon.png "inanepain/config") inanepain/config](#inanepainconfig)
- [1. Install](#install)
- [2. Config](#config)
    - [2.1. Loading configuration from files](#loading-configuration-from-files)
    - [2.2. Locking and modifications](#locking-and-modifications)
    - [2.3. Component / class-specific configuration](#component-class-specific-configuration)
    - [2.4. Creating and initialising the manager](#creating-and-initialising-the-manager)
    - [2.5. Injecting configuration into an object](#injecting-configuration-into-an-object)
    - [2.6. Retrieving configuration from the manager](#retrieving-configuration-from-the-manager)
- [3. ConfigAware helpers](#configaware-helpers)
    - [3.1. Interface: `ConfigAwareInterface`](#interface-configawareinterface)
    - [3.2. Trait: `ConfigAwareTrait`](#trait-configawaretrait)
    - [3.3. Attribute: `ConfigAwareAttribute`](#attribute-configawareattribute)
    - [3.4. `ConfigNotFoundException`](#confignotfoundexception)

[![icon](./icon.png "inanepain/config")](./icon.png) inanepain/config
---------------------------------------------------------------------

[](#-inanepainconfig)

Configuration helpers.

1. Install
----------

[](#1-install)

composer

```
composer require inanepain/config
```

2. Config
---------

[](#2-config)

The `Inane\\Config\\Config` class is a small helper built on top of `Inane\\Stdlib\\Options`. It is used to:

- load configuration from a base config file
- merge additional config files (via a `glob_pattern`)
- (optionally) lock the configuration to prevent further modifications
- provide a convention for **component/class specific** configuration via `getConfig()`

The public API is intentionally small:

- `Config::fromConfigFile()` loads/merges/locks
- `Config::getConfig()` returns a configuration subset for a specific class

### 2.1. Loading configuration from files

[](#21-loading-configuration-from-files)

The default entry point is `Config::fromConfigFile()`:

```
use Inane\Config\Config;

$config = Config::fromConfigFile();
```

By default it looks for `config/app.config.php`.

The base config file is expected to return an array (or something compatible with `Options`), e.g.:

```
// config/app.config.php

return [
    // the default key inspected by Config::fromConfigFile()
    'config' => [
        // Optional: extra files to merge in (glob brace patterns supported)
        'glob_pattern'        => 'config/autoload/{{,*.}global,{,*.}local}.php',

        // Optional: prevent modifications after initial loading
        'allow_modifications' => false,
    ],

    // application config (example)
    'appId'    => 'inane-fw',
    'services' => [
        // ...
    ],
];
```

If `glob_pattern` is set and matches files, each matching file is included and merged into the main config.

#### 2.1.1. Config file merge order

[](#211-config-file-merge-order)

The default `glob_pattern` merges `*.global.php` before `\*.local.php` allowing for default configurations to be overridden with local ones. It is recommended to have a `.gitignore` file in the autoload directory to ignore `\*.local.php` in your commits.

.gitignore for autoload directory

```
local.php
*.local.php
```

### 2.2. Locking and modifications

[](#22-locking-and-modifications)

If `allow_modifications` is `false` (the default), `Config::fromConfigFile()` locks the configuration after loading/merging. This is a convenience to ensure your configuration is treated as immutable during runtime.

If you need a mutable config instance (for tests or dynamic environments), set:

```
return [
    'config' => [
        'allow_modifications' => true,
    ],
];
```

### 2.3. Component / class-specific configuration

[](#23-component--class-specific-configuration)

`Config::getConfig(string $class)` is a convention for retrieving configuration scoped to a specific class.

By default, it looks under the `components` key and then under the given class name:

```
use Inane\Config\Config;

/** @var Config $config */
$serviceManagerConfig = $config->getConfig(Inane\Services\ServiceManager::class);
```

That means your config can be structured like this:

```
return [
    'components' => [
        Inane\Services\ServiceManager::class => [
            'cache' => true,
            'debug' => false,
        ],
    ],
];
```

Note

`getConfig()` returns `null` when no matching config is found. If you rely on class-specific config injection (see `ConfigAware` below), ensure the config entry exists for that class, or use global injection instead.

:= ConfigManager

`Inane\\Config\\ConfigManager` is a small singleton that centralises configuration access and **attribute-based injection**.

It is primarily useful in bootstrapping code where you want to:

- create/load one `ConfigInterface` instance (typically `Config::fromConfigFile()`)
- inject either global config **or** class-specific config into objects marked with `#[ConfigAwareAttribute]`

### 2.4. Creating and initialising the manager

[](#24-creating-and-initialising-the-manager)

The manager is a singleton:

```
use Inane\Config\Config;
use Inane\Config\ConfigManager;

$config = Config::fromConfigFile();

$configManager = ConfigManager::instance()
    ->setConfig($config);
```

If you don’t call `setConfig()` yourself, `setConfigFor()` will lazily initialise the manager with `Config::fromConfigFile()`.

### 2.5. Injecting configuration into an object

[](#25-injecting-configuration-into-an-object)

`ConfigManager::setConfigFor(object $object)` inspects the object via reflection and looks for the `ConfigAwareAttribute`.

When found, it will call `setConfig()` on the object:

- with the **global config** when the attribute requests global injection
- otherwise with the config subset returned by `Config::getConfig()`

In the framework, this is used during bootstrapping (see `Knot\\Application::bootstrapObject()`).

Important

`Config::getConfig()` returns `null` when no matching config is found. If you use class-specific injection, ensure you provide a matching entry under `components`.

### 2.6. Retrieving configuration from the manager

[](#26-retrieving-configuration-from-the-manager)

You can retrieve the manager’s configured `ConfigInterface` via `getConfig()`.

```
use Inane\Config\ConfigManager;

$config = ConfigManager::instance()->getConfig();
```

When you pass a `$key`, the manager will first check that a configuration subset exists for that key. If it does not, it throws `Inane\\Config\\Exception\\ConfigNotFoundException`.

Note

To actually **use** the subset, call `Config::getConfig($key)` directly on the returned config instance.

3. ConfigAware helpers
----------------------

[](#3-configaware-helpers)

The `ConfigAware` helpers provide a lightweight, opt-in way to inject configuration into objects.

They are designed to work with `Inane\\Config\\Config` but can also accept plain arrays or `Inane\\Stdlib\\Options`.

### 3.1. Interface: `ConfigAwareInterface`

[](#31-interface-configawareinterface)

To be configurable, a class can implement `Inane\\Config\\ConfigAware\\ConfigAwareInterface`:

```
use Inane\Config\ConfigAware\ConfigAwareInterface;
use Inane\Stdlib\Array\OptionsInterface;

class MyComponent implements ConfigAwareInterface {
    public function setConfig(array|OptionsInterface $config): void {
        // store config / initialise component
    }
}
```

### 3.2. Trait: `ConfigAwareTrait`

[](#32-trait-configawaretrait)

Most classes will use the provided trait instead of implementing the storage/locking logic themselves.

The trait:

- stores config in `$this→config`
- merges the provided config with an optional `$defaultConfig` property
- locks the config after it is set (to keep it effectively immutable)

Example:

```
use Inane\Config\ConfigAware\ConfigAwareInterface;
use Inane\Config\ConfigAware\ConfigAwareTrait;
use Inane\Stdlib\Array\OptionsInterface;

class MyComponent implements ConfigAwareInterface {
    use ConfigAwareTrait;

    // Optional: default/fallback config values
    protected array $defaultConfig = [
        'enabled' => true,
        'ttl'     => 60,
    ];

    public function isEnabled(): bool {
        return (bool)($this->config->enabled ?? false);
    }
}
```

Note

`ConfigAwareTrait::setConfig()` only applies once: after the internal config is locked, subsequent calls have no effect.

### 3.3. Attribute: `ConfigAwareAttribute`

[](#33-attribute-configawareattribute)

`Inane\\Config\\ConfigAware\\ConfigAwareAttribute` is a class attribute that can be used by a bootstrapper/container to decide **how** to inject configuration.

It has a single flag:

- `globalConfig=false` (default): inject config scoped to the class via `Config::getConfig(ClassName::class)`
- `globalConfig=true`: inject the global config instance as-is

Example — global config injection:

```
use Inane\Config\ConfigAware\ConfigAwareAttribute;
use Inane\Config\ConfigAware\ConfigAwareTrait;

#[ConfigAwareAttribute(true)]
class ServiceManager {
    use ConfigAwareTrait;
}
```

Example — class-specific injection:

```
use Inane\Config\ConfigAware\ConfigAwareAttribute;
use Inane\Config\ConfigAware\ConfigAwareTrait;

#[ConfigAwareAttribute]
class MyComponent {
    use ConfigAwareTrait;
}
```

With class-specific injection, ensure your configuration provides a matching entry under `components`:

```
return [
    'components' => [
        MyComponent::class => [
            'enabled' => true,
        ],
    ],
];
```

Important

In the framework bootstrap implementation (see `Knot\\Application::bootstrapObject()`), when `globalConfig=false` the injector calls:

`$object→setConfig($config→getConfig($object::class));`

Since `getConfig()` can return `null`, class-specific injection requires that the class has a config entry. If you want a safe default without providing a `components` entry, prefer `#[ConfigAwareAttribute(true)]` and/or provide a `$defaultConfig` property on the class.

:= Exceptions

### 3.4. `ConfigNotFoundException`

[](#34-confignotfoundexception)

`Inane\\Config\\Exception\\ConfigNotFoundException` is thrown when a requested configuration is missing.

It extends `Inane\\Stdlib\\Exception\\ConfigurationException`.

The exception is currently used by `ConfigManager::getConfig($key)` to fail fast when a class/component-specific configuration key does not exist.

```
use Inane\Config\ConfigManager;
use Inane\Config\Exception\ConfigNotFoundException;

try {
    // Validate that the component config exists
    $config = ConfigManager::instance()->getConfig(MyComponent::class);

    // Access the component-specific config via Config::getConfig()
    $componentConfig = $config->getConfig(MyComponent::class);
} catch (ConfigNotFoundException $e) {
    // handle missing configuration (provide defaults, abort startup, etc.)
}
```

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance87

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

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.

###  Release Activity

Cadence

Every ~404 days

Total

4

Last Release

101d ago

PHP version history (2 changes)0.1.0PHP &gt;=8.1

0.2.0PHP &gt;=8.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1823594?v=4)[Philip Michael Raab](/maintainers/inanepain)[@inanepain](https://github.com/inanepain)

---

Top Contributors

[![inanepain](https://avatars.githubusercontent.com/u/1823594?v=4)](https://github.com/inanepain "inanepain (41 commits)")

---

Tags

composerconfiglibraryphpconfiglibraryinanepain

### Embed Badge

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

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

###  Alternatives

[symfony/options-resolver

Provides an improved replacement for the array\_replace PHP function

3.2k493.9M1.6k](/packages/symfony-options-resolver)[league/config

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

564302.2M24](/packages/league-config)[league/iso3166

ISO 3166-1 PHP Library

69536.3M116](/packages/league-iso3166)[dekor/php-array-table

PHP Library for printing associative arrays as text table (similar to mysql terminal console)

296.6M2](/packages/dekor-php-array-table)

PHPackages © 2026

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