PHPackages                             nabeghe/configurator - 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. nabeghe/configurator

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

nabeghe/configurator
====================

A PHP configuration management library that supports file-based storage and loads each section lazily.

v1.2.0(4mo ago)16MITPHPPHP &gt;=8.3

Since Dec 16Pushed 4mo agoCompare

[ Source](https://github.com/nabeghe/configurator-php)[ Packagist](https://packagist.org/packages/nabeghe/configurator)[ Docs](https://github.com/nabeghe/configurator-php)[ RSS](/packages/nabeghe-configurator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (5)Used By (0)

Nabeghe Configurator for PHP
============================

[](#nabeghe-configurator-for-php)

> A PHP configuration management library that supports file-based storage and loads each section lazily.

---

Features
--------

[](#features)

- **Section-Based Configuration**: Organize your config into named sections for better structure and readability.
- **ArrayAccess &amp; Magic Methods**: Access configuration sections and keys using array syntax or object properties.
- **Lazy Loading of Sections**: Configuration sections are loaded only when accessed, reducing memory usage and improving performance.
- **Type-Safe Access**: Supports IDE autocomplete and type hinting via Proxy classes and PHPDoc annotations.
- **Dot Notation Support**: Easily get or set nested configuration values with intuitive dot paths (e.g., `database.connections.mysql.host`).
- **Defaults Handling**: Define default values for keys, ensuring fallback values when a key is missing.
- **File-Based Persistence**: Save and load configuration sections to individual PHP files.
- **Dynamic Proxy System**: Each configuration section is accessible via a Proxy class, providing seamless interaction and encapsulation.
- **Caching**: Optional APCu or file-based caching to improve performance by storing available file metadata.
- **Utility Methods**: Easily manage keys, delete sections, iterate over values, or eject sections from memory.

---

### Installation

[](#installation)

Install via Composer:

```
composer require nabeghe/configurator
```

Usage
-----

[](#usage)

1. Create a configuration class and extend it from `Configurator`.
2. Define the `DEFAULTS` constant in this class. This constant is an array that can contain arbitrary values. Each key represents a section, and its value is an array of that section’s configuration values (for example: `db`, `log`, etc.).
3. It is recommended to create a separate class for each section. This class is used only for IDE type hinting and has no other functional purpose. In this class, you can define the keys that the section may contain, along with their types, using `@property` annotations in the docblock comments. This class must extend the `Proxy` class, because each section is a `Proxy`.
4. Instantiate your configuration class.

### Configurator Constructor

[](#configurator-constructor)

The constructor accepts three parameters:

- First parameter: The path to a directory where each section can be stored as a separate PHP file. Each file must return an array. For example, a section named `db.php` can be used for database configuration. The default value is `null`, meaning no directory is used.
- Second parameter: Configuration data. You may inject configuration data for each section at instantiation time. In this case, the data will not be loaded from the directory. The default value is an empty array.
- Third parameter: Specifies whether APCu should be used. It is used only to cache the list of available files and has no other purpose. If not set, a file named `_.cache` will be used in the specified directory instead.

**Note 1:**
By default, the directory path is `null`. If it is not set, loading configuration from files and persisting configurations is not possible. Therefore, if your configuration is file-based, you should set this path.

**Note 2:**
Injecting data together with a directory path is allowed. In this case, the injected sections will no longer be loaded from their corresponding files.

```
use Nabeghe\Configurator\Configurator;
use Nabeghe\Configurator\Proxy;

class MyConfig extends Configurator
{
    const DEFAULTS = [
        'db' => [
            'type' => 'mysql',
            'host' => 'localhost',
            'port' => 3306,
        ],
        'debug' => [
            'enabled' => true,
        ],
    ];
}

$config = new MyConfig(path: __DIR__ . '/config');

// Accessing sections via Proxy
$db = $config->db;
echo $db->host; // localhost

// Using dot notation
$config->dot('db.host', '127.0.0.1');
echo $config->dot('db.host'); // 127.0.0.1

// Adding new keys or editing
$config->app->version = '1.0.0';

// Save a section
$config->db->save();

// Delete a key
$config->db->del('port');

// Iterate through keys
$config->database->each(function($key, $value) {
    echo "$key => $value\n";
});

// Get all configuration data including defaults
$allConfig = $config->getAll(addDefaults: true);
```

Cache file
----------

[](#cache-file)

A file named `_.cache` is reserved. If APCu is not available, the list of existing configuration files is stored in this file. Although the system automatically updates the list, it is recommended to delete the `_.cache` file whenever you add a new file or remove an existing one.

Configurator class
------------------

[](#configurator-class)

MethodDescription\_\_construct($path, $config, $apcuAllowed)Initialize configurator with path, initial config and cache option\_\_get($name)Get a Proxy instance for a config section\_\_set($name, $value)Set or create a config section (via Proxy)getPath()Get configuration directory pathsetPath($value)Set configuration directory pathisLoadable()Check if file loading/saving is enabledhasDefault($section, $key)Check if a default value existsgetDefault($section, $key)Get default value for a keygetDefaults($section)Get all default values of a sectionhas($section, $key)Check if a key exists in a sectionget($section, $key)Get a config value (falls back to default)set($section, $key, $value)Set a config valuesetOnce($section, $key, $value)Set a value only if it does not existdot($path, $value = null)Get/set config using dot-notationdel($section, $key)Delete a key from a sectiongetAll($section = null, $addDefaults = false)Get all config datasetAll($sectionOrArray, $config = \[\])Replace section or full configgetKeys($section, $addDefaults = false)Get keys of a sectionisEmpty($section = null)Check if section or config is emptygeneratePath($section)Generate file path for a sectionload($proxyOrName)Load section config from filesave($proxyOrName = null)Save section(s) to fileclear($proxyOrName)Clear config values of a sectiondelete($proxyOrName)Delete config file of a sectioneject($proxyOrName)Remove section from memoryejectAll($excepts = \[\])Remove all sections except given oneseach($section, $callback, $addDefaults = false)Iterate over section valuesmkdirs($path, $permissions)Recursively create directoriesgetCacheName()Get cache identifier namehasCache()Check if cache existsgetCache()Retrieve cached metadataupdateCache()Update cache with file metadatadelCache()Delete cache entryoffsetExists($offset)ArrayAccess: check section existsoffsetGet($offset)ArrayAccess: get section ProxyoffsetSet($offset, $value)ArrayAccess: set sectionoffsetUnset($offset)ArrayAccess: remove sectionProxy class
-----------

[](#proxy-class)

This class is used for each configuration section.

MethodDescription\_\_construct($configurator, $name)Create a proxy for a configuration sectionoffsetExists($key)ArrayAccess: check if a key existsoffsetGet($key)ArrayAccess: get a value by keyoffsetSet($key, $value)ArrayAccess: set a value by keyoffsetUnset($key)ArrayAccess: remove a key\_\_get($key)Get a config value via property access\_\_set($key, $value)Set a config value via property accesshas($key)Check if a key exists in the sectiongetName()Get section namegetDefaults()Get default values of the sectiongetKeys()Get all keys in the sectionisEmpty()Check if section is emptygetAll($addDefaults = false)Get all config valuessetAll($config)Replace all section valueshasDefault($key)Check if a default exists for keygetDefault($key)Get default value for keyload()Load section config from filesave()Save section config to fileclear()Clear all values in sectiondelete()Delete section config fileeject()Remove section from memoryeach($callback, $addDefaults = false)Iterate over key-value pairs📖 License
---------

[](#-license)

Licensed under the MIT license, see [LICENSE.md](LICENSE.md) for details.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance75

Regular maintenance activity

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity53

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

Total

4

Last Release

137d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/dae1bf378bcf40fe55c193160377d613d628188587554a3fb11cdec6f0521ba1?d=identicon)[nabeghe](/maintainers/nabeghe)

---

Top Contributors

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

---

Tags

helperconfigurationSettingsconfiglibraryconfigurator

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nabeghe-configurator/health.svg)

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

###  Alternatives

[chillerlan/php-settings-container

A container class for immutable settings objects. Not a DI container.

3427.3M21](/packages/chillerlan-php-settings-container)[dmishh/settings-bundle

Database centric Symfony configuration management. Global and per-user settings supported.

115254.9k1](/packages/dmishh-settings-bundle)[caseyamcl/configula

A simple, but versatile, PHP config loader

42146.6k6](/packages/caseyamcl-configula)

PHPackages © 2026

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