PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of Thierry Feuzeu   Jaxon Config   README.md   Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: Jaxon Config
Save configuration values in immutable objects
Author: By
Last change:
Date: 8 days ago
Size: 3,115 bytes
 

Contents

Class file image Download

Build Status Scrutinizer Code Quality StyleCI codecov

Latest Stable Version Total Downloads License

Jaxon Config

Jaxon Config saves config options in immutable objects.

Install

composer require jaxon-php/jaxon-config

Usage

Create a config setter.

$setter = new \Jaxon\Config\ConfigSetter();

Create a config object with initial value.

/ @var \Jaxon\Config\Config */
$config = $setter->newConfig([
    'a' => [
        'b' => [
            'c' => 'Value',
        ],
    ],
]);

Create an empty config object and set values.

/ @var \Jaxon\Config\Config */
$config = $setter->newConfig();
// A new config object is returned.
$config = $setter->setOptions($config, [
    'a' => [
        'b' => [
            'c' => 'Value',
        ],
    ],
]);

Read values.

$config->getOption('a'); // Returns ['b' => ['c' => 'Value']]
$config->getOption('a.b'); // Returns ['c' => 'Value']
$config->getOption('a.b.c'); // Returns 'Value'

Set a single value.

// A new config object is returned.
$config = $setter->setOption($config, 'a.b.d', 'Another value');

Read values.

$config->getOption('a'); // Returns ['b' => ['c' => 'Value', 'd' => 'Another value']]
$config->getOption('a.b'); // Returns ['c' => 'Value', 'd' => 'Another value']
$config->getOption('a.b.c'); // Returns 'Value'
$config->getOption('a.b.d'); // Returns 'Another value'

Set values with a prefix.

// A new config object is returned.
$config = $setter->setOptions($config, [
    'd' => [
        'e' => 'Overwritten value',
    ],
    'f' => ['Array', 'Of', 'Values'],
], 'a.b');

Read values.

$config->getOption('a.b'); // Returns ['c' => 'Value', 'd' => ['e' => 'Overwritten value']]
$config->getOption('a.b.d'); // Returns ['e' => 'Overwritten value']
$config->getOption('a.b.d.e'); // Returns 'Overwritten value'
$config->getOption('a.b.f'); // Returns ['Array', 'Of', 'Values']

Create a config reader.

$reader = new \Jaxon\Config\ConfigReader(new \Jaxon\Config\ConfigSetter());

Read config options from a file.

// A new config object is returned.
$config = $reader->load($config, '/path/to/config/file.php');