protected function execute(InputInterface $input, OutputInterface $output)
 {
     $configArgument = $input->getArgument('config');
     if (false === file_exists($configArgument)) {
         throw new FileNotFoundException(sprintf('configuration file : "%s" can not be found', $configArgument));
     }
     $output->write('1 - Parse config file : ');
     $parser = new Parser();
     $config = $parser->parse(file_get_contents($configArgument));
     unset($parser);
     $output->writeln('<info>Ok</info>');
     $output->write('2 - Load Resolver and Generators : ');
     $processor = new Processor();
     $workerConfiguration = $processor->process($this->configurationTree->getWorkerTree(), ['root' => $config]);
     $generators = $this->generatorChain->getGenerators($workerConfiguration['generators']);
     $resolvers = $this->resolverChain->getResolvers($workerConfiguration['resolvers']);
     $output->writeln('<info>Ok</info>');
     $output->write('3 - Build configuration tree : ');
     foreach (array_merge($generators, $resolvers) as $worker) {
         if ($worker instanceof TreeConfiguratorInterface) {
             $this->configurationTree->addTreeConfigurator($worker);
         }
     }
     $output->writeln('<info>Ok</info>');
     $dumper = new YamlReferenceDumper();
     echo $dumper->dump($this->configurationTree);
 }
Exemplo n.º 2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $configArgument = $input->getArgument('config');
     if (false === file_exists($configArgument)) {
         throw new FileNotFoundException(sprintf('configuration file : "%s" can not be found', $configArgument));
     }
     $output->write('1 - Parse config file : ');
     $parser = new Parser();
     $config = $parser->parse(file_get_contents($configArgument));
     unset($parser);
     $output->writeln('<info>Ok</info>');
     $output->write('2 - Load Resolver and Generators : ');
     $processor = new Processor();
     $workerConfiguration = $processor->process($this->configurationTree->getWorkerTree(), ['root' => $config]);
     $generators = $this->generatorChain->getGenerators($workerConfiguration['generators']);
     $resolvers = $this->resolverChain->getResolvers($workerConfiguration['resolvers']);
     $fileContainer = new FileContainer();
     $output->writeln('<info>Ok</info>');
     $output->write('3 - Check configuration : ');
     foreach (array_merge($generators, $resolvers) as $worker) {
         if ($worker instanceof TreeConfiguratorInterface) {
             $this->configurationTree->addTreeConfigurator($worker);
         }
     }
     $processedConfiguration = $processor->processConfiguration($this->configurationTree, ['root' => $config]);
     $output->writeln('<info>Ok</info>');
     $output->writeln('4 - Process each resolver');
     foreach ($resolvers as $resolver) {
         $output->write('  |-' . basename(get_class($resolver)) . ' : ');
         $processedConfiguration = $resolver->resolve($processedConfiguration);
         $output->writeln('<info>Ok</info>');
     }
     $output->write('5 - Check resolved configuration : ');
     $finalConfiguration = $processor->processConfiguration($this->configurationTree, ['root' => $processedConfiguration]);
     $output->writeln('<info>Ok</info>');
     $output->writeln('6 - Process each Generator');
     foreach ($generators as $generator) {
         $output->write('  |-' . basename(get_class($generator)) . ' : ');
         $generator->generate($finalConfiguration, $fileContainer);
         $output->writeln('<info>Ok</info>');
     }
     $output->write('7 - Create File : ');
     foreach ($fileContainer->getFiles() as $file) {
         //todo : do somethings to manage how file is render (twig is not only way)
         $fileContent = $this->twig->render($file->getRenderTemplate(), ['globalConfig' => $finalConfiguration, 'file' => $file]);
         $this->generateDirecory(dirname($file->getFilePath()));
         file_put_contents($file->getFilePath(), $fileContent);
     }
     $output->writeln('<info>Ok</info>');
     $output->write('8 - Fix Coding style : ');
     $this->fixCs($fileContainer);
     $output->writeln('<info>Ok</info>');
     $output->writeln('<comment>Warning : Coding style fixer is partial, use your IDE to fix correctly.</comment>');
 }