2017 © Pedro Peláez
 

library kingconf

Load configuration in any sane format

image

monomelodies/kingconf

Load configuration in any sane format

  • Wednesday, July 18, 2018
  • by monomelodies
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1,086 Installations
  • PHP
  • 6 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 11 Versions
  • 5 % Grown

The README.md

Kingconf

Load configuration in any sane format, (*1)

Some prefer JSON, some prefer YAML. Some even prefer XML... why not allow them all and let the user decide?, (*2)

Kingconf loads configuration from any of the following formats: - json: A JSON as a key/value store. - yaml: A Yaml file. - xml: An XML file. It should contain a root element which can be called anything. - ini: The PHP .ini format. - php: Plain ol' PHP (return ['key' => 'value'] format)., (*3)

Installation

$ cd /path/to/project
$ composer require monomelodies/kingconf

Manual

  • Download or clone the repository somewhere;
  • Add /path/to/kingconf/src to your autoloader for PSR-4 namespace Monomelodies\\Kingconf\\.

Usage

Create a Monomelodies\Kingconf\Config object with one or more config file paths as the constructor arguments:, (*4)

<?php

use Monomelodies\Kingconf\Config;

$config = new Config('/path/to/json', '/path/to/ini');

Note that the first value found is leading, i.e. if in the above example the JSON defines foo = bar and the ini foo = baz, foo will remain bar., (*5)

The resulting $config object simply extends PHP's ArrayObject, so you can access it like any other array:, (*6)

<?php

echo $config['foo']; // (string)"bar"

Errors and exceptions

Kingconf will throw exceptions if config files can't be read, contain invalid syntax etc. So, if you can't be sure about the contents (e.g. user submitted data) be sure to wrap the constructor in a try/catch block:, (*7)

<?php

use Monomelodies\Kingconf\Config;
use Monomelodies\Kingconf\Exception;

try {
    $config = new Config($some_file_we_dont_trust);
} catch (Exception $e) {
    echo "Config invalid!!!1";
}

Note that user submitted configuration is probably best handled in a different manner though..., (*8)

All Kingconf exceptions extend Monomelodies\Kingconf\Exception, which in turn extends DomainException., (*9)

The Versions

18/07 2018

dev-master

9999999-dev

Load configuration in any sane format

  Sources   Download

MIT

The Requires

 

The Development Requires

by Marijn Ophorst

php json xml configuration ini config yaml loader

18/07 2018

1.1.4

1.1.4.0

Load configuration in any sane format

  Sources   Download

MIT

The Requires

 

The Development Requires

by Marijn Ophorst

php json xml configuration ini config yaml loader

18/07 2018

1.1.3

1.1.3.0

Load configuration in any sane format

  Sources   Download

MIT

The Requires

 

The Development Requires

by Marijn Ophorst

php json xml configuration ini config yaml loader

16/07 2018

1.1.2

1.1.2.0

Load configuration in any sane format

  Sources   Download

MIT

The Requires

 

The Development Requires

by Marijn Ophorst

php json xml configuration ini config yaml loader

01/02 2018

1.1.1

1.1.1.0

Load configuration in any sane format

  Sources   Download

MIT

The Requires

 

The Development Requires

by Marijn Ophorst

php json xml configuration ini config yaml loader

15/07 2016

1.1.0

1.1.0.0

Load configuration in any sane format

  Sources   Download

MIT

The Requires

 

The Development Requires

by Marijn Ophorst

php json xml configuration ini config yaml loader

02/12 2015

dev-develop

dev-develop

Load configuration in any sane format

  Sources   Download

MIT

The Requires

 

The Development Requires

by Marijn Ophorst

php json xml configuration ini config yaml loader

02/12 2015

1.0.3

1.0.3.0

Load configuration in any sane format

  Sources   Download

MIT

The Requires

 

The Development Requires

by Marijn Ophorst

php json xml configuration ini config yaml loader

02/12 2015

1.0.2

1.0.2.0

Load configuration in any sane format

  Sources   Download

MIT

The Requires

 

The Development Requires

by Marijn Ophorst

php json xml configuration ini config yaml loader

02/12 2015

1.0.1

1.0.1.0

Load configuration in any sane format

  Sources   Download

MIT

The Requires

 

The Development Requires

by Marijn Ophorst

php json xml configuration ini config yaml loader

02/12 2015

1.0.0

1.0.0.0

Load configuration in any sane format

  Sources   Download

MIT

The Requires

 

The Development Requires

by Marijn Ophorst

php json xml configuration ini config yaml loader