2017 © Pedro Pelรกez
 

library chain-config

A configuration loader, where order matters.

image

macfja/chain-config

A configuration loader, where order matters.

  • Tuesday, January 12, 2016
  • by MacFJA
  • Repository
  • 1 Watchers
  • 2 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

ChainConfig

A configuration loader, where order matters., (*1)

Features

  • Multiple configuration paths
  • Multiple loader
    • Ini (.ini, .properties)
    • Json (.json)
    • Neon (.neon)
    • Php (.php)
    • Xml (.xml)
    • Yaml (.yml, .yaml)
  • Handle .dist file
  • Paths order matters
  • Readers order matters
  • Dynamic key
  • Dynamic value

The .dist file handling

When the search for the config file to load, the library check if a .dist exist. If it's the case, and there is no file without the .dist part, the file is used., (*2)

So, in this example:, (*3)

 โ”œโ”€โ”€ test1.ini.dist
 โ”œโ”€โ”€ test2.ini
 โ””โ”€โ”€ test2.ini.dist

test1.ini.dist will be loaded,
but not test2.ini.dist because the file test2.ini exist. (and it's test2.ini that will be loaded), (*4)

Order matters

Configuration data are loaded in the order you define. Loader are used in the order you define., (*5)

Example:, (*6)

โ”œโ”€โ”€ 01-my-secondary-path/
โ”‚ย ย  โ””โ”€โ”€ a.php
โ””โ”€โ”€ 02-my-main-path/
    โ”œโ”€โ”€ a.ini
    โ”œโ”€โ”€ b.ini
 ย ย  โ””โ”€โ”€ b.xml

If you define 02-my-main-path to be the first path, and 01-my-secondary-path as the second path. If you ask of a a.* configuration then the library will first load 02-my-main-path/a.php and after 02-my-main-path/a.ini. Later loading don't override already loaded data, later loading only add missing key/value., (*7)

The order of the reader also matter. In the previous structure, if you define the Xml reader before the Ini loader, then, if you ask a b.* config, the first file to be load is 02-my-main-path/b.xml and after the 02-my-main-path/b.ini file., (*8)

Dynamics data

The library expose two callback functionality. One for the key, the other for the value. Before the key is send to the library, it can be changed by one or more callback function. Same thing for the value, just before returning it, the library will send the value to all registered callback., (*9)

This can be useful for change a key or a value depending on another configuration or an environment depends variable. See example below, (*10)

Installation

The simplest way to install the library is to use Composer: ``` sh composer require macfja/chain-config, (*11)



Usage ----- Create a `Config` object: ``` php $config = new Config(); $config->appendPath(__DIR__ . DIRECTORY_SEPARATOR . 'config'); $config->appendReader(new IniReader());

Read a configuration: php engine = $config->get('database.engine');, (*12)

Detailed class API, (*13)

Example of usage, (*14)

Reader Format

More information in Readers documentation, (*15)

Limitation

You can not use the directory separator (/ on Unix/Linux, \ on Windows) or the path separator (: on Unix/Linux) in the first part of the key., (*16)

Additional Classes

You can found two class that ChainConfig use to work:, (*17)

The Versions

12/01 2016

dev-master

9999999-dev

A configuration loader, where order matters.

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Avatar MacFJA

json xml configuration ini yaml chain neon load priority

12/01 2016

0.1.0

0.1.0.0

A configuration loader, where order matters.

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Avatar MacFJA

json xml configuration ini yaml chain neon load priority