PHPackages                             radiergummi/libconfig - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. radiergummi/libconfig

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

radiergummi/libconfig
=====================

Configuration object creation for PHP apps

v1.0(10y ago)021[2 issues](https://github.com/Radiergummi/libconfig/issues)MITPHPPHP &gt;=5.3.0

Since Jun 4Pushed 10y ago1 watchersCompare

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

READMEChangelog (2)DependenciesVersions (2)Used By (0)

libconfig [![Build Status](https://camo.githubusercontent.com/60795d0e4f9667499d5cd222829da977288284f9d8f0a0409161a2467a557091/68747470733a2f2f7472617669732d63692e6f72672f52616469657267756d6d692f6c6962636f6e6669672e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Radiergummi/libconfig) [![volkswagen status](https://camo.githubusercontent.com/36b9ff1274473c66626de3d5be56f1565ea9286fe7c9f5151e39d1bfcd3d3321/68747470733a2f2f61756368656e626572672e6769746875622e696f2f766f6c6b73776167656e2f766f6c6b7377617267656e5f63692e7376673f763d31)](https://github.com/auchenberg/volkswagen) [![Documentation](https://camo.githubusercontent.com/bb9f27645c07815099a658f3309425c499c778c1177514dfe8dbdfed4c1d22db/68747470733a2f2f72656164746865646f63732e6f72672f70726f6a656374732f6c6962636f6e6669672f62616467652f3f76657273696f6e3d6c6174657374)](http://libconfig.docs.9dev.de) [![Join the chat at https://gitter.im/Radiergummi/libconfig](https://camo.githubusercontent.com/abe08b740a4156153736f791393ec4da6619c4be73212e75769f52edacc0e2b5/68747470733a2f2f6261646765732e6769747465722e696d2f4a6f696e253230436861742e737667)](https://gitter.im/Radiergummi/libconfig?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#libconfig----)

Simple php class to create a key-value storage. Basically, you can just throw your configuration at it, be it arrays, json, files or even directories, and libconfig will make it accessible in an intuitive way. You can `get`, `set` and `add` it, count it, iterate over it or access it as an array. Each method has its tricks up its sleeve. More on that below.

> Note: I also made a singleton version of this which is available [here](/../../tree/singleton).
> Why? Because using stuff like `Config::get('key')` from anywhere without an instance is pretty darn comfortable.

Installation
============

[](#installation)

\###Installation via Composer (Packagist):

1. Include the following in your *composer.json* file:

    ```
     "require": {
         ...
         "radiergummi\libconfig": "~1.0"
     }

    ```
2. Then, run `php composer.phar install`

\###Installation via source:

1. Download from [Github](http://github.com/Radiergummi/libconfig, "Github Page for libconfig")
2. Drop the *src/libconfig* folder into your codebase at `vendor/Radiergummi` (you don't need the parent folders)
3. Use a [PSR-4 Autoloader](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4.md, "PSR-4 Standards Explanation") to include it!

Usage
=====

[](#usage)

Creating a Config object
------------------------

[](#creating-a-config-object)

Create a config object like this:

```
  $config = new Config($data);
```

where `$data` can be an array or a json string, a file or folder path.

Creating a Config object with a file as a parameter
---------------------------------------------------

[](#creating-a-config-object-with-a-file-as-a-parameter)

To directly include a json file, use

```
$config = new Config(PATH . 'example.json');
```

The only requirement is the complete path to be valid.

I often use php files like the one below to store configuration. So you could also use

```
$config = new Config(PATH . 'example.php');
```

PHP Config file:

```
