2017 © Pedro Peláez
 

library config

A simple configuration library

image

geeksareforlife/config

A simple configuration library

  • Friday, October 13, 2017
  • by geeksareforlife
  • Repository
  • 1 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Config

A simple configuration library, (*1)

This library stores config in two files - a normal config file and a defaults file., (*2)

When retrieving a value from the config, the normal config is checked first and if nothing is found the value from the defaults file is used., (*3)

Getting Started

Install Composer and run the following command to get the latest version:, (*4)

composer require "geeksareforlife/config:^0.1"

Basic Usage

First, create a config object and load the files (Files will be created if they don't exist):, (*5)

$config = new Config();
$config->load('/path/to/config.json', '/path/to/defaultConfig.json');

Then you can get or set values into the config object. Keys are dot-seperated., (*6)

$value = $config->getValue('key.name');
$config->setValue('key.name', $value);

When you have finished, you need to call the save function to commit the config to disk., (*7)

$config->save();

More Details

Values can be stored in two config files. Each file is a single JSON object., (*8)

Keys are in dot-notation, and an optional "module" can be used for each key. This allows you to have identical keys for different areas of your system., (*9)

Loading your config files

Once you have created the config object, you need to load the two config files. The config file needs to be writable, and both files will be created if they don't exist., (*10)

Getting a value

The getValue function returns the value of a given key:, (*11)

getValue(string $key, [string $module]);

If the key is found in the config file, the value from there is returned. If not, the default file is checked and a value returned from there if available., (*12)

If the key is not found in either file, the function will return false, (*13)

Setting a value

the setValue function behaves very similarly to the getValue, (*14)

setValue(string $key, mixed $value, [string $module]);

The value is only ever stored in the config - the defaults are never touched., (*15)

At this point, the file itself it not saved, the value is only stored in-memory., (*16)

Saving the config

The save function saves the in-memory config to the config file., (*17)

The Versions

13/10 2017

dev-master

9999999-dev https://github.com/geeksareforlife/config

A simple configuration library

  Sources   Download

MIT

The Requires

 

by James Hayward

13/10 2017

dev-doc

dev-doc https://github.com/geeksareforlife/config

A simple configuration library

  Sources   Download

MIT

The Requires

 

by James Hayward

19/09 2017

0.1.0

0.1.0.0 https://github.com/geeksareforlife/config

A simple configuration library

  Sources   Download

MIT

The Requires

 

by James Hayward