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

ActiveLibrary

weew/config
===========

Simple configuration loader.

v1.19.0(9y ago)05233MITPHP

Since Sep 22Pushed 9y ago1 watchersCompare

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

READMEChangelogDependencies (6)Versions (36)Used By (3)

Configuration made simple
=========================

[](#configuration-made-simple)

[![Build Status](https://camo.githubusercontent.com/67197c5305e95710099e93cd4dbd3b2d9e0b0d098cc9be45277ca4fb7136a212/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f776565772f636f6e6669672e737667)](https://travis-ci.org/weew/config)[![Code Quality](https://camo.githubusercontent.com/bf7220b484826b250466442c13765230d68bd05cfd93159833e82516dcda43cb/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f776565772f636f6e6669672e737667)](https://scrutinizer-ci.com/g/weew/config)[![Test Coverage](https://camo.githubusercontent.com/4032d1295eb9532a7a22caa56667edfc6317d487bd8d93c6b8678e7183ba6b73/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f776565772f636f6e6669672e737667)](https://coveralls.io/github/weew/config)[![Version](https://camo.githubusercontent.com/b5401834299469a7922ac3cab820f7f6b57180d32a62af35b9af0c1cd1fbe385/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f776565772f636f6e6669672e737667)](https://packagist.org/packages/weew/config)[![Licence](https://camo.githubusercontent.com/cab55b950cf5e5ec96c3f20d9e93505b8cb7eea41dee2844e1344ddcf73ea52b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f776565772f636f6e6669672e737667)](https://packagist.org/packages/weew/config)

Table of contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Loading configurations](#loading-configurations)
- [Accessing configurations](#accessing-configurations)
- [Configuration formats](#configuration-formats)
- [References](#references)
- [Runtime config](#runtime-config)
- [Environments](#environments)
    - [Setting an environment](#setting-an-environment)
    - [How it works](#how-it-works)
    - [Adding custom environments](#adding-custom-environments)
    - [Ignoring files](#ignoring-files)
- [Extending](#extending)
    - [Custom config drivers](#custom-config-drivers)
    - [Custom environment detector](#custom-environment-detector)

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

[](#installation)

`composer require weew/config`

Loading configurations
----------------------

[](#loading-configurations)

The config loader is responsible for loading of the configuration files. All you have to do is to provide a location(file or directory) where it can find your configs. It will scan the locations(s) for configuration files and return you a config object.

```
$loader = new ConfigLoader();
$loader->addPath('path/to/my/config');
$config = $loader->load();
```

Accessing configurations
------------------------

[](#accessing-configurations)

You can easily access config values by the config key.

```
// get config value
$config->get('key', 'defaultValue');

// set config value
$config->set('key', 'value');

// check if config is set
$config->has('key');

// remove config value
$config->remove('key');

// check if config is set, throws MissingConfigException
// optionally a type may be specified (string, int, array, etc..)
$config
    ->ensure('key', 'errorMessage')
    ->ensure('stringNode', 'errorMessage', 'string')
    ->ensure('arrayNode', 'errorMessage', 'array');
```

Configuration formats
---------------------

[](#configuration-formats)

Following formats are supported out of the box.

Plain PHP format example:

```
return [
    'key' => 'value',
    'list' => [
        'key' => 'value',
    ],
];
```

INI format example:

```
key = value

[list]
key = value
```

YAML format example:

```
key: 'value'
list:
    key: value
```

Json format example:

```
{
    "key": "value",
    "list": {
        "key": "value",
    }
}
```

References
----------

[](#references)

You can always reference to other config values from within a config file. To create a reference, simple wrap a config key with curly braces {config.key}`.

```
// config1
return [
    'list' => [
        'foo' => 'bar'
    ]
];

// config2
return [
    'reference' => 'foo {list.foo}'
];

// returns 'foo bar'
$config->get('reference');
```

You can even reference whole config blocks.

```
// config1
return [
    'list' => [
        'foo' => 'bar'
    ]
];

// config2
return [
    'reference' => '{list}'
];

// returns ['foo' => 'bar']
$config->get('reference');
```

Now when you access the `reference` value you will get "bar" in return. Keep in mind that references are interpolated at access time (when you call $config-&gt;get()). This means that if you change a config value, everyone who references it will receive it's updated value and not the old one.

Runtime config
--------------

[](#runtime-config)

Sometimes you might want to apply runtime config from an array or similar that also has a higher priority as the config loaded from the filesystem.

```
$loader->addRuntimeConfig(['my' => 'config']);

// or

$loader->addRunetimeConfig(new Config(['my' => 'config']));
```

Environments
------------

[](#environments)

Often you want to split your configurations in multiple files or directories and load them depending on your current environment. This can be achieved trough the environment settings.

### Setting an environment

[](#setting-an-environment)

Out of the box it comes with support for dev, test and prod environments. Custom environments can be added on the fly.

```
$loader->setEnviroonment('prod');
```

### How it works

[](#how-it-works)

To understand how environments detection works, lets take a look at this directory structure:

```
- test
    - db.php
- prod
    - db.php
- config.php
- config_test.php
- config_prod.php

```

In the test environment only the "test" directory and it's contents, "config\_test.php" and "config.php" will be loaded. In the prod environment however, it will load only the "prod" directory, "config\_prod.php" and "config.php".

Files and folders that have been added to the config loader will be loaded in the order of registration. Inside directories, files are loaded alphabetically.

### Adding custom environments

[](#adding-custom-environments)

To create your own environments you'll have to register a new rule on the environment detector. The first argument is the name of the environment and the second is an array of masks.

```
$loader->getEnvironmentDetector()
    ->addEnvironmentRule('integ', ['integ', 'integration', 'stage']);
```

Below is a list of some files and directories that would match the integration environment:

```
- stage
- _stage
- _stage_
- foo_stage
- _stage.txt
- foo_stage.txt

```

This files will not match:

```
- stagefoo
- foostage
- foo_stage_bar
- _stagebar

```

As delimiter you can use any of this characters: `._+:-`.

### Ignoring files

[](#ignoring-files)

This files are ignored by default:

```
- dist
- _dist
- _dist_
- foo_dist
- _dist.txt
- foo_dist.txt

- ignore
- _ignore
- _ignore_
- foo_ignore
- _ignore.txt
- foo_ignore.txt

```

You may specify custom rules to ignore certain files:

```
$loader->getEnvironmentDetector()
    ->addIgnoreRule('sample', ['dist', 'ignore', 'sample']);
```

Extending
---------

[](#extending)

Config loader provides you multiple extension points to alter its behaviour and functionality.

### Custom config drivers

[](#custom-config-drivers)

Adding your own drivers is very easy. All you have to do is to implement the IConfigDriver interface and pass an instance of the driver to the config loader. You can have multiple active drivers at the same time.

```
class MyDriver implements IConfigDriver {}

$loader->addDriver(new MyDriver());
```

### Custom environment detector

[](#custom-environment-detector)

You can replace the default environment detector with your own. Just create a new detector which implements the IEnvironmentDetector interface and pass it to the config loader. Also take a look on how to [create your own environments](#adding-custom-environments).

```
class MyDetector implements IEnvironmentDetector {}

$loader->setEnvironmentDetector(new MyDetector());
```

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity75

Established project with proven stability

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

Recently: every ~41 days

Total

35

Last Release

3477d ago

Major Versions

v0.0.9 → v1.0.02015-11-16

### Community

Maintainers

![](https://www.gravatar.com/avatar/10b2b854b5829dd13a15967c000ed2119b5faef67aca24d94c653c8ac550d85e?d=identicon)[weew](/maintainers/weew)

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[getkirby/cms

The Kirby core

1.5k535.5k352](/packages/getkirby-cms)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)[neos/flow

Flow Application Framework

862.0M451](/packages/neos-flow)

PHPackages © 2026

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