jaxon-php/jaxon-config 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jaxon-php/jaxon-config

最新稳定版本:v1.0.0

Composer 安装命令:

composer require jaxon-php/jaxon-config

包简介

Save config options in immutable objects.

README 文档

README

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 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']

统计信息

  • 总下载量: 1.2k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2025-01-13