11# PConfig 配置文件库
22
3- PConfig 是一个使用了 PHP 编写的配置文件解析库,能够解析 PHP(数组 )、JSON、YAML、XML 和 INI 格式的文件,其统一了 API 操作,屏蔽了不同格式文件的解析细节,使用起来更加简单、高效。
3+ PConfig 是一个使用了 PHP 编写的配置文件解析库,能够解析 PHP(array )、JSON、YAML、XML 和 INI 格式的文件,其统一了 API 操作,屏蔽了不同格式文件的解析细节,使用起来更加简单、高效。
44
55PConfig is a PHP library for parsing config file (php, json, xml, yaml, ini).
66
7+ ## 更新 Update
8+
9+ 中文
10+
11+ - 2017-12-24 修改 ` pconfig\Config#setConfigFile ` api 为 ` pconfig\Config#setPath `
12+
13+ English
14+
15+ - 2017-12-24 change ` pconfig\Config#setConfigFile ` api to ` pconfig\Config#setPath `
16+
717## 安装 Install
818
919使用 PHP Composer 安装
1020
21+ Install by composer
22+
1123``` bash
1224composer require oopsguy/pconfig
1325```
@@ -27,12 +39,13 @@ $config = DefaultConfigBuilder::build("config/config.php");
2739echo $config->get("app");
2840$config->delete("version");
2941$config->set('debug', false);
42+ $config->set("settings.key", "new value");
3043$config->save();
3144
3245// json file
3346$jsonConfig = DefaultConfigBuilder::build('config/config.json');
3447$jsonConfig->set('homepage', 'https://github.com');
35- $jsonConfig->setConfigFile ('config/temp_json.json'); //save as temp_json.json file
48+ $jsonConfig->setPath ('config/temp_json.json'); //save as temp_json.json file
3649$jsonConfig->save();
3750
3851$parser = new YamlParser();
@@ -42,7 +55,53 @@ $extConfig->set('type', 'yaml');
4255$extConfig->save();
4356```
4457
45- ## 配置文件示例 Config file example
58+ 配置项的层级关系使用逗号分割,您也可以配置自定义分割规则
59+
60+ The hierarchy of configuration items is separated by commas, you an custom your own separator.
61+
62+ ``` php
63+ <?php
64+ use pconfig\Config;
65+ use pconfig\provider\impl\FileProvider;
66+ use pconfig\parser\impl\JsonParser;
67+
68+ $config = new Config(
69+ new JsonParser(), // specify format parser
70+ new FileProvider(['file' => 'config/config.php']),
71+ [
72+ Config::CONFIG_KEY_CASE => Config::KEY_CASE_LOWER, // change config keys into case lower
73+ Config::CONFIG_SEPARATOR => '.', // setting config item separator
74+ ]
75+ );
76+ ```
77+
78+ config example
79+
80+ ``` php
81+ <?php
82+ return [
83+ 'level1' => [
84+ 'level2' => [
85+ 'level3' => 'Level 3'
86+ ]
87+ ]
88+ ];
89+ ```
90+
91+ 操作 ` level3 ` 配置项
92+
93+ Set ` level3 ` item
94+
95+ ``` php
96+ <?php
97+
98+ // init config ...
99+ $config->set('level1.level2.level3', "Level end");
100+ // delete config item
101+ $config->delete('level1.level2');
102+ ```
103+
104+ ## 配置文件示例 Config file examples
46105
47106### PHP Array
48107
0 commit comments