diff --git a/Command/GoogleTranslateCommand.php b/Command/GoogleTranslateCommand.php index 440ecbf..fb7181a 100644 --- a/Command/GoogleTranslateCommand.php +++ b/Command/GoogleTranslateCommand.php @@ -75,7 +75,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $file = $basePath . '/' . $messageToFileName; $messagesTo = $this->ksortRecursive($messagesTo); - file_put_contents($file, Yaml::dump($messagesTo, 100500)); + $yamlIndent = $this->getContainer()->getParameter('exercise_google_translate.yaml_indent'); + file_put_contents($file, Yaml::dump($messagesTo, 100500, $yamlIndent)); } } } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 1e0d63d..226f450 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -20,13 +20,25 @@ public function getConfigTreeBuilder() $treeBuilder = new TreeBuilder(); $rootNode = $treeBuilder->root('exercise_google_translate'); + $yamlIndent = array(2, 4); + $rootNode ->children() + ->scalarNode('api_key') ->isRequired() ->cannotBeEmpty() ->info('key for your app https://code.google.com/apis/console/b/0/?pli=1#project:247987860421:access') ->end() + + ->scalarNode('yaml_indent') + ->cannotBeEmpty() + ->defaultValue(4) + ->validate() + ->ifNotInArray($yamlIndent) + ->thenInvalid('The input type "%s" is not supported. Please use one of the following values: '.implode(', ', $yamlIndent)) + ->end() + ->end() ; diff --git a/DependencyInjection/ExerciseGoogleTranslateExtension.php b/DependencyInjection/ExerciseGoogleTranslateExtension.php index d6fae30..84e74da 100644 --- a/DependencyInjection/ExerciseGoogleTranslateExtension.php +++ b/DependencyInjection/ExerciseGoogleTranslateExtension.php @@ -24,6 +24,7 @@ public function load(array $configs, ContainerBuilder $container) $rootNode = $configuration->getConfigTreeBuilder()->buildTree()->getName(); $container->setParameter($rootNode.'.api_key', $config['api_key']); + $container->setParameter($rootNode.'.yaml_indent', $config['yaml_indent']); $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.xml'); diff --git a/Tests/App/config.yml b/Tests/App/config.yml index b8b4b83..5bfdb8a 100644 --- a/Tests/App/config.yml +++ b/Tests/App/config.yml @@ -4,3 +4,4 @@ framework: exercise_google_translate: api_key: thisistestapikey + yaml_indent: 4