feat: Initial commit
This commit is contained in:
47
lib/Configs/ConfigBuilder.php
Normal file
47
lib/Configs/ConfigBuilder.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Aerex\BaikalStorage\Configs;
|
||||
|
||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\Config\Definition\Processor;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class ConfigBuilder implements ConfigurationInterface {
|
||||
private $configs = [];
|
||||
private $configFile;
|
||||
|
||||
public function __construct($configFile = '~/.config/baikal') {
|
||||
$this->configFile = $configFile;
|
||||
$this->processor = new Processor();
|
||||
}
|
||||
|
||||
public function add($config) {
|
||||
$this->configs[] = $config;
|
||||
}
|
||||
|
||||
public function getConfigTreeBuilder() {
|
||||
$treeBuilder = new TreeBuilder('configs');
|
||||
$rootNode = $treeBuilder->getRootNode();
|
||||
$ref = $rootNode->children();
|
||||
foreach ($this->configs as $config) {
|
||||
$ref = $ref->append($config->get());
|
||||
}
|
||||
$ref->end();
|
||||
return $treeBuilder;
|
||||
}
|
||||
|
||||
public function readContent() {
|
||||
if (!is_dir($this->configFile)) {
|
||||
mkdir($this->configFile);
|
||||
}
|
||||
$contents = sprintf('%s/storage.yml', $this->configFile);
|
||||
return file_get_contents($contents);
|
||||
}
|
||||
|
||||
public function loadYaml() {
|
||||
$contents = $this->readContent();
|
||||
$parseContents = Yaml::parse($contents);
|
||||
return $this->processor->processConfiguration($this, [$parseContents]);
|
||||
}
|
||||
}
|
17
lib/Configs/TaskwarriorConfig.php
Normal file
17
lib/Configs/TaskwarriorConfig.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Aerex\BaikalStorage\Configs;
|
||||
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
|
||||
class TaskwarriorConfig {
|
||||
public function get() {
|
||||
$treeBuilder = new TreeBuilder('taskwarrior');
|
||||
$node = $treeBuilder->getRootNode();
|
||||
$node->children()
|
||||
->scalarNode('data_dir')
|
||||
->defaultValue('~/.task')
|
||||
->end();
|
||||
return $node;
|
||||
}
|
||||
}
|
21
lib/Configs/Todotxt.php
Normal file
21
lib/Configs/Todotxt.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Aerex\BaikalStorage\Configs;
|
||||
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
|
||||
class Config extends AbstractConfig {
|
||||
protected function getConfigTree() {
|
||||
$treeBuilder = new TreeBuilder('config');
|
||||
$rootNode = $treeBuilder->getRootNode();
|
||||
|
||||
$rootNode->children
|
||||
->scalarNode('storage')
|
||||
->isRequired()
|
||||
->ifNotInArray(['todotxt'])
|
||||
->thenInvalid('Invalid storage %s')
|
||||
->end();
|
||||
return $treeBuilder;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user