From a7355540a6d03cd0f337da68765150043320c16b Mon Sep 17 00:00:00 2001 From: Ivo Marino Date: Sun, 5 Mar 2017 16:59:50 +0100 Subject: [PATCH] First YAML configuration file parsing. --- bin/appflow | 29 ++++++++++++-- src/Appflow/Command/CheckoutCommand.php | 2 +- src/Appflow/Config/Configuration.php | 39 +++++++++++++++++++ ...onfigSourceRC.php => YamlConfigLoader.php} | 13 ++----- 4 files changed, 69 insertions(+), 14 deletions(-) create mode 100644 src/Appflow/Config/Configuration.php rename src/Appflow/Config/{ConfigSourceRC.php => YamlConfigLoader.php} (66%) diff --git a/bin/appflow b/bin/appflow index cd46fd1a..fec37257 100755 --- a/bin/appflow +++ b/bin/appflow @@ -6,6 +6,9 @@ require __DIR__.'/../vendor/autoload.php'; use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Config\FileLocator; +use Symfony\Component\Config\Definition\Processor; +use AppFlow\Config\YamlConfigLoader; +use AppFlow\Config\Configuration; $application = new Application('AppFlow', '1.0.0'); @@ -44,8 +47,28 @@ $application->addCommands(array( // http://symfony.com/doc/current/components/config/resources.html // $configDirectories = array(__DIR__.'/app/config'); -// -// $locator = new FileLocator($configDirectories); -// $yamlUserFiles = $locator->locate('users.yml', null, false); +$configDirectories = array($_SERVER['HOME'] . '/.appflow'); + +// convert the config file into an array +$locator = new FileLocator($configDirectories); +$loader = new YamlConfigLoader($locator); +$configValues = $loader->load($locator->locate('config.yml')); + +// process the array using the defined configuration +$processor = new Processor(); +$configuration = new Configuration(); + +try { + $processedConfiguration = $processor->processConfiguration( + $configuration, + $configValues + ); + + // configuration validated + dump($processedConfiguration); + +} catch (Exception $e) { + echo $e->getMessage() . PHP_EOL; +} $application->run(); diff --git a/src/Appflow/Command/CheckoutCommand.php b/src/Appflow/Command/CheckoutCommand.php index f180d64c..887861e8 100644 --- a/src/Appflow/Command/CheckoutCommand.php +++ b/src/Appflow/Command/CheckoutCommand.php @@ -56,6 +56,6 @@ protected function execute(InputInterface $input, OutputInterface $output) throw new ProcessFailedException($process); } - echo $process->getOutput(); + // echo $process->getOutput(); } } diff --git a/src/Appflow/Config/Configuration.php b/src/Appflow/Config/Configuration.php new file mode 100644 index 00000000..94cc7646 --- /dev/null +++ b/src/Appflow/Config/Configuration.php @@ -0,0 +1,39 @@ + + * Luca Di Maio + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace AppFlow\Config; + +use Symfony\Component\Config\Definition\ConfigurationInterface; +use Symfony\Component\Config\Definition\Builder\TreeBuilder; + +class Configuration implements ConfigurationInterface +{ + public function getConfigTreeBuilder() + { + $treeBuilder = new TreeBuilder(); + $rootNode = $treeBuilder->root('appflow'); + + $rootNode + ->children() + ->arrayNode('tenant') + ->children() + ->scalarNode('id')->end() + ->scalarNode('name')->end() + ->scalarNode('default_env')->end() + ->end() + ->end() + ->end() + ; + + return $treeBuilder; + } +} diff --git a/src/Appflow/Config/ConfigSourceRC.php b/src/Appflow/Config/YamlConfigLoader.php similarity index 66% rename from src/Appflow/Config/ConfigSourceRC.php rename to src/Appflow/Config/YamlConfigLoader.php index 456002ec..f2cd8af4 100644 --- a/src/Appflow/Config/ConfigSourceRC.php +++ b/src/Appflow/Config/YamlConfigLoader.php @@ -10,28 +10,21 @@ * file that was distributed with this source code. */ -namespace AppFlow\Command; +namespace AppFlow\Config; -// use Symfony\Component\Console\Command\Command; -// use Symfony\Component\Console\Input\InputInterface; -// use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Config\Loader\FileLoader; use Symfony\Component\Yaml\Yaml; /** * @author Ivo Marino */ -class ConfigSourceRC extends FileLoader +class YamlConfigLoader extends FileLoader { public function load($resource, $type = null) { $configValues = Yaml::parse(file_get_contents($resource)); - // ... handle the config values - - // maybe import some other resource: - - // $this->import('extra_users.yml'); + return $configValues; } public function supports($resource, $type = null)