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

ActiveLibrary

werx/config
===========

Use environment-specific configuration files in your app.

1.3(10y ago)527.1k↓100%5[1 issues](https://github.com/werx/config/issues)1MITPHPPHP &gt;= 5.4

Since Jul 11Pushed 10y ago1 watchersCompare

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

READMEChangelogDependencies (2)Versions (10)Used By (1)

werx\\config
============

[](#werxconfig)

[![Build Status](https://camo.githubusercontent.com/33a43eeba89d7dc7cce33097a37c53f519b74ef5e0a4a508e75121077ac25314/68747470733a2f2f7472617669732d63692e6f72672f776572782f636f6e6669672e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/werx/config) [![Total Downloads](https://camo.githubusercontent.com/1df626b978c444561edaa09ed16d58586c779af695440ff0c67d5853224d2f77/68747470733a2f2f706f7365722e707567782e6f72672f776572782f636f6e6669672f646f776e6c6f6164732e706e67)](https://packagist.org/packages/werx/config) [![Latest Stable Version](https://camo.githubusercontent.com/3a4148f959d3e7fe2e67e71a7d86271a21352d1737cb0759a29acf3b8cdac982/68747470733a2f2f706f7365722e707567782e6f72672f776572782f636f6e6669672f762f737461626c652e706e67)](https://packagist.org/packages/werx/config)

Use environment-specific configuration files in your app.

Features:

- Multiple Environment Support (example: local/test/prod)
- Extensible Configuration Providers
    - Includes an ArrayProvider and JsonProvider out of the box
    - Create your own providers by implementing `\werx\config\Providers\ProviderInterface`
- Load multiple config files with a single call

Basic Usage
-----------

[](#basic-usage)

```
# Get an instance of the ArrayProvider
$provider = new \werx\Config\Providers\ArrayProvider('/path/to/config/directory');

# Create a Config\Container Instance from this provider.
$config = new \werx\Config\Container($provider);

# Load config/config.php
$config->load('config');

# Get an item.
$item = $config->get('foo');
```

### Recommended Directory Structure

[](#recommended-directory-structure)

For the default config providers, you'll need to create a directory structure somewhere in your project to hold your configuration files.

Recommended structure:

```
config/
    config.php
    another_config.php
    /local/
        config.php
    /test/
        config.php
    /prod/
        config.php

```

Default configs go in the root `config` directory. There must also sub-directories for each environment (local/test/prod) if you want to override the default setting when running in different environments.

### Using ArrayProvider

[](#using-arrayprovider)

Create a .php file in your config directory that returns an array of config values.

```
