PHPackages                             simplecomplex/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. [Caching](/categories/caching)
4. /
5. simplecomplex/config

ActiveLibrary[Caching](/categories/caching)

simplecomplex/config
====================

Simple Cache like configuration interfaces; ini-files as source, cache as store.

2.1.4(7y ago)02502MITPHPPHP &gt;=7.0

Since Jul 12Pushed 6y ago2 watchersCompare

[ Source](https://github.com/simplecomplex/php-config)[ Packagist](https://packagist.org/packages/simplecomplex/config)[ Docs](https://github.com/simplecomplex/php-config)[ RSS](/packages/simplecomplex-config/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependencies (2)Versions (20)Used By (2)

Config
------

[](#config)

- [Installation](#installation)
- [Requirements](#requirements)

### Simple and sectioned configuration interfaces

[](#simple-and-sectioned-configuration-interfaces)

**`ConfigInterface`**
is basically PSR-16 Simple Cache without time-to-live.
There's a key and a value.

That principle isn't optimal for general use, unless you like real long and complex key names.

**`SectionedConfigInterface`**
Splits the item key into 'section' plus 'key', facilitating a more organized structure.

The immediate benefit is that you can namespace all items that belong to a particular library.

The section-key pattern can be implemented and utilized in two manners:

- concatenation: the configuration setters and getters simply concatenate section and key
- listing: the section is a list of keys, you can access the whole section as well as a particular key

`SectionedConfigInterface` also allows for short-term keeping items in memory, via methods `remember()` and `forget()`.

### Implementations

[](#implementations)

#### Environment variable based

[](#environment-variable-based)

**`EnvConfig`**
is a simple abstraction of server environment variables.

**`EnvSectionedConfig`**
a sectioned implementation, using concatenation.

#### Ini-files as source, cache as store

[](#ini-files-as-source-cache-as-store)

The ini-file based classes parse ini-files, and save to cache stores.

They read recursively from their ini-file paths. That allows one to clone and use ini-files from multiple version control repositories.

> Ini-files are so old-school...

Aye, but the ini format is less error-prone than JSON, YAML, what-not.
The syntax is so simple it's hard to make mistakes. And operations people are used to ini-files.

##### Cache layer

[](#cache-layer)

is [SimpleComplex Cache](https://github.com/simplecomplex/php-cache) **`PersistentFileCache`**.
Cache store names are prefixed with **`'config.'`**
Beware of conflict; do not prefix other cache stores that way.

##### Types of ini-based configuration

[](#types-of-ini-based-configuration)

**`IniConfig`**
is not sectioned. Simple but probably not that useful.
`$value = $config->get('key')`

**`IniSectionedConfig`**
is a powerful general usage implementation.
`$value = $config->get('section', 'key')`

Reads ini-files from a *base* path and an *override* path.
Keep development/production invariant variables (ini-files) in the *base* path.
Let operations keep production variables in the *override* path.

Using the list-principle - and fully supporting `remember()` and `forget()` - `IniSectionedConfig` is optimal for accessing many/all keys of a section within a limited procedure.

**`IniSectionedFlatConfig`**
a sectioned implementation, using concatenation.

Optimal for types of configuration one expects to access keys of diverse sections in an unpredictable manner, but still want the organisational benefit of sections; many but exact cache reads.
[SimpleComplex Locale](https://github.com/simplecomplex/php-locale) uses this config class for localized texts.

### Abstraction

[](#abstraction)

The **`Config`** class is an abstraction of sectioned configuration.

In this package it extends `IniSectionedConfig`.
In an extending package it could be some other sectioned config implementation.

### CLI interface

[](#cli-interface)

**`CliConfig`** delivers CLI commands for setting, getting and deleting config items.
And commands for refreshing and exporting full configuration stores.

It exposes `IniSectionedConfig` instances, via the `Config` class.
The other config classes are not accessible via CLI.

### Global config

[](#global-config)

`Config` defaults to deliver an instance named 'global'.

A typical system could probably benefit from a single config instance for the bulk of items.
Since the whole thing *runtime* is cache based, there's no performance reason for using multiple instances.

#### Dependency injection container ID: config

[](#dependency-injection-container-id-config)

Recommendation: access (and thus instantiate) the global config via DI container ID 'config'.
See [SimpleComplex Utils](https://github.com/simplecomplex/php-utils) `Dependency`.

### Example

[](#example)

```
// Bootstrap.
Dependency::genericSetMultiple([
    'cache-broker' => function () {
        return new \SimpleComplex\Cache\CacheBroker();
    },
    'config' => function() {
        return new \SimpleComplex\Config\Config('global');
    },
]);
// ...
// Use.
/** @var \Psr\Container\ContainerInterface $container */
$container = Dependency::container();
/**
 * Create or re-initialize the 'global' config store;
 * based on ini-files placed in base and override paths,
 * cached by a PSR-16 Simple Cache cache store.
 *
 * @var \SimpleComplex\Config\IniSectionedConfig $config
 */
$config = $container->get('config');
/** @var mixed $whatever */
$whatever = $config->get('some-section', 'some-key', 'the default value');
```

### CLI commands

[](#cli-commands)

```
# List all config commands and their help.
php cli.php config -h
# One command's help.
php cli.php config-xxx -h

# List existing config stores.
php cli.php config-list-stores

# Display/get value of a config item.
php cli.php config-get store section key

# Set a config item.
php cli.php config-set store section key value

# Delete a config item.
php cli.php config-delete store section key

# Refresh a config store from .ini file sources.
# The fresh store gets applied atomically, when fully built.
php cli.php config-refresh store

# Export a config store as JSON to a file.
php cli.php config-export store target-path-and-file
```

### Installation

[](#installation)

Create a 'conf' directory alongside the document root dir.

Like:
`/var/www/my-host/`**`http`**
`/var/www/my-host/`**`conf`**

Create 'base' and 'override' paths within the 'conf', like:
`conf/`**`ini/base`**
`conf/`**`ini/override`**

For the 'global' config store, place or symlink or git clone your system's
.ini configuration files under the 'base' and 'override' paths
using file extension `global.ini` (= `[store name].ini`).

Like:
`conf/ini/base/`**`some-ding.global.ini`**
`conf/ini/override/`**`some-ding.prod.global.ini`**

If that directory structure isn't suitable, do either:

- supply **`Config`** constructor with a 'paths' argument
- extend **`Config`** and override it's class constant **`PATH_DEFAULTS`**

### Requirements

[](#requirements)

- PHP &gt;=7.0
- [SimpleComplex Cache](https://github.com/simplecomplex/php-cache)
- [SimpleComplex Utils](https://github.com/simplecomplex/php-utils)

##### Suggestions

[](#suggestions)

- [SimpleComplex Inspect](https://github.com/simplecomplex/inspect)

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 99.1% 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 ~42 days

Recently: every ~63 days

Total

16

Last Release

2595d ago

Major Versions

1.x-dev → 2.02018-06-24

### Community

Maintainers

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

---

Top Contributors

[![jacobfriis](https://avatars.githubusercontent.com/u/3807905?v=4)](https://github.com/jacobfriis "jacobfriis (111 commits)")[![simplecomplex](https://avatars.githubusercontent.com/u/10960036?v=4)](https://github.com/simplecomplex "simplecomplex (1 commits)")

---

Tags

configconfigurationiniphpphp7psrphpconfigurationsimple-cachepsr-16

### Embed Badge

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

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

###  Alternatives

[psr/simple-cache

Common interfaces for simple caching

8.1k727.3M2.1k](/packages/psr-simple-cache)[sabre/cache

Simple cache abstraction layer implementing PSR-16

541.2M3](/packages/sabre-cache)

PHPackages © 2026

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