PHPackages                             sheikhheera/iconfig - 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. sheikhheera/iconfig

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

sheikhheera/iconfig
===================

A very simple, smart, light-weight and dynamic configuration manager for PHP.

1.0.0(10y ago)1540.8k↓85%5MITPHPPHP &gt;=5.3.0

Since Sep 10Pushed 9y ago1 watchersCompare

[ Source](https://github.com/heera/iconfig)[ Packagist](https://packagist.org/packages/sheikhheera/iconfig)[ Docs](https://github.com/heera/Iconfig)[ RSS](/packages/sheikhheera-iconfig/feed)WikiDiscussions master Synced 2w ago

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

Iconfig [![Build Status](https://camo.githubusercontent.com/a76b2e2e9f041ca672169a4c831236ddc1c596265ff1c6ffe5bd55bbbc99b98f/68747470733a2f2f7472617669732d63692e6f72672f68656572612f69636f6e6669672e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/heera/iconfig) [![Latest Stable Version](https://camo.githubusercontent.com/35a7b2ad9640847e52fbed66c4e2afd8b12965c8606c225f0447cafc61208421/68747470733a2f2f706f7365722e707567782e6f72672f736865696b6868656572612f69636f6e6669672f76657273696f6e)](https://packagist.org/packages/sheikhheera/iconfig) [![Total Downloads](https://camo.githubusercontent.com/d37c3cf8d2d816afe3e42bfd6917ca95d032a6ce6411bd337f885167bab9e410/68747470733a2f2f706f7365722e707567782e6f72672f736865696b6868656572612f69636f6e6669672f646f776e6c6f616473)](https://packagist.org/packages/sheikhheera/iconfig) [![GitHub license](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](https://github.com/heera/iconfig/blob/master/license.txt)
====================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#iconfig----)

A very simple, smart, light-weight and dynamic configuration manager for `PHP`.

Iconfig (Instant Config) could be used as a stand alone component to manage the configuration of any php application. It can load settings saved in a php file and build an array which would be available at run time. It provides useful methods to set or retrieve any configuration at the run time of an application.

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

[](#installation)

Iconfig uses [Composer](http://getcomposer.org/) to make things easy.

Learn to use composer and add this to require (in your composer.json):

```
"sheikhheera/iconfig": "1.0.0"

```

And run:

```
composer update

```

Library on [Packagist](https://packagist.org/packages/sheikhheera/iconfig).

How It Works ?
--------------

[](#how-it-works-)

Basically, php applications or `mvc` frameworks use array for configurations, for example, this is a sample of database configuration

```
return array(
 	'default' => 'mysql',
	'connections' => array(
		'sqlite' => array(
			'driver'   => 'sqlite',
			'database' => 'public/caliber.sqlite',
			'prefix'   => 'cb_',
		),
		'mysql' => array(
			'driver'    => 'mysql',
			'host'      => 'localhost',
			'database'  => 'caliber',
			'username'  => 'root',
			'password'  => 'bossboss',
			'charset'   => 'utf8',
			'collation' => 'utf8_unicode_ci',
			'prefix'    => 'cb_',
		)
   ),
);
```

An `mvc` framework or an application without any framework must have some common settings and user can configure those according to his/her need and most often all configuration files reside in a single folder, commonly, the `config` name is used. So, keeping that on mind, this dynamic configuration manager (or whatever you say) has been built, which loads all files from a given path. For example :

Initialization
--------------

[](#initialization)

```
$config = new Iconfig\Config('config');
```

Above code will load all files from the `config` folder (it expects arrays inside files) and will put everything in an array (groups using file name). Now, you can set/get any item from the array. For example, if you want to get the `default` item from the array, then you can use

```
$default = $config->getDatabase('default'); // mysql
```

Now, what is `getDatabase()` ? Actually, in this example, I've used the file name `database.php` for this array so I can use `getDatabase()` and `setDatabase()` to get or set an item. If I have a file named with `session.php` then I can use `getSession()` and `setSession()` to get or set any settings for session management. Which means, when you will pass the path (where you all configuration files are saved) to the constructor it'l load all 'php' files from that path/folder. So If, for example, in a folder named `settings` you have three files inside that folder as `database.php`, `session.php` and for example `chache.php` and if you initialize it using

```
$settings = new Iconfig\Config('settings');
```

Then, it'll load all three `php` files from the folder and it'll create one associative array using three groups like

```
Array(
  'database' => array(
    'default' => 'mysql',
    'connections' => array(
		    'sqlite' => array(
			  'driver'   => 'sqlite',
			  'database' => 'public/caliber.sqlite',
			  'prefix'   => 'cb_',
		  )
  ),
  'session' => array(
    'driver' => 'native',
    'lifetime' 120,
    'files' => '/sessions'
  ),
  'chache' =>array(
    'path' => 'c:/web/app/storage'
  )
);
```

Now, you can use this array to retrieve a setting or you can also set/change any predefined settings using dynamic methods.

Dynamic Methods
---------------

[](#dynamic-methods)

You can use `setDatabase()` and `getDatabase` to set/get database' configurations and `setSession()` and `getSession` for session and so on. These dynamic methods will be available to you after initialization, using php's `overloading` technic.

```
$settings->setDatabase('default', 'sqlite');
$settings->getDatabase('default'); // sqlite

$settings->setSession('lifetime', 240);
$settings->getSession('lifetime'); // 240
```

Using Alias
-----------

[](#using-alias)

If you want you can set an `Alias` and can use methods `statically` like this :

```
new Iconfig\Config('../myApp/config', 'Config'); // Config as Alias, you can use any name
if(Config::isExist('session')) {
    Config::setSession('driver', 'database');
    $sessionArray = Config::getSession(); // full array will be returned when called without argument
}
```

Give Default Value
------------------

[](#give-default-value)

Also you can use a defult value like

```
$chache = getChache('path', '/web') // if path doesn't exist then "/web" will be returned
```

Access Nested Arrays
--------------------

[](#access-nested-arrays)

If you have three database connections and all have a driver `key` then you can specify which `driver` key you want like

```
Config::getDatabase('connections.sqlite.driver'); // get the driver from sqlite
Config::getDatabase('connections.pgsql.driver'); // get the driver from pgsql
```

Use callbacks
-------------

[](#use-callbacks)

You can use closure as `getMethod($key, $callback)`

```
$connections = Config::getDatabase('connections', function($data){
  if(is_array($data) && array_key_exists('sqlite', $data)) {
		Config::setDatabase('connections.sqlite.driver', 'myNewSqliteDriver');
		return Config::getDatabase('connections'); // this will return connections array with new value
	}
});
```

Same could be used when setting a value like `setDatabase('connections.pgsql.driver', 'pgsql')`.

Search Using `find()` Method
----------------------------

[](#search-using-find-method)

You can also use `::find()` to search for an item as

```
Config::find('sqlite'); // if it exists, you'll get the value
Config::find('connections.sqlite'); // it'll look sqlite in to the connections
Config::find('connections.sqlite.driver'); // it'll look driver in to the connections.sqlite array
```

Get All Using `getAll()` Method
-------------------------------

[](#get-all-using-getall-method)

Also you can use

```
$all = Config::getAll();
var_dump($all); // full configuration array will be returned
```

Load More Files Using `load()` Method
-------------------------------------

[](#load-more-files-using-load-method)

You can also use

```
Config::load('filePath'); // new items will be added.
```

Well, that's all for now. Feel free to use or modify it to improve it's functionality or if you find any bug, please inform me. Hope, I'll be able to add more features in future In-Sha-Allah (on God's will). Thanks!

---

© 2013 Sheikh Heera. Licensed under MIT.

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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

Unknown

Total

1

Last Release

3938d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a8677f62a3dcb23c61e579c2d6e1799b8a61d305f6f37ec453dc3bbdea17d486?d=identicon)[sheikh\_heera](/maintainers/sheikh_heera)

---

Top Contributors

[![heera](https://avatars.githubusercontent.com/u/1007324?v=4)](https://github.com/heera "heera (38 commits)")

---

Tags

Settingsconfigcomponent

### Embed Badge

![Health badge](/badges/sheikhheera-iconfig/health.svg)

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

###  Alternatives

[akaunting/laravel-setting

Persistent settings package for Laravel

490857.9k7](/packages/akaunting-laravel-setting)[pheme/yii2-settings

Yii2 Database settings

149753.2k7](/packages/pheme-yii2-settings)[dmishh/settings-bundle

Database centric Symfony configuration management. Global and per-user settings supported.

114256.9k1](/packages/dmishh-settings-bundle)[jbtronics/settings-bundle

A symfony bundle to easily create typesafe, user-configurable settings for symfony applications

9558.8k3](/packages/jbtronics-settings-bundle)[selective/config

Config component, strictly typed

16191.9k3](/packages/selective-config)[lav45/yii2-settings

This extension helps you to easily store and retrieve data for your application.

1616.6k2](/packages/lav45-yii2-settings)

PHPackages © 2026

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