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

ActiveLibrary

phossa/phossa-config
====================

Configuration management libraray for PHP

1.0.7(9y ago)11241MITPHPPHP &gt;=5.4.0CI failing

Since Apr 25Pushed 6y ago1 watchersCompare

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

READMEChangelog (8)Dependencies (2)Versions (9)Used By (1)

phossa-config \[ABANDONED\]
===========================

[](#phossa-config-abandoned)

[![Build Status](https://camo.githubusercontent.com/ae299fb5e1d1c833eed86c9a854bda6ba226ce3f6bb4fda15658547d579bc737/68747470733a2f2f7472617669732d63692e6f72672f70686f7373612f70686f7373612d636f6e6669672e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/phossa/phossa-config)[![Latest Stable Version](https://camo.githubusercontent.com/72d835d08191d7407bafbdf5e470c00fdaa7938888d7c3d8fb343428bef0ba96/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f767072652f70686f7373612f70686f7373612d636f6e6669672e7376673f7374796c653d666c6174)](https://packagist.org/packages/phossa/phossa-config)[![License](https://camo.githubusercontent.com/2a19b238b698334a7a69fd0cc42895d8cf54f5de0d8e606abfc786020259a89c/68747470733a2f2f706f7365722e707567782e6f72672f70686f7373612f70686f7373612d636f6e6669672f6c6963656e7365)](http://mit-license.org/)

**See new lib at [phoole/config](https://github.com/phoole/config)**

Introduction
------------

[](#introduction)

*phossa-config* is a configuration management library for PHP. The design idea is inspired by another github project `mrjgreen/config` but with lots of cool features.

It requires PHP 5.4 and supports PHP 7.0+, 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").

Features
--------

[](#features)

- One central place for all config files

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

    ```
- Use an [environment](#env) value, e.g. `production` or `production/host1` for switching between `development`, `staging` or `production`.
- Support `.php`, `.json`, `.ini` and `.xml` type of configuration files.
- [Reference](#ref) is possible, such as `${system.tmpdir}` in configuration file and environment file.
- On demand configuration loading (lazy loading).
- Able to load all configuration files in one shot with `$config->get(null)`
- Configuration [cache](#cache).
- Hierachy configuration structure with dot notation like `db.auth.host`.

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

    // returns a string
    $db_host = $config->get('db.auth.host');
    ```
- Both flat notation and array notation fully supported and co-exist at the same time.

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

        // flat notation
        'auth.user' => 'dbuser'
    ];
    ```
- Un\*x shell style environment file '.env' is supported with dereferencing feature and magic environment values like `${__DIR__}` and `${__FILE__}`

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

[](#installation)

Install via the [`composer`](https://getcomposer.org/) utility.

```
composer require "phossa/phossa-config=1.*"

```

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

```
{
    "require": {
      "phossa/phossa-config": "1.*"
    }
}
```

Usage
-----

[](#usage)

- Running Environment

    Usually running environment is different for different servers. A good practice is setting environment in a `.env` file in the installation root and put all configuration files in the `config/` directory.

    Sample `.env` file,

    ```
    # debugging true|false, change to 'false' ON production server
    APP_DEBUG=true

    # App environment, change to 'prod' ON production server
    APP_ENV=dev

    # app root directory, default to current dir
    APP_ROOT=${__DIR__}

    # central configuration directory
    CONFIG_DIR=${APP_ROOT}/config
    ```

    In the `bootstrap.php` file,

    ```
    // load environment
    (new Phossa\Config\Env\Environment())->load(__DIR__.'/.env');

    // create config object
    $config = new Phossa\Config\Config(
        getenv('CONFIG_DIR'), // loaded from .env file
        getenv('APP_ENV')     // loaded from .env file
    );

    // load all configs in one shot
    $conf_data = $config->get(null);
    ```
- Grouping

    Configurations are grouped into groups, namely files. For example, the `system.php` holds all `system.*` configurations

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

    Later, system related configs can be retrieved as

    ```
    $dir = $config->get('system.tmpdir');
    ```

    Or being used in other configs as [reference](#ref).
- Caching

    A cache pool can be passed to the config constructor to have it read all configs from the cache or save all configs to cache.

    ```
    // create config object
    $config = new Phossa\Config\Config(
        dirname(__DIR__) . '/config',     // the config dir
        'staging/server2',                // config env
        'php',                            // file type
        new Phossa\Config\Cache\Cache(__DIR__ . '/cache') // cache location
    );

    // if cache exists, this will read all configs from the cache
    $conf_data = $config->get(null);

    // ...

    // write to cache
    $config->save();
    ```

    - Pros of using caching

        - Speed up. Read from one file instead of lots of configuration files.
        - [References](#ref) like `${system.tmpdir}` are done already.
    - Cons of using caching

        - Config data might be stale. need to using `$config->save()` to overwrite or `$cache->clear()` to clear the cache.
        - Need write permission to a cache directory.
        - Might expose your configuration if you are not careful with cache data.
- Reference

    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',
                'hash_level' => 2
            ]
        ],
        ...
    ];
    ```

    You may reset the reference start and ending chars,

    ```
    // now reference is something like '%system.tmpdir%'
    $config = (new Config())->setReferencePattern('%', '%');
    ```

    Or even disable the reference feature,

    ```
    // now reference is not recognised
    $config = (new Config())->setReferencePattern('', '');
    ```
- Overwriting

    If the environment is set to `production/host1`, the precedence order is,

    - `config/production/host1/db.php` over
    - `config/production/db.php` over
    - `config/config/db.php`
- Config API

    - `get($key, $default = null)`

        `$key` is the a flat notation like `db.auth.host` or `NULL` to get all of the configurations. `$default` is used if no configs found.

        Return value might be a `string` or `array` base on the `$key`.
    - `set($key, $value)`

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

        `$value` can be a `string` or `array`.
    - `has($key)`

        Test if `$key` exists or not. Returns a `boolean` value.
    - `save()`

        Save current full configurations into a cache.

Changes
-------

[](#changes)

- 1.0.6 added `setReferencePattern()`, `hasReference()` and `deReference()`

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

[](#dependencies)

- PHP &gt;= 5.4.0
- phossa/phossa-shared ~1.0.10

License
-------

[](#license)

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

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

Established project with proven stability

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

Recently: every ~1 days

Total

8

Last Release

3621d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

configurationconfigconfigurephossa

###  Code Quality

TestsPHPUnit

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/phossa-phossa-config/health.svg)](https://phpackages.com/packages/phossa-phossa-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)[hassankhan/config

Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files

97513.5M169](/packages/hassankhan-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.

115254.9k1](/packages/dmishh-settings-bundle)[sandrokeil/interop-config

Provides interfaces and a concrete implementation to create instances depending on configuration via factory classes and ensures a valid config structure. It can also be used to auto discover factories and to create configuration files.

58446.7k34](/packages/sandrokeil-interop-config)

PHPackages © 2026

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