| Recommend this page to a friend! | 
|  Download | 
| Info |  Files |  Install with Composer |  Download | Reputation | Support forum | Blog | Links | 
| Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
| 2025-03-02 (23 days ago)  | Not yet rated by the users | Total: Not yet counted | Not yet ranked | |||||
| Version | License | PHP version | Categories | |||
| jaxon-config 0.9.0 | BSD License | 8 | Configuration, PSR, PHP 8 | 
| Collaborate with this project | Author | |
| jaxon-config - github.com Description This package can save configuration values in immutable objects. | 
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 a config reader.
$reader = new \Jaxon\Config\ConfigReader($setter);
Read config options from a file.
// A new config object is returned.
// From a PHP file.
$config = $reader->load($config, '/path/to/config/file.php');
// Or from a YAML file.
$config = $reader->load($config, '/path/to/config/file.yaml');
// Or from a JSON file.
$config = $reader->load($config, '/path/to/config/file.json');
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 new config object.
/ @var \Jaxon\Config\Config */
$config = $setter->newConfig([
    'b' => [
        'c' => 'Value',
    ],
    'd' => 'Value',
    'e' => 'Value',
    'f' => 'Value',
], 'a');
Read values.
$config->getOption('a'); // Returns ['b' => ['c' => 'Value'], 'd' => 'Value', 'e' => 'Value', 'f' => 'Value']
Remove an entry.
// A new config object is returned.
$config = $setter->unsetOption($config, 'a.e');
Read values.
$config->getOption('a'); // Returns ['b' => ['c' => 'Value'], 'd' => 'Value', 'f' => 'Value']
Remove multiple entries.
// A new config object is returned.
$config = $setter->unsetOptions($config, ['a.f', 'a.b']);
Read values.
$config->getOption('a'); // Returns ['d' => 'Value']
|  Files (27) | 
| File | Role | Description | ||
|---|---|---|---|---|
|  .github (1 directory) | ||||
|  src (3 files, 2 directories) | ||||
|  tests (2 directories) | ||||
|    .styleci.yml | Data | Auxiliary data | ||
|    composer.json | Data | Auxiliary data | ||
|    LICENSE | Lic. | License text | ||
|    phpunit.xml | Data | Auxiliary data | ||
|    README.md | Doc. | Documentation | ||
|  Files (27) | / | src | 
| File | Role | Description | ||
|---|---|---|---|---|
|  Exception (5 files) | ||||
|  Reader (4 files) | ||||
|  Config.php | Class | Class source | ||
|  ConfigReader.php | Class | Class source | ||
|  ConfigSetter.php | Class | Class source | ||
|  Files (27) | / | src | / | Exception | 
| File | Role | Description | 
|---|---|---|
|  DataDepth.php | Class | Class source | 
|  FileAccess.php | Class | Class source | 
|  FileContent.php | Class | Class source | 
|  FileExtension.php | Class | Class source | 
|  YamlExtension.php | Class | Class source | 
|  Files (27) | / | src | / | Reader | 
| File | Role | Description | 
|---|---|---|
|  JsonReader.php | Class | Class source | 
|  PhpReader.php | Class | Class source | 
|  Value.php | Class | Class source | 
|  YamlReader.php | Class | Class source | 
|  Files (27) | / | tests | / | config | 
| File | Role | Description | 
|---|---|---|
|    array.php | Aux. | Configuration script | 
|    config.ini | Data | Auxiliary data | 
|    config.json | Data | Auxiliary data | 
|    config.php | Aux. | Configuration script | 
|    config.yaml | Data | Auxiliary data | 
|    error.json | Data | Auxiliary data | 
|    error.php | Aux. | Configuration script | 
|    error.yml | Data | Auxiliary data | 
| The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. | 
|  Install with Composer | 
| Version Control | Unique User Downloads | |||||||
| 100% | 
 | 
| Applications that use this package | 
 If you know an application of this package, send a message to the author to add a link here.
 If you know an application of this package, send a message to the author to add a link here.