dev-sanjeeb/config

该项目专注于编写配置文件的解析器。

1.0.1 2021-10-19 17:10 UTC

This package is auto-updated.

Last update: 2024-09-19 23:50:47 UTC


README

该项目专注于编写配置文件的解析器。

支持的文件格式

  • JSON

要求

  • PHP >= 7.2

使用Composer安装

$ composer require dev-sanjeeb/config

用法

加载文件

方法1:初始化时

// Loading Single file
$config = new Config(__DIR__.'/files/test.json');

// Loading Multiple file
$config = new Config([__DIR__.'/files/test.json', __DIR__.'/files/test2.json']);

方法2:初始化后

$config = new Config();

// Loading Single file
$config->loadFiles(__DIR__.'/files/test.json');

// Loading Multiple file
$config->loadFiles([__DIR__.'/files/test.json', __DIR__.'/files/test2.json']);

加载原始文本

$config = new Config();

// Loading Raw Text
$config->loadRawText(
            [
                [
                    'content' => '{"a":1,"b":2,"c":3,"d":4,"e":5}',
                    'type' => 'json'
                ],
                [
                    'content' => '{"a1":1,"b1":2,"c1":3,"d1":4,"e1":5}',
                    'type' => 'json'
                ]
            ]
        );

获取器

$config = new Config();

// Accessing 
$config->get('database.host');

// Accessing with default data
$config->get('database.host', '127.0.0.1');

设置器

$config = new Config();

// Setting value
$config->set('database.host', '127.0.0.1');

合并数组

$config = new Config();

// merge value
$config->merge(['database' => ['host'] => '127.0.0.1']);

重置

$config = new Config();

// Resetting value
$config->reset();

测试

$ phpunit

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件