PHPackages                             chonla/cfg - 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. chonla/cfg

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

chonla/cfg
==========

Configuration Loader/Dumper

0.1.3(11y ago)027MITPHPPHP &gt;=5.4

Since Feb 5Pushed 11y ago1 watchersCompare

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

READMEChangelogDependencies (2)Versions (4)Used By (0)

Config Loader/Dumper
====================

[](#config-loaderdumper)

Config Loader/Dumper is an extension to [Noodlehaus/Config package](https://packagist.org/packages/noodlehaus/config).

Supported configuration loader
------------------------------

[](#supported-configuration-loader)

PHP, INI, XML, JSON, and YAML

Supported configuration dumper
------------------------------

[](#supported-configuration-dumper)

JSON and YAML

API
---

[](#api)

Like Noodlehause/Config, `Config` object can be statically created or instantiated from `Config`:

```
$conf = Config::load('config.json');
$conf = new Config('config.json');
```

Use `get()` to retrieve values:

```
// Get value using key
$debug  = $config->get('debug');

// Get value using nested key
$secret = $config->get('security.secret');

// Get a value with a fallback
$ttl    = $config->get('app.timeout', 3000);
```

Use `set()` to set values (doh!):

```
$conf = Config::load('config.json');
$conf->set('app.timeout', 1000);
```

Use `save()` to export settings to file:

```
$conf = Config::load('config.yaml');
$conf->set('app.timeout', 1000);
$conf->save('new-config.yaml');
```

Examples (from Noodlehaus/Config)
---------------------------------

[](#examples-from-noodlehausconfig)

Here's an example JSON file that we'll call `config.json`.

```
{
    "app": {
        "host": "localhost",
        "port": 80,
        "base": "/my/app"
    },
    "security": {
        "secret": "s3cr3t-c0d3"
    },
    "debug": false
}
```

Here's the same config file in PHP format:

```
