e1558792
xu
common(v1.0.0 bui...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
 
# weblibs-configmanager
weblibs-configmanager is a tool library for easily read and access to php config array file and direct read/write configuration file / object.
[](https://insight.sensiolabs.com/projects/54c4e80c-ff15-4235-8bec-a4c71bbe3ba5)
## Why use weblibs-configmanager ?
The purpose of this project is to propose a simple and lightweight library to manage php hierarchical configuration files.
## Installation
The recommended way to install weblibs-configmanager is through [Composer](https://getcomposer.org).
```bash
composer require clagiordano/weblibs-configmanager
```
## Usage examples
### Write a sample config file like this
```
<?php
return array (
'app' => 'app_name',
'db' =>
array (
'host' => 'localhost',
'user' => 'sample_user',
'pass' => 'sample_pass',
'port' => 3306,
),
'other' =>
array (
'multi' =>
array (
'deep' =>
array (
'nested' => 'config_value',
),
),
),
);
```
### Instance ConfigManager object
```php
use clagiordano\weblibs\configmanager\ConfigManager;
/**
* Instance object to read argument file
*/
$config = new ConfigManager("configfile.php");
```
### Check if a value exists into config file
```php
/**
* Check if a value exists into config file
*/
$value = $config->existValue('app');
```
### Read a simple element from config file
```php
/**
* Read a simple element from config file
*/
$value = $config->getValue('app');
```
### Access to a nested element from config
```php
/**
* Access to a nested element from config
*/
$nestedValue = $config->getValue('other.multi.deep.nested');
```
### Change config value at runtime
```php
/**
* Change config value at runtime
*/
$this->config->setValue('other.multi.deep.nested', "SUPERNESTED");
```
### Save config file with original name (OVERWRITE)
```php
/**
* Save config file with original name (OVERWRITE)
*/
$this->config->saveConfigFile();
```
### Or save config file with a different name
```php
/**
* Save config file with original name (OVERWRITE)
*/
$this->config->saveConfigFile('/new/file/name/or/path/test.php');
```
### Optionally you can also reload config file from disk after save
```php
/**
* Optionally you can also reload config file from disk after save
*/
$this->config->saveConfigFile('/new/file/name/or/path/test.php', true);
```
### Load another configuration file without reinstance ConfigManager
```php
/**
* Load another configuration file without reinstance ConfigManager
*/
$this->config->loadConfig('another_config_file.php');
```
## Legal
*Copyright (C) Claudio Giordano <claudio.giordano@autistici.org>*
|