popphp / pop-config
Pop Config Component for Pop PHP Framework
Installs: 6 205
Dependents: 2
Suggesters: 0
Security: 0
Stars: 4
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: >=8.1.0
- ext-dom: *
- ext-json: *
- ext-simplexml: *
- popphp/pop-utils: ^2.1.0
Requires (Dev)
- phpunit/phpunit: ^10.0.0
Suggests
- ext-yaml: For handling YAML data
README
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, XML, INI and YAML.
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" : "^4.0.0"
}
Quickstart
Set and access values
use Pop\Config\Config; $config = new Config(['foo' => 'bar']); $foo = $config->foo; // OR $foo = $config['foo'];
Allow changes
Changes to configuration values are disabled by default.
use Pop\Config\Config; $config = new Config(['foo' => 'bar'], true); $config->foo = 'New Value';
Merge new values into the config object
use Pop\Config\Config; $config = new Config($configData); $config->merge($newData);
Convert config object down to a basic array
use Pop\Config\Config; $config = new Config($configData); $data = $config->toArray();
Parse a configuration file
; This is a sample configuration file config.ini
[foo]
bar = 1
baz = 2
use Pop\Config\Config; $config = Config::createFromData('/path/to/config.ini'); // $value equals 1 $value = $config->foo->bar;
Render config data to a string format
Supported formats include PHP, JSON, XML, INI and YAML
use Pop\Config\Config; $config = new Config($configData); echo $config->render('json');