diff --git a/src/Command/RenderCommand.php b/src/Command/RenderCommand.php index 43a739ab447e7fffd405773cad2866241bd8e420..dd16e7019fbe23d14ffe087e4e067923d12079e4 100644 --- a/src/Command/RenderCommand.php +++ b/src/Command/RenderCommand.php @@ -29,6 +29,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\Process\ExecutableFinder; /** * Description of ImportAffiliationCommand. @@ -69,7 +70,13 @@ class RenderCommand extends ContainerAwareCommand } } - protected function renderGraph(Graph $graph, $target, $format, SymfonyStyle $io) + /** + * @param Graph $graph + * @param $target + * @param $format + * @param SymfonyStyle $io + */ + private function renderGraph(Graph $graph, $target, $format, SymfonyStyle $io): void { $io->writeln("Fichier de sortie: $target"); @@ -103,20 +110,28 @@ class RenderCommand extends ContainerAwareCommand } } - protected function startProcess($target, $format) + /** + * @param $target + * @param $format + * @return array + */ + 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')); + $fs = new Filesystem(); $fs->mkdir(dirname($target)); - $ctn = $this->getContainer(); $cmd = implode( ' ', [ - $ctn->getParameter('irstea_plant_uml.binaries.java'), + $javaBin, '-jar', $ctn->getParameter('irstea_plant_uml.binaries.plamtuml_jar'), '-graphvizdot', - $ctn->getParameter('irstea_plant_uml.binaries.dot'), + $dotBin, '-pipe', '-t' . $format, ] @@ -136,4 +151,21 @@ class RenderCommand extends ContainerAwareCommand return [$proc, $pipes]; } + + /** + * @param string $nameOrPath + * @return string + */ + private function findExecutable(string $nameOrPath): string + { + if (\file_exists($nameOrPath) && \is_executable($nameOrPath)) { + return $nameOrPath; + } + $exec = new ExecutableFinder(); + $path = $exec->find($nameOrPath); + if ($path === null) { + throw new \RuntimeException("cannot find executable: $nameOrPath"); + } + return $path; + } }