|
| 1 | + |
1 | 2 | # Strong Typed Config |
2 | 3 |
|
3 | 4 | A lightweight and strong typed configuration file loader that supports PHP, INI, XML, JSON, and YAML files. |
4 | 5 |
|
| 6 | +This package is a wrapper around [hassankhan/config](https://github.com/hassankhan/config). |
| 7 | + |
5 | 8 | <table> |
6 | 9 | <thead> |
7 | 10 | <tr> |
@@ -33,6 +36,56 @@ A lightweight and strong typed configuration file loader that supports PHP, INI, |
33 | 36 | </tbody> |
34 | 37 | </table> |
35 | 38 |
|
| 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 | + |
36 | 89 | License |
37 | 90 | ======= |
38 | 91 |
|
|
0 commit comments