Commit 6b09c22c authored by Guillaume Perréal's avatar Guillaume Perréal

Léger refactoring de la RenderCommand.

parent ba187cf5
......@@ -22,7 +22,8 @@ namespace Irstea\PlantUmlBundle\Command;
use Irstea\PlantUmlBundle\Model\Graph;
use Irstea\PlantUmlBundle\Writer\StreamWriter;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Psr\Container\ContainerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
......@@ -34,12 +35,76 @@ use Symfony\Component\Process\ExecutableFinder;
/**
* Description of ImportAffiliationCommand.
*/
class RenderCommand extends ContainerAwareCommand
class RenderCommand extends Command
{
protected function configure()
/**
* @var string
*/
private const CMD_NAME = 'irstea:plantuml:render';
/**
* @var ContainerInterface
*/
private $container;
/**
* @var string[]
*/
private $graphNames;
/**
* @var string
*/
private $defaultFormat;
/**
* @var string
*/
private $defaultOutput;
/**
* @var string
*/
private $javaBinary;
/**
* @var string
*/
private $plantUmlJar;
/**
* @var string
*/
private $dotBinary;
/**
* RenderCommand constructor.
* @param ContainerInterface $container
* @param array $graphNames
* @param string $defaultFormat
* @param string $defaultOutput
* @param string $javaBinary
* @param string $plantUmlJar
* @param string $dotBinary
*/
public function __construct(ContainerInterface $container, array $graphNames, string $defaultFormat, string $defaultOutput, string $javaBinary, string $plantUmlJar, string $dotBinary)
{
parent::__construct(self::CMD_NAME);
$this->container = $container;
$this->graphNames = $graphNames;
$this->defaultFormat = $defaultFormat;
$this->defaultOutput = $defaultOutput;
$this->javaBinary = $javaBinary;
$this->plantUmlJar = $plantUmlJar;
$this->dotBinary = $dotBinary;
}
/**
* {@inheritDoc}
*/
protected function configure(): void
{
$this
->setName('irstea:plantuml:render')
->setName(self::CMD_NAME)
->setDescription("Créer la page d'un graphe ou plusieurs graphes.")
->addOption('output', 'o', InputOption::VALUE_REQUIRED, 'Répertoire de destination.')
->addOption('format', 'f', InputOption::VALUE_REQUIRED, 'Format du fichier à générer')
......@@ -47,15 +112,13 @@ class RenderCommand extends ContainerAwareCommand
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @SuppressWarnings(UnusedFormalParameter)
* {@inheritDoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$graphs = $input->getArgument('graph') ?: $this->getContainer()->getParameter('irstea_plant_uml.graph_keys');
$format = $input->getOption('format') ?: $this->getContainer()->getParameter('irstea_plant_uml.output.format');
$outputDir = $input->getOption('output') ?: $this->getContainer()->getParameter('irstea_plant_uml.output.directory');
$graphs = $input->getArgument('graph') ?: $this->graphNames;
$format = $input->getOption('format') ?: $this->defaultFormat;
$outputDir = $input->getOption('output') ?: $this->defaultOutput;
$io = new SymfonyStyle($input, $output);
......@@ -64,7 +127,7 @@ class RenderCommand extends ContainerAwareCommand
$io->section("Graphe: $name");
$graph = $this->getContainer()->get("irstea_plant_uml.graph.$name");
$graph = $this->container->get("irstea_plant_uml.graph.$name");
$this->renderGraph($graph, $target, $format, $io);
}
......@@ -117,26 +180,16 @@ class RenderCommand extends ContainerAwareCommand
*/
private function startProcess($target, $format): array
{
$ctn = $this->getContainer();
$javaBin = $this->findExecutable($ctn->getParameter('irstea_plant_uml.binaries.java'));
$dotBin = $this->findExecutable($ctn->getParameter('irstea_plant_uml.binaries.dot'));
$cmd = sprintf('%s -jar %s -graphvizdot %s -pipe -t %s',
$this->findExecutable($this->javaBinary),
$this->plantUmlJar,
$this->findExecutable($this->dotBinary),
$format
);
$fs = new Filesystem();
$fs->mkdir(dirname($target));
$cmd = implode(
' ',
[
$javaBin,
'-jar',
$ctn->getParameter('irstea_plant_uml.binaries.plamtuml_jar'),
'-graphvizdot',
$dotBin,
'-pipe',
'-t' . $format,
]
);
$desc = [
// stdin
['pipe', 'r'],
......
......@@ -88,6 +88,14 @@ services:
class: Irstea\PlantUmlBundle\Command\RenderCommand
lazy: true
public: false
arguments:
- '@service_container'
- '%irstea_plant_uml.graph_keys%'
- '%irstea_plant_uml.output.format%'
- '%irstea_plant_uml.output.directory%'
- '%irstea_plant_uml.binaries.java%'
- '%irstea_plant_uml.binaries.plamtuml_jar%'
- '%irstea_plant_uml.binaries.dot%'
tags:
- { name: console.command }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment