|
| 1 | +<?php |
| 2 | +declare(strict_types=1); |
| 3 | + |
| 4 | +namespace Oliverde8\PhpEtlBundle\Command; |
| 5 | + |
| 6 | +use Oliverde8\Component\PhpEtl\Output\MermaidStaticOutput; |
| 7 | +use Oliverde8\PhpEtlBundle\Services\ChainProcessorsManager; |
| 8 | +use Symfony\Component\Console\Command\Command; |
| 9 | +use Symfony\Component\Console\Input\InputArgument; |
| 10 | +use Symfony\Component\Console\Input\InputInterface; |
| 11 | +use Symfony\Component\Console\Input\InputOption; |
| 12 | +use Symfony\Component\Console\Output\OutputInterface; |
| 13 | +use Symfony\Component\Console\Style\SymfonyStyle; |
| 14 | +use Symfony\Component\Yaml\Yaml; |
| 15 | + |
| 16 | +class GetDefinitionGraphCommand extends Command |
| 17 | +{ |
| 18 | + const OPTION_GETURL = 'get-url'; |
| 19 | + |
| 20 | + protected ChainProcessorsManager $chainProcessorsManager; |
| 21 | + |
| 22 | + /** |
| 23 | + * ExecuteCommand constructor. |
| 24 | + * @param ChainProcessorsManager $chainProcessorsManager |
| 25 | + */ |
| 26 | + public function __construct(ChainProcessorsManager $chainProcessorsManager) |
| 27 | + { |
| 28 | + parent::__construct(); |
| 29 | + $this->chainProcessorsManager = $chainProcessorsManager; |
| 30 | + } |
| 31 | + |
| 32 | + |
| 33 | + protected function configure() |
| 34 | + { |
| 35 | + $this->setName("etl:definition:graph"); |
| 36 | + $this->addArgument("name", InputArgument::REQUIRED); |
| 37 | + $this->addOption(self::OPTION_GETURL, 'u', InputOption::VALUE_NONE); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * @throws \Oliverde8\Component\PhpEtl\Exception\ChainOperationException |
| 42 | + */ |
| 43 | + protected function execute(InputInterface $input, OutputInterface $output) |
| 44 | + { |
| 45 | + $sfs = new SymfonyStyle($input, $output); |
| 46 | + |
| 47 | + $chainName = $input->getArgument("name"); |
| 48 | + $processor = $this->chainProcessorsManager->getProcessor($chainName, []); |
| 49 | + |
| 50 | + $mermaidOutput = new MermaidStaticOutput(); |
| 51 | + |
| 52 | + if ($input->getOption(self::OPTION_GETURL)) { |
| 53 | + $graph = $mermaidOutput->generateUrl($processor); |
| 54 | + $sfs->title("Mermaid Graph Url"); |
| 55 | + $output->writeln($graph); |
| 56 | + } else { |
| 57 | + $graph = $mermaidOutput->generateGrapText($processor); |
| 58 | + $sfs->title("Mermaid graph"); |
| 59 | + $output->writeln($graph); |
| 60 | + } |
| 61 | + |
| 62 | + return 0; |
| 63 | + } |
| 64 | +} |
0 commit comments