An error occurred while loading the file. Please try again.
-
Raidelet Nicolas authored7b889ef8
<?php declare(strict_types=1);
/*
* Copyright (C) 2016-2017 IRSTEA
* All rights reserved.
*/
namespace Irstea\PlantUmlBundle\Command;
use Irstea\PlantUmlBundle\Model\Graph;
use Irstea\PlantUmlBundle\Writer\StreamWriter;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Filesystem\Filesystem;
/**
* Description of ImportAffiliationCommand.
*/
class RenderCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('irstea:plantuml:render')
->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')
->addArgument('graph', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'Graphe à générer');
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @SuppressWarnings(UnusedFormalParameter)
*/
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');
$io = new SymfonyStyle($input, $output);
foreach ($graphs as $name) {
$target = $outputDir . DIRECTORY_SEPARATOR . $name . '.' . $format;
$io->section("Graphe: $name");
$graph = $this->getContainer()->get("irstea_plant_uml.graph.$name");
$this->renderGraph($graph, $target, $format, $io);
}
}
protected function renderGraph(Graph $graph, $target, $format, SymfonyStyle $io)
{
$io->writeln("Fichier de sortie: <comment>$target</comment>");
if (OutputInterface::VERBOSITY_VERY_VERBOSE <= $io->getVerbosity()) {
$desc = [];
$graph->toConfig($desc);
$io->writeln(json_encode($desc, JSON_PRETTY_PRINT));
}
$io->write('Exploration des classes: ');
$graph->visitAll();
$io->writeln('<info>Ok</info>.');
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
$io->write('Démarrage de PlantUML: ');
list($proc, $pipes) = $this->startProcess($target, $format);
$io->writeln('<info>Ok</info>.');
$io->write('Génération du graphe: ');
$writer = new StreamWriter($pipes[0]);
$graph->writeTo($writer);
fclose($pipes[0]);
$io->writeln('<info>Ok</info>.');
$io->write('Rendu graphique par PlantUML: ');
$res = proc_close($proc);
if ($res === 0) {
$io->writeln('<info>Ok</info>.');
} else {
$io->writeln('<error>Nok</error>.');
}
}
protected function startProcess($target, $format)
{
$fs = new Filesystem();
$fs->mkdir(dirname($target));
$ctn = $this->getContainer();
$cmd = implode(
' ',
[
$ctn->getParameter('irstea_plant_uml.binaries.java'),
'-jar',
$ctn->getParameter('irstea_plant_uml.binaries.plamtuml_jar'),
'-graphvizdot',
$ctn->getParameter('irstea_plant_uml.binaries.dot'),
'-pipe',
'-t' . $format,
]
);
$desc = [
// stdin
['pipe', 'r'],
// stdout
['file', $target, 'wt'],
// stderr
STDERR,
];
$pipes = [];
$proc = proc_open($cmd, $desc, $pipes);
return [$proc, $pipes];
}
}