PHPackages                             kktsvetkov/konphigo - 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. kktsvetkov/konphigo

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

kktsvetkov/konphigo
===================

simple configuration library

v1.0.1.1(9y ago)1241LGPL-3.0PHPPHP &gt;=5.3.0

Since Mar 19Pushed 9y ago1 watchersCompare

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

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

Konphigo
========

[](#konphigo)

Konphigo is a small PHP5/PHP7 library for working with configuration.

It is meant to be very easy to use. I've had experience with several other configuration implementations and they were quite clumsy and overdressed for my taste. I prefer dead-simple and re-usable.

Konphigo is meant to be used as "facade" -- a class with static methods.

Basic use
---------

[](#basic-use)

You read configuration data by calling the `\Konphigo\Konphigo::get()` method. First argument is the name of what you want to read.

```
$a = \Konphigo\Konphigo::get('a');

```

You get all the loaded configuration data by using an empty first argument.

```
$all = \Konphigo\Konphigo::get();

```

The second argument is a fallback default value, if what you want to read is not there.

```
$a = \Konphigo\Konphigo::get('a', 123);

```

Since you can have both scalars and arrays inside the configuration, that second argument can be array as well.

```
$skip = \Konphigo\Konphigo::get('skip', ['.svn', '.git']);

```

Loading up
----------

[](#loading-up)

I want to keep library very simple. The main class, `\Konphigo\Konphigo` has a single method for loading configuration data, called `\Konphigo\Konphigo::load()`.

```
\Konphigo\Konphigo::load([
	'skip' => ['.svn', '.git'],
	'tmp' => '/tmp'
	]);

```

The first argument is an array with the data you want to read. It is an associated array, where the keys are the names for the configuration data, and the values is the actual data.

In a lot of cases you need to load configuration data in more than one occurrence. You start loading some data, then you need to add more data; in same cases you need to replace some of the already loaded data. This is where the second argument for the `\Konphigo\Konphigo::load()` method is used. This is the "mode" used for how to handle the loaded data.

```
// replacing already loaded "skip" configuration value with a new one
//
\Konphigo\Konphigo::load([
	'skip' => ['.svn', '.git', '.dudu']
	],
	Konphigo::LOAD_MODE_REPLACE
	);

```

The three options are:

- `Konphigo::LOAD_MODE_UNION` - default value, this will get the new data and do array union with it, e.g. `$config += $data`;
- `Konphigo::LOAD_MODE_MERGE` - new data is merged with the already loaded, e.g. `$config = array_merge($data, $config);`;
- `Konphigo::LOAD_MODE_REPLACE` - new data will overwrite existing keys if there is a match, e.g. `$config = array_replace($data, $config);`;

The `array_replace()` is pretty straight-forward, most people are puzzled with the difference between array union and `array_merge()`.

Advanced loading
----------------

[](#advanced-loading)

Inside this library there are several classes under the `Konphigo\Read` namespace. They are designed to read configuration data from various media. These "reader" classes do not work with `Konphigo` class, instead they return arrays from what was read. I did this de-coupling on purpose, since as I stated at the beginning, I wanted this to be dead-simple.

All of the `Konphigo\Read` classes read the data with a static `::load()` methods. First method is usually how to identify the media to read from. The second argument is optional, and it is to provide default values for what was read; in this way even if you read from an empty media, there are still going to be configuration data loaded from these default values.

#### Konphigo\\Read\\PHP

[](#konphigoreadphp)

This reads the data from PHP files.

```
 \Konphigo\Konphigo::load(
 	\Konphigo\Read\PHP::load(
 		'config-test.php',
 		array('B' => 303, 'CC' => 'ddd')
 	)
 );

```

These files need to follow a format, which will allow to get the data by including them.

```
