Skip to content

Commit b0c42b1

Browse files
committed
Merge branch 'master' of github.com:SetBased/php-typed-config
2 parents 2263c43 + 2aaadb7 commit b0c42b1

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
12
# Strong Typed Config
23

34
A lightweight and strong typed configuration file loader that supports PHP, INI, XML, JSON, and YAML files.
45

6+
This package is a wrapper around [hassankhan/config](https://github.com/hassankhan/config).
7+
58
<table>
69
<thead>
710
<tr>
@@ -33,6 +36,56 @@ A lightweight and strong typed configuration file loader that supports PHP, INI,
3336
</tbody>
3437
</table>
3538

39+
# Manual
40+
41+
## Instantiating Strong Typed Config
42+
43+
Creating an instance of Strong Typed Config requires passing an instance of ```Noodlehaus\Config```:
44+
```php
45+
use Noodlehaus\Config;
46+
use SetBased\Config\TypedConfig;
47+
48+
$config = new TypedConfig(new Config('config.json'));
49+
```
50+
51+
## Getting the value of a key
52+
53+
There are two flavors of methods for getting a configuration value:
54+
* Mandatory keys (man for short). These methods will never return a null value.
55+
* Optional keys (opt for short). These methods will return null if the key does not exists or has value ```null```.
56+
57+
All methods will try to cast the value of a key to the required type using package [setbased/helper-cast](https://github.com/SetBased/php-helper-cast/blob/master/composer.json). I.e. if the value of key is ```string(1)``` method
58+
```getManBool``` will return ```bool(true)``` and method ```getManInt``` will return ```int(1)```.
59+
60+
All methods have two arguments:
61+
1. The key.
62+
2. An optional default value. this value will be returned if the key does not exists or has value ```null```.
63+
64+
The table below gives an overview of all methods for getting the value of a key.
65+
66+
| Method | Null Value | Return Type |
67+
| ----------------- | ------------------- | ------------ |
68+
| getManArray | throws an exception | array |
69+
| getManBool | throws an exception | bool |
70+
| getManFiniteFloat | throws an exception | float |
71+
| getManFloat | throws an exception | float |
72+
| getManInt | throws an exception | int |
73+
| getManString | throws an exception | string |
74+
| getOptArray | returns null | array\|null |
75+
| getOptBool | returns null | bool\|null |
76+
| getOptFiniteFloat | returns null | float\|null |
77+
| getOptFloat | returns null | float\|null |
78+
| getOptInt | returns null | int\|null |
79+
| getOptString | returns null | string\|null |
80+
81+
82+
# Installation
83+
84+
Strong Typed Config can be installed using composer:
85+
```sh
86+
composer require setbased/typed-config
87+
```
88+
3689
License
3790
=======
3891

0 commit comments

Comments
 (0)