Skip to content

Commit 0439ab4

Browse files
committed
Update README.md and change setConfigFile api to setPath
1 parent 4906bb9 commit 0439ab4

2 files changed

Lines changed: 65 additions & 6 deletions

File tree

README.md

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
# PConfig 配置文件库
22

3-
PConfig 是一个使用了 PHP 编写的配置文件解析库,能够解析 PHP(数组)、JSON、YAML、XML 和 INI 格式的文件,其统一了 API 操作,屏蔽了不同格式文件的解析细节,使用起来更加简单、高效。
3+
PConfig 是一个使用了 PHP 编写的配置文件解析库,能够解析 PHP(array)、JSON、YAML、XML 和 INI 格式的文件,其统一了 API 操作,屏蔽了不同格式文件的解析细节,使用起来更加简单、高效。
44

55
PConfig 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
1224
composer require oopsguy/pconfig
1325
```
@@ -27,12 +39,13 @@ $config = DefaultConfigBuilder::build("config/config.php");
2739
echo $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

src/Config.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ class Config implements \ArrayAccess
2626
/**
2727
* 处理配置项名称统一大写
2828
*/
29-
const VALUE_CASE_UPPER = CASE_UPPER;
29+
const KEY_CASE_UPPER = CASE_UPPER;
3030

3131
/**
3232
* 处理配置项名称统一小写
3333
*/
34-
const VALUE_CASE_LOWER = CASE_LOWER;
34+
const KEY_CASE_LOWER = CASE_LOWER;
3535

3636
/**
3737
* 元素不存在时中断寻找
@@ -105,7 +105,7 @@ public function save()
105105
* 设置配置文件
106106
* @param string $file 文件路径
107107
*/
108-
public function setConfigFile($file)
108+
public function setPath($file)
109109
{
110110
$this->provider->setConfig('file', $file);
111111
}

0 commit comments

Comments
 (0)