refactor: Added general config validations and timezone config

This commit is contained in:
Aerex
2020-06-03 00:04:43 -05:00
parent 00d0ea624f
commit c2e181aa75
7 changed files with 69 additions and 51 deletions

View File

@@ -6,6 +6,7 @@ use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Yaml\Yaml;
use Carbon\CarbonTimeZone;
class ConfigBuilder implements ConfigurationInterface {
private $configs = [];
@@ -24,20 +25,32 @@ class ConfigBuilder implements ConfigurationInterface {
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('configs');
$ref = $rootNode->children()
->arrayNode('logger')
->canBeEnabled()
->arrayNode('general')
->children()
->scalarNode('file')->end()
->scalarNode('level')
->defaultValue('ERROR')
->validate()
->IfNotInArray(['DEBUG', 'INFO', 'NOTICE', 'WARNING', 'ERROR', 'CRITICAL', 'ALERT', 'EMERGENCY'])
->thenInvalid('Invalid log level %s')
->end()
->end()
->end()
->end();
->arrayNode('logger')
->canBeEnabled()
->children()
->scalarNode('file')->end()
->scalarNode('level')
->defaultValue('ERROR')
->validate()
->IfNotInArray(['DEBUG', 'INFO', 'NOTICE', 'WARNING', 'ERROR', 'CRITICAL', 'ALERT', 'EMERGENCY'])
->thenInvalid('Invalid log level %s')
->end()
->end()
->end()
->end()
->scalarNode('timezone')
->defaultValue('UTC')
->validate()
->IfNotInArray(CarbonTimeZone::listIdentifiers())
->thenInvalid('Invalid timezone identifier %s')
->end()
->end()
->end()
->end()
->arrayNode('storages')
->children();
foreach ($this->configs as $config) {
$ref = $ref->append($config->get());
}