A simple YAML config file loader.
Via Composer
$ composer require kyos/configparserGiven the following config.yaml configuration file:
application:
releaseStage: Production
debugMode: trueyou 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'));Using ConfigParser, you can require specific keys to be defined and their types. Note: All commands should be proceeded by an evaluate function call.
echo $parser->evaluate('application.releaseStage')->isRequired();echo $parser->evaluate('application.releaseStage')->isString();echo $parser->evaluate('application.releaseStage')->isNumeric();echo $parser->evaluate('application.releaseStage')->isBoolean();echo $parser->evaluate('application')->isArray();echo $parser->evaluate('application.releaseStage')->isOneOf(['Production', 'Staging', 'Test']);Assertion functions can be also chained.
echo $parser->evaluate('application.releaseStage')
->isRequired()->isString()
->isOneOf(['Production', 'Staging', 'Test']);Please see changelog for more information on what has changed recently.
$ composer testIf you discover any security related issues, please email pagoulatos@kyos.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
