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

ActiveLibrary

phoole/config
=============

A slim configuration loader library for PHP.

1.1.0(6y ago)4134↓100%Apache-2.0PHPPHP &gt;=7.2.0

Since Oct 7Pushed 6y ago2 watchersCompare

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

READMEChangelog (10)Dependencies (2)Versions (15)Used By (0)

config
======

[](#config)

[![Build Status](https://camo.githubusercontent.com/0663d1e9a1dd5d88f2512f1dc97ad6b00872293f50298775017b236b008e5644/68747470733a2f2f7472617669732d63692e636f6d2f70686f6f6c652f636f6e6669672e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/phoole/config)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/183e1d8d5694ee2b0990671347f217738d73731717ce654938c3d523a96b138d/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f70686f6f6c652f636f6e6669672f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/phoole/config/?branch=master)[![Code Climate](https://camo.githubusercontent.com/0351429ef9156492ffd2d33233a1d75ee847c6a3f46510a08553031b99ebab6b/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f70686f6f6c652f636f6e6669672f6261646765732f6770612e737667)](https://codeclimate.com/github/phoole/config)[![PHP 7](https://camo.githubusercontent.com/abeaa862d7a93e94c5e714c6b2eb65885578527f1f7e42173ed6e90d99024aef/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f70686f6f6c652f636f6e666967)](https://packagist.org/packages/phoole/config)[![Latest Stable Version](https://camo.githubusercontent.com/5fe7d61b12be3d48a26bcd82b983693f5e344fa7627d242c9de130e1503e97f4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f70686f6f6c652f636f6e666967)](https://packagist.org/packages/phoole/config)![License](https://camo.githubusercontent.com/b9ba5b5b1b0a2c48db9ee39e33610907b318f9de17b184173e46f153e8bad636/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f70686f6f6c652f636f6e666967)

A slim configuration loader library for PHP. It loads PHP, JSON, YAML config files, easy to use, yet powerful. It requires PHP 7.2+ and is compliant with [PSR-1](http://www.php-fig.org/psr/psr-1/ "PSR-1: Basic Coding Standard"), [PSR-4](http://www.php-fig.org/psr/psr-4/ "PSR-4: Autoloader"), [PSR-12](http://www.php-fig.org/psr/psr-2/ "PSR-12: Extended Coding Style Guide").

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

[](#installation)

Install via the `composer` utility.

```
composer require "phoole/config=1.*"

```

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

```
{
    "require": {
       "phoole/config": "1.*"
    }
}
```

Features
--------

[](#features)

- Simple interface, `get($id)`, `has($id)`, `with($id, $value)`.
- 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

    ```
- May 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}`.
- Get environment values using `$config->get('ENV.USER')` or `${ENV.USER}`
- Hierarchy configuration structure with [dot notation](#dot) like `db.auth.host`.
- Support `.php`, `.json`, `.yml`(need yaml extension installed) 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 Phoole\Config\Config;
    use Phoole\Env\Environment;

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

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

    // object access of $config
    $db_config = $config->get('db');
    ```
- 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

        ```
        $dir = $config->get('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 (assume config files are `*.php`),

        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`

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

    In your `cache.php` file,

    ```
    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('%{', '}%');
    ```
- Access environment values

    Environment values can be accessed through special node `'ENV'`. e.g.

    ```
    $tmpdir = $config->get('ENV.APP_TMPDIR');
    ```

    or in reference format,

    ```
    return [
        'tmpdir' => '${ENV.APP_TMPDIR}'
    ];
    ```
- DOT notation

    Hierarchy 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'
    ];
    ```
- After initial loading, `$config` is immutable. If you want to add new conf values. You may use,

    ```
    $newconf = $config->with('redis', ['host' => 'localhost']);
    ```

    where `$newconf` is a new configuration object.

APIs
----

[](#apis)

- `ConfigInterface` API

    - `get(string $id): mixed`

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

        Test if `$id` exists or not. Returns a `boolean` value.
    - `with(string $id, mixed $value): Config`

        Returns a new config object with `$id` set.
- `ReferenceInterface` API

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

        Reset the reference start chars and ending chars. The default are `'${'` and `'}'`

Testing
-------

[](#testing)

```
$ composer test
```

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

[](#dependencies)

- PHP &gt;= 7.2.0

License
-------

[](#license)

- [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 82.6% 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

14

Last Release

2364d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3bae7d5f135e90fd05271574bfd04d4844169bd4c554eaa9e103e4af69267ffc?d=identicon)[phoole](/maintainers/phoole)

---

Top Contributors

[![phossa](https://avatars.githubusercontent.com/u/8499165?v=4)](https://github.com/phossa "phossa (19 commits)")[![phoole](https://avatars.githubusercontent.com/u/55728163?v=4)](https://github.com/phoole "phoole (3 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (1 commits)")

---

Tags

configconfigurationphoolephpswoolephpconfiglibraryphoole

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[phppkg/config

Config manage, load, get. Supports INI,JSON,YAML,NEON,PHP format file

133.5k](/packages/phppkg-config)

PHPackages © 2026

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