PHPackages                             northwoods/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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. northwoods/config

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

northwoods/config
=================

Simple configuration loader

2.0.0(8y ago)1616.1kMITPHPPHP &gt;=7.0

Since Dec 26Pushed 7y ago2 watchersCompare

[ Source](https://github.com/northwoods/config)[ Packagist](https://packagist.org/packages/northwoods/config)[ Docs](https://github.com/northwoods/config)[ RSS](/packages/northwoods-config/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (3)Versions (21)Used By (0)

Northwoods Config
=================

[](#northwoods-config)

[![Build Status](https://camo.githubusercontent.com/a650ee67070256ec8e4a374db5491283c28846224a249e423353a61f399a9926/68747470733a2f2f7472617669732d63692e6f72672f6e6f727468776f6f64732f636f6e6669672e7376673f6272616e63683d646576656c6f70)](https://travis-ci.org/northwoods/config)[![StyleCI](https://camo.githubusercontent.com/ccd7fbb8b3db290863973b13939025a9d45e39ff858584576df16b477d5ea232/68747470733a2f2f7374796c6563692e696f2f7265706f732f39363537353730322f736869656c64)](https://styleci.io/repos/96575702)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/b91ee3fa507cb13d807b68d1b7009987c3341b6bbbbf691a95a15c7f55bcaebd/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e6f727468776f6f64732f636f6e6669672f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/northwoods/config/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/70b2d1e34723ba07e3138c6833a14a46c29300874d8e147a7a05be651b0d28e0/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6e6f727468776f6f64732f636f6e6669672f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/northwoods/config/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/454f47777f78c0aa5e2dce5f8092f27fc996a8ec84d27b4213746a17d2451fe4/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e6f727468776f6f64732f636f6e6669672e7376673f7374796c653d666c6174)](https://packagist.org/packages/northwoods/config)[![Total Downloads](https://camo.githubusercontent.com/1235e97d3eb46cedc8a0e57d9f637c88187007fcd83370990ba48dba9b2c6348/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e6f727468776f6f64732f636f6e6669672e7376673f7374796c653d666c6174)](https://packagist.org/packages/northwoods/config)[![License](https://camo.githubusercontent.com/2230190c8c8ea9f2bb9920fae05799500d402cf3327b5b520c154264c1745c5e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6e6f727468776f6f64732f636f6e6669672e7376673f7374796c653d666c6174)](https://packagist.org/packages/northwoods/config)[![SensioLabsInsight](https://camo.githubusercontent.com/7324d2d249d30bea367a2fdd620cbced5d6a82a58c7497f8cdbb586ed67d70f5/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f64613863313163392d363831352d346234662d613963342d3938393763383663626334362f6d696e692e706e67)](https://insight.sensiolabs.com/projects/da8c11c9-6815-4b4f-a9c4-9897c86cbc46)

PHP configuration loading library. It is made to enable your application to have different configurations depending on the environment it is running in. For example, your application can have different configurations for testing, development, staging, and production.

It is **not recommended** to include your staging or production configuration in version control! To support system specific configuration, you may install [`josegonzalez/dotenv`](https://github.com/josegonzalez/php-dotenv).

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

[](#installation)

The best way to install and use this package is [through composer](http://getcomposer.org/):

```
composer require northwoods/config
```

Usage
-----

[](#usage)

There are several different ways to use this package. The most simple is to use the static factory:

```
use Northwoods\Config\ConfigFactory;

$config = ConfigFactory::make([
    'directory' => __DIR__ . '/config',
]);
```

Configuration can now be read using a "dot path":

```
$token = $config->get('app.timezone');
```

This will load `config/app.php` and return the `timezone` key, if it exists.

Optionally, an environment can be set that will add an additional search path:

```
$config = ConfigFactory::make([
    'directory' => __DIR__ . '/config',
    'environment' => 'dev',
]);
```

Now when `app.timezone` is requested, both `config/dev/app.php` and `config/app.php`will be searched for the `timezone` key and the first result will be returned.

### Best Practice

[](#best-practice)

It is **not recommended** to add your staging or production secrets to configuration files that are checked into source control. A better solution is to use an env loader such as [`josegonzalez/dotenv`](https://github.com/josegonzalez/php-dotenv) or [`vlucas/phpdotenv`](https://github.com/vlucas/phpdotenv). This will allow writing PHP configuration files that read from `getenv`:

```
return [
    'database' => [
        'password' => getenv('DATABASE_PASSWORD')
    ],
];
```

Refer the package documentation for how to populate env values from a `.env` file.

### YAML Files

[](#yaml-files)

YAML configuration files are supported when the [`symfony/yaml`](https://github.com/symfony/yaml)package is installed:

```
$config = ConfigFactory::make([
    'directory' => __DIR__ . '/config',
    'environment' => 'dev',
    'type' => 'yaml'
]);
```

**Note:** This assumes that all configuration files have a `.yaml` extension! If you wish to combine PHP and YAML files, create a custom `ConfigCollection`with `ConfigFactory`.

### Decorators

[](#decorators)

It is also possible to replace variables in configuration by using the `VariableDecorator`. This allows you to define variables at runtime without changing configuration:

```
use Northwoods\Config\Decorator\VariableDecorator;

// Wrap any existing configuration with the decorator
$config = new VariableDecorator($config);
$config->setVariables(['%cacheDir%' => '/tmp']);
```

Now any configuration value that contains `%cacheDir%` will have it replaced with `/tmp`:

```
return [
    'emails' => '%cacheDir%/emails',
];
```

Would resolve to `/tmp/emails` when decorated.

`ConfigInterface`
-----------------

[](#configinterface)

All configuration containers must implement `ConfigInterface`.

### `get()`

[](#get)

Configuration values are accessed using the `get($path, $default)` method.

The first parameter is a "dot path" to search for in the form `file.key.extra`. An unlimited depth is supported.

The second parameter is a default value that will be returned if the path cannot be resolved. If the default is not provided `null` will be used.

```
// If not defined, $timezone will be null
$timezone = $config->get('app.timezone');

// If not defined, $timezone will be "UTC"
$timezone = $config->get('app.timezone', 'UTC');
```

### `set()`

[](#set)

Configuration values can also be set at runtime using the `set($path, $value)` method.

The first parameter is a "dot path" to set in the form `file.key.extra`. An unlimited depth is supported.

The second parameter is the value to set for the path.

```
$config->set('app.timezone', 'Europe/Berlin');
```

### Classes

[](#classes)

The following classes are part of this package:

- `ConfigFactory` - factory for configuration containers
- `ConfigDirectory` - container that reads a single directory
- `ConfigCollection` - container that reads from an collection of containers
- `Decorator\VariableDecorator` - decorator to support variable replacement in configuration values
- `Loader\LoaderFactory` - factory for configuration readers
- `Loader\PhpLoader` - reader for `.php` configuration files
- `Loader\YamlLoader` - reader for `.yaml` configuration files

### Functions

[](#functions)

Getting and setting functionality is implemented by `array_path` and `array_path_set`:

```
use function Northwoods\Config\array_path;
use function Northwoods\Config\array_path_set;

$config = [
    'service' => [
        'uri' => 'http://api.example.com/'
    ],
];

// get a value from an array
$uri = array_path($config, 'service.uri');

// set a value in an array
$config = array_path_set($config, 'service.uri', 'https://api.example.com/v2/')
```

Examples
--------

[](#examples)

See more examples in the [examples folder](https://github.com/northwoods/config/tree/master/examples).

### PHP Configuration File

[](#php-configuration-file)

Example of a PHP configuration file:

```
return [
    'timezone' => "America/New_York"
];
```

### YAML Configuration File

[](#yaml-configuration-file)

Example of a YAML configuration file:

```
timezone: America/New_York
```

Original Ownership
------------------

[](#original-ownership)

This library is a fork of [`sinergi/config`](https://github.com/sinergi/config), starting in July 2017, and has changed significantly. Thank you to Gabriel Bull for creating the original package!

License
-------

[](#license)

Config is licensed under The MIT License (MIT).

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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

Recently: every ~156 days

Total

20

Last Release

3074d ago

Major Versions

0.6.4 → 1.0.02017-07-13

1.1.0 → 2.0.02018-02-01

PHP version history (5 changes)0.1.0PHP &gt;=5.4.0

0.5.0PHP &gt;=5.4

0.5.1PHP &gt;=5.3

0.6.0PHP &gt;=5.6

2.0.0PHP &gt;=7.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/38203?v=4)[Woody Gilk](/maintainers/shadowhand)[@shadowhand](https://github.com/shadowhand)

---

Top Contributors

[![gabrielbull](https://avatars.githubusercontent.com/u/671923?v=4)](https://github.com/gabrielbull "gabrielbull (42 commits)")[![shadowhand](https://avatars.githubusercontent.com/u/38203?v=4)](https://github.com/shadowhand "shadowhand (35 commits)")[![white-poto](https://avatars.githubusercontent.com/u/4362540?v=4)](https://github.com/white-poto "white-poto (12 commits)")[![aak74](https://avatars.githubusercontent.com/u/3227024?v=4)](https://github.com/aak74 "aak74 (2 commits)")[![kegi](https://avatars.githubusercontent.com/u/6678421?v=4)](https://github.com/kegi "kegi (1 commits)")[![Nyholm](https://avatars.githubusercontent.com/u/1275206?v=4)](https://github.com/Nyholm "Nyholm (1 commits)")

---

Tags

configurationloaderphpyamlphpconfigurationconfigyamldirectorymanagementloading

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[hassankhan/config

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

1.0k13.8M185](/packages/hassankhan-config)[m1/vars

Vars is a simple to use and easily extendable configuration loader with in built loaders for ini, json, PHP, toml, XML and yaml/yml file types. It also comes with in built support for Silex and more frameworks to come soon.

69124.3k1](/packages/m1-vars)[romanpitak/nginx-config-processor

Nginx configuration files processor.

6935.9k1](/packages/romanpitak-nginx-config-processor)[thewunder/conphigure

Framework Agnostic Configuration Library

3120.6k](/packages/thewunder-conphigure)

PHPackages © 2026

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