setbased / typed-config
A lightweight and strong typed that supports PHP, INI, XML, JSON, and YAML files
Installs: 14 141
Dependents: 4
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: >=8.1
- hassankhan/config: ^3.1.0
- setbased/helper-cast: ^3.0.0
Requires (Dev)
- phing/phing: ^3.0.0-RC4
- phpunit/phpunit: ^9.5.28
This package is auto-updated.
Last update: 2024-10-26 09:24:03 UTC
README
A lightweight and strong typed configuration file loader that supports PHP, INI, XML, JSON, and YAML files.
This package is a wrapper around hassankhan/config.
Manual
Instantiating Strong Typed Config
Creating an instance of Strong Typed Config requires passing an instance of Noodlehaus\Config
:
use Noodlehaus\Config; use SetBased\Config\TypedConfig; $config = new TypedConfig(new Config('config.json'));
Getting the value of a key
There are two flavors of methods for getting a configuration value:
- Mandatory keys (man for short). These methods will never return a null value.
- Optional keys (opt for short). These methods will return null if the key does not exists or has value
null
.
All methods will try to cast the value of a key to the required type using package setbased/helper-cast. I.e. if the value of key is string(1)
method
getManBool
will return bool(true)
and method getManInt
will return int(1)
.
All methods have two arguments:
- The key.
- An optional default value. this value will be returned if the key does not exists or has value
null
.
The table below gives an overview of all methods for getting the value of a key.
Installation
Strong Typed Config can be installed using composer:
composer require setbased/typed-config
License
This project is licensed under the terms of the MIT license.