popphp/pop-config

Pop Config Component for Pop PHP Framework

3.2.0 2017-06-28 20:48 UTC

README

Build Status Coverage Status

OVERVIEW

pop-config is a basic configuration component that helps centralize application configuration values and parameters. Values can be accessed via array notation or object arrow notation. It can disable changes to the configuration values if need be for the life-cycle of the application. It also can parse configuration values from common formats, such as JSON, INI and XML.

pop-config is a component of the Pop PHP Framework.

INSTALL

Install pop-config using Composer.

composer require popphp/pop-config

Or, require it in your composer.json file

"require": {
    "popphp/pop-config" : "3.0.*"
}

BASIC USAGE

Set and access values

$config = new Pop\Config\Config(['foo' => 'bar']);

$foo = $config->foo;
// OR
$foo = $config['foo'];

Allow changes

Changes to configuration values are disabled by default.

$config = new Pop\Config\Config(['foo' => 'bar'], true);
$config->foo = 'New Value';

Parse a configuration file

; This is a sample configuration file config.ini
[foo]
bar = 1
baz = 2
$config = new Pop\Config\Config('/path/to/config.ini');

// $value equals 1
$value = $config->foo->bar;

Merge new values into the config object

$config = new Pop\Config\Config($configData);
$config->merge($newData);

Convert config object down to a basic array

$config = new Pop\Config\Config($configData);
$data   = $config->toArray();