kyos / configparser
A simple YAML config file loader.
Installs: 180 756
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 8
Forks: 0
Open Issues: 0
Requires
- php: ^8.0
- symfony/yaml: ^5.0
Requires (Dev)
- phpunit/phpunit: ^9.0
- squizlabs/php_codesniffer: ^3.0
README
configparser
A simple YAML config file loader.
Install
Via Composer
$ composer require kyos/configparser
Usage
Given the following config.yaml
configuration file:
application: releaseStage: Production debugMode: true
you can parse any of its properties using:
$parser = Kyos\ConfigParser::getParserForFile('config.yaml'); echo $parser->get('application.releaseStage');
You can use the following notations:
- Dot notation:
echo $parser->get('application.releaseStage');
- Array notation:
echo $parser->get(['application', 'releaseStage']);
- String notation (for top level keys):
var_dump($parser->get('application'));
Assertions
Using ConfigParser, you can require specific keys to be defined and their types. Note: All commands should be proceeded by an evaluate function call.
Required Key
echo $parser->evaluate('application.releaseStage')->isRequired();
String
echo $parser->evaluate('application.releaseStage')->isString();
Numeric
echo $parser->evaluate('application.releaseStage')->isNumeric();
Boolean
echo $parser->evaluate('application.releaseStage')->isBoolean();
Array
echo $parser->evaluate('application')->isArray();
Allowed Values
echo $parser->evaluate('application.releaseStage')->isOneOf(['Production', 'Staging', 'Test']);
Chain
Assertion functions can be also chained.
echo $parser->evaluate('application.releaseStage') ->isRequired()->isString() ->isOneOf(['Production', 'Staging', 'Test']);
Change log
Please see changelog for more information on what has changed recently.
Testing
$ composer test
Security
If you discover any security related issues, please email pagoulatos@kyos.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.