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

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

phossa2/config
==============

A simple, easy to use, yet powerful configuration management library for PHP.

2.0.12(9y ago)32331MITPHPPHP &gt;=5.4.0

Since Jun 28Pushed 6y ago1 watchersCompare

[ Source](https://github.com/phossa2/config)[ Packagist](https://packagist.org/packages/phossa2/config)[ Docs](https://github.com/phossa2/config)[ RSS](/packages/phossa2-config/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (10)Dependencies (2)Versions (14)Used By (1)

phossa2/config \[ABANDONED\]
============================

[](#phossa2config-abandoned)

**PLEASE USE [phoole/config](https://github.com/phoole/config) library instead**

[![Build Status](https://camo.githubusercontent.com/a547628b9c2ce89f4adb02de59258fcd41c53b450d41c8435ef251a0c38edc19/68747470733a2f2f7472617669732d63692e6f72672f70686f737361322f636f6e6669672e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/phossa2/config)[![Code Quality](https://camo.githubusercontent.com/baedc301be8bf6910595b9bb1790bc3a90fb191c13e53e198d9a4c34800318fc/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f70686f737361322f636f6e6669672f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/phossa2/config/)[![Code Climate](https://camo.githubusercontent.com/77ebf7059953faaec1ff9071bf9d9d487c09c0ac2440ca93000669c9aa644516/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f70686f737361322f636f6e6669672f6261646765732f6770612e737667)](https://codeclimate.com/github/phossa2/config)[![PHP 7 ready](https://camo.githubusercontent.com/47790063fd8e2ff69bc49a3f421599449ec6d9fc441f0c85e6079f924813b8c3/687474703a2f2f7068703772656164792e74696d6573706c696e7465722e63682f70686f737361322f636f6e6669672f6d61737465722f62616467652e737667)](https://travis-ci.org/phossa2/config)[![HHVM](https://camo.githubusercontent.com/20a77d0841909ff2e0debb2e82f820bbfc6367455009270c9e03bc9cf810a94f/68747470733a2f2f696d672e736869656c64732e696f2f6868766d2f70686f737361322f636f6e6669672e7376673f7374796c653d666c6174)](http://hhvm.h4cc.de/package/phossa2/config)[![Latest Stable Version](https://camo.githubusercontent.com/92e7e2027038b23f46861b3217f612bd901513b9af5171e91fdf433640cf1a9b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f767072652f70686f737361322f636f6e6669672e7376673f7374796c653d666c6174)](https://packagist.org/packages/phossa2/config)[![License](https://camo.githubusercontent.com/4fc6538ded72843e26a272d300ce4c95da083ce92576e10e4fdd505d579a8125/68747470733a2f2f696d672e736869656c64732e696f2f3a6c6963656e73652d6d69742d626c75652e737667)](http://mit-license.org/)

**phossa2/config** is a simple, easy to use, yet powerful configuration management library for PHP. The design idea was inspired by another github project [mrjgreen/config](https://github.com/ecfectus/config) but some cool features added.

It requires PHP 5.4, supports PHP 7.0+ and HHVM. It is compliant with [PSR-1](http://www.php-fig.org/psr/psr-1/ "PSR-1: Basic Coding Standard"), [PSR-2](http://www.php-fig.org/psr/psr-2/ "PSR-2: Coding Style Guide"), [PSR-4](http://www.php-fig.org/psr/psr-4/ "PSR-4: Autoloader").

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

[](#installation)

Install via the `composer` utility.

```
composer require "phossa2/config=2.*"

```

or add the following lines to your `composer.json`

```
{
    "require": {
       "phossa2/config": "2.*"
    }
}
```

Features
--------

[](#features)

- Simple interface, `get($id, $default = null)` and `has($id)`.
- One central place for all config files for ease of management.

    ```
    config/
     |
     |___ production/
     |       |
     |       |___ host1/
     |       |      |___ db.php
     |       |      |___ redis.php
     |       |
     |       |___ db.php
     |
     |___ dev/
     |     |
     |     |___ redis.php
     |     |___ db.php
     |
     |___ db.php
     |___ redis.php
     |___ system.php

    ```
- Use an [environment](#env) value, such as `production` or `production/host1`for switching between different configurations.
- Use of [references](#ref) in configuration value is fully supported, such as `${system.tmpdir}`.
- On demand configuration loading (lazy loading).
- Hierachy configuration structure with dot notation like `db.auth.host`.
- [Array access](#array) for ease of use. e.g. `$config['db.user'] = 'www';`.
- Reference lookup [delegation](#delegate) and config chaining.
- Support `.php`, `.json`, `.ini`, `.xml` and `.serialized` type of config files.

Usage
-----

[](#usage)

- Use environment value

    Usually application running environment is different on different servers. A good practice is setting environment in a `.env` file somewhere on the host, and put all configuration files in one central `config/` directory.

    A sample `.env` file,

    ```
    # installation base
    BASE_DIR=/www

    # app directory
    APP_DIR=${BASE_DIR}/app

    # config directory
    CONFIG_DIR=${APP_DIR}/config

    # app env for current host
    APP_ENV=production/host1
    ```

    In a sample `bootstrap.php` file,

    ```
    use Phossa2\Config\Config;
    use Phossa2\Env\Environment;
    use Phossa2\Config\Loader\ConfigFileLoader;

    // load environment from '.env' file
    (new Environment())->load(__DIR__ . '/.env');

    // create config instance with the config file loader
    $config = new Config(
        new ConfigFileLoader(
            getenv('CONFIG_DIR'),
            getenv('APP_ENV')
        )
    );

    // object access of $config
    $db_config = $config->get('db');

    // array access of $config
    $config['db.user'] = 'www';
    ```
- Central config directory and configuration grouping

    - Configuration grouping

        Configurations are gathered into one directory and are grouped into files and subdirectories for ease of management.

        For example, the `config/system.php` holds `system.*` configurations

        ```
        // system.php
        return [
            'tmpdir' => '/usr/local/tmp',
            // ...
        ];
        ```

        Later, `system` related configs can be retrieved as

        ```
        // object acess of config
        $dir = $config->get('system.tmpdir');

        // array access of $config
        $dir = $config['system.tmpdir'];
        ```

        Or being used in other configs as [references](#ref).
    - Configuration files loading order

        If the environment is set to `production/host1`, the config files loading order are,

        1. `config/config/*.php`
        2. `config/production/*.php`
        3. `config/production/host1/*.php`

        Configuration values are overwritten and replaced those from later loaded files.
- Use of references

    References make your configuration easy to manage.

    For example, in the `system.php`

    ```
    // group: system
    return [
        'tmpdir' => '/var/local/tmp',
        ...
    ];
    ```

    In your `cache.php` file,

    ```
    // group: cache
    return [
        // a local filesystem cache driver
        'local' => [
            'driver' => 'filesystem',
            'params' => [
                'root_dir'   => '${system.tmpdir}/cache', // use reference here
                'hash_level' => 2
            ]
        ],
        ...
    ];
    ```

    You may reset the reference start and ending matching pattern as follows,

    ```
    // now reference is something like '%{system.tmpdir}%'
    $config->setReferencePattern('%{', '}%');
    ```
- ArrayAccess and DOT notation

    `Config` class implements `ArrayAccess` interface. So config values can be accessed just like an array.

    ```
    // test
    if (!isset($config['db.auth.user'])) {
        // set
        $config['db.auth.user'] = 'www';
    }
    ```

    Hierachy configuration structure with dot notation like `db.auth.host`.

    ```
    // returns the db config array
    $db_config = $config->get('db');

    // returns a string
    $db_host = $config->get('db.auth.host');
    ```

    Both flat notation and array notation are supported and can co-exist at the same time.

    ```
    // db config file
    return [
        // array notation
        'auth' => [
            'host' => 'localhost',
            'port' => 3306
        ],

        // flat notation
        'auth.user' => 'dbuser'
    ];
    ```
- Reference lookup delegation and config chaining

    - Config delegation

        Reference lookup delegation is similar to the delegation idea of [Interop Container Delegate Lookup](https://github.com/container-interop/fig-standards/blob/master/proposed/container.md)

        - Calls to the `get()` method should only return an entry if the entry is part of the config registry. If the entry is not part of the registry, a `NULL` will be returned as described in `ConfigInterface`.
        - Calls to the `has()` method should only return true if the entry is part of the config registry. If the entry is not part of the registry, false should be returned.
        - If the fetched entry has dependencies (references), **instead** of performing the reference lookup in this config registry, the lookup is performed on the delegator.
        - **Important** By default, the lookup *SHOULD* be performed on the delegator only, not on the config registry itself.

            ```
            $config1 = new Config();
            $config2 = new Config();
            $delegator = new Delegator();

            // add some values
            $config1['db.user'] = '${system.user}';
            $config2['system.user'] = 'root';

            // reference unresolved in $config1
            var_dump($config1['db.user'] === '${system.user}'); // true

            // add both configs to the delegator
            $delegator->addConfig($config1);
            $delegator->addConfig($config2);

            // reference resolved thru the delegator
            var_dump($config1['db.user'] === 'root'); // true
            ```

        `Delegator` class implements the `ConfigInterface` and `ArrayAccess`interfaces, thus can be used just like a normal config.

        ```
        $dbUser = $delegator['db.user'];
        ```
    - Config chaining

        Config chaining can be achieved via multiple-level delegations. For example,

        ```
        // configs
        $config1 = new Config();
        $config2 = new Config();

        // delegators
        $delegator1 = new Delegator();
        $delegator2 = new Delegator();

        // register $config1 with $delegator1
        $delegator1->addConfig($config1);

        // chaining
        $delegator2->addConfig($delegator1);
        $delegator2->addConfig($config2);

        // get from the chain
        $db = $delegator2->get('db');
        ```

    ```

    ```

APIs
----

[](#apis)

- `ConfigInterface` API

    - `get(string $id, $default = null): mixed`

        `$default` is used if no config value is found.

        The return value might be a `string`, `array` or even `object`.
    - `has(string $id): bool`

        Test if `$id` exists or not. Returns a `boolean` value.
- `WritableInterface` API

    - `set(string $id, mixed $value): bool`

        Set the configuration manually in this *session*. The value will **NOT**be reflected in any config files unless you modify config file manually.

        `$value` may be a `string`, `array` or `object`.

        This feature can be disabled by

        ```
        // disable writing to the $config
        $config->setWritable(false);
        ```
    - `setWritable(bool $writable): bool`

        Enable or disable the `set()` functionality. Returns `true` on success.
    - `isWritable(): bool`

        Test to see if current config writable or not.
- `ReferenceInterface` API

    - `setReferencePattern(string $start, string $end): $this`

        Reset the reference start chars and ending chars. The default are `'${'` and `'}'`
    - `hasReference(string $string): bool`

        Test to see if there are references in the `$string`
    - `deReference(string $string): mixed`

        Dereference all the references in the `$string`. The result might be `string`, `array` or even `object`.
    - `deReferenceArray(mixed &$data): $this`

        Recursively dereference everything in the `$data`. `$data` might be `string`or `array`. Other data type will be ignored and untouched.
- `DelegatorInterface` API

    - `addConfig(ConfigInterface $config): $this`

        Added one `Phossa2\Config\Interfaces\ConfigInterface` instance to the delegator.
- Others

    - `setErrorType(int $type): $this`

        Set either `Config::ERROR_IGNORE`, `Config::ERROR_WARNING` or `Config::ERROR_EXCEPTION` for the config.

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) from more information.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTE](CONTRIBUTE.md) for more information.

Dependencies
------------

[](#dependencies)

- PHP &gt;= 5.4.0
- phossa2/shared &gt;= 2.0.21

License
-------

[](#license)

[MIT License](http://mit-license.org/)

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 96.8% 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 ~1 days

Total

13

Last Release

3636d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/19922046?v=4)[Hong Zhang](/maintainers/phossa2)[@phossa2](https://github.com/phossa2)

---

Top Contributors

[![phossa](https://avatars.githubusercontent.com/u/8499165?v=4)](https://github.com/phossa "phossa (60 commits)")[![phossa2](https://avatars.githubusercontent.com/u/19922046?v=4)](https://github.com/phossa2 "phossa2 (2 commits)")

---

Tags

configurationconfigconfigurephossa2

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[symfony/options-resolver

Provides an improved replacement for the array\_replace PHP function

3.2k525.7M2.0k](/packages/symfony-options-resolver)[league/config

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

565335.0M36](/packages/league-config)[dflydev/dot-access-configuration

Given a deep data structure representing a configuration, access configuration by dot notation.

13414.5M4](/packages/dflydev-dot-access-configuration)[dmishh/settings-bundle

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

115257.8k1](/packages/dmishh-settings-bundle)[jbtronics/settings-bundle

A symfony bundle to easily create typesafe, user-configurable settings for symfony applications

9558.8k3](/packages/jbtronics-settings-bundle)[caseyamcl/configula

A simple, but versatile, PHP config loader

42150.0k6](/packages/caseyamcl-configula)

PHPackages © 2026

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