共生体/config

小型配置库

v1.2.9 2024-07-15 15:52 UTC

This package is auto-updated.

Last update: 2024-09-15 14:10:25 UTC


README

简单的配置库。

此软件包正在开发中!

要求

  • PHP 8.2

安装

composer require symbiont/config

使用

使用不带驱动程序的通用 Config

use Symbiont\Config\Config;

$config = new Config;
$config->set('key', 'value');
$config->get('key');

使用预配置的 ArrayConfig

// some-config.php
return [
    'nothing' => null,
    'some' => 'string',
    'and' => [
        'nested' => 'value'   
    ],
    'array' => [
        'with',
        'values'    
    ]
]
{
  "nothing": null, 
  "some": "string",
  "and": {
    "nested": "value"
  },
  "array": [
    "with",
    "values"
  ]
}
use Symbiont\Config\{Config, ArrayConfig, JsonConfig};

// as array
$config = new ArrayConfig('some-config.php');
// as json
$config = new JsonConfig('some-config.json');
// auto choose
$config = Config::from('some-config.json'); // returns JsonConfig object

$config->get('some') // `string`
$config->get('nothing', 'default-value') // `default-value`
$config->get('and->nested') // `value`
$config->set('and->nested', 'changed') // and->nested = `changed`
$config->set(['and', 'nested'], 'changed-again') // and->nested = `changed-again`
$config->add('array', 'added') // 'array' => ['with', 'values', 'changed']
$config->remove('array', 'values') // 'array' => ['with', 'changed']
$config->unset('some')
$config->save() // save changes to file
$config->store('new-file') // stores current config to new file

// @todo:
// $config->storeVersion() // stores a version of a config leaving the original untouched
// $config->loadVersion($version) // load a stored `$version` of the original config

文档

此文档仅记录了此软件包的技术使用方法,文字很少。

测试

composer test

许可

MIT 许可证