Skip to content

Commit

Permalink
First YAML configuration file parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivomarino committed Mar 5, 2017
1 parent 51527db commit a735554
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 14 deletions.
29 changes: 26 additions & 3 deletions bin/appflow
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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();
2 changes: 1 addition & 1 deletion src/Appflow/Command/CheckoutCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
throw new ProcessFailedException($process);
}

echo $process->getOutput();
// echo $process->getOutput();
}
}
39 changes: 39 additions & 0 deletions src/Appflow/Config/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/*
* This file is part of AppFlow.
*
* (c) Ivo Marino <ivo.marino@ttss.ch>
* Luca Di Maio <luca.dimaio@ttss.ch>
*
* 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ivo.marino@ttss.ch>
*/
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)
Expand Down

0 comments on commit a735554

Please sign in to comment.