refactor: Added general config validations and timezone config
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
@@ -25,7 +25,7 @@ class Console extends AbstractConsole {
|
||||
if (isset($input)) {
|
||||
$input = $this->convertToString($input);
|
||||
}
|
||||
$process = new Process(implode(' ', $stdin), $input, $envs);
|
||||
$process = new Process(implode(' ', $stdin), null, $envs, $input);
|
||||
$process->inheritEnvironmentVariables();
|
||||
|
||||
try {
|
||||
|
@@ -39,11 +39,13 @@ class StorageManager {
|
||||
throw new \Exception('StorageManger was not initialize or configs are not defined');
|
||||
}
|
||||
foreach ($this->configs as $key => $value) {
|
||||
$storage = $this->storages[$key];
|
||||
if (!isset($storage)){
|
||||
throw new \Exception();
|
||||
if ($key !== 'logger') {
|
||||
$storage = $this->storages[$key];
|
||||
if (!isset($storage)){
|
||||
throw new \Exception();
|
||||
}
|
||||
$storage->save($calendar);
|
||||
}
|
||||
$storage->save($calendar);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -26,9 +26,9 @@ class Taskwarrior implements IStorage {
|
||||
public function refresh() {
|
||||
$output = $this->console->execute('task', ['sync'], null,
|
||||
['TASKRC' => $this->configs['taskrc'],'TASKDATA' => $this->configs['taskdata']]);
|
||||
$tasks = json_decode($this->console->execute('task', ['export'], null,
|
||||
$this->tasks = json_decode($this->console->execute('task', ['export'], null,
|
||||
['TASKRC' => $this->configs['taskrc'], 'TASKDATA' => $this->configs['taskdata']]), true);
|
||||
foreach ($tasks as $task) {
|
||||
foreach ($this->tasks as $task) {
|
||||
if (isset($task['uid'])) {
|
||||
$this->tasks[$task['uid']] = $task;
|
||||
}
|
||||
|
Reference in New Issue
Block a user