Skip to content

Commit

Permalink
Merge pull request #5 from jawira/4-search-plantuml-in-path
Browse files Browse the repository at this point in the history
feat: Checks if PlantUml is installed as Path variable
  • Loading branch information
jawira authored Oct 14, 2022
2 parents e16b195 + c7913ce commit 28f63d0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
20 changes: 19 additions & 1 deletion src/PlantUml.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ public function setJar(string $path): self

/**
* Convert diagram into requested format.
*
* @param string $diagram This is the diagram to be converted, you must provide the diagram itself and not a file
* path. Otherwise, it's up to you to load that file into a variable.
* @param string $format Must be a valid PlantUml format: `png`, `svg`, `eps`, `txt`, ...
* @throws \Jawira\PlantUmlToImage\PlantUmlException
*/
public function convertTo(string $diagram, string $format): string
{
Expand All @@ -50,6 +52,7 @@ public function convertTo(string $diagram, string $format): string
* Returns PlantUml Jar or Executable, if not found `plantuml` is returned by default.
*
* @return string[]
* @throws \Jawira\PlantUmlToImage\PlantUmlException
*/
protected function findPlantUml(): array
{
Expand All @@ -65,7 +68,7 @@ protected function findPlantUml(): array
return $candidate;
}

return ['plantuml'];
throw new PlantUmlException('Cannot found PlantUml, try installing `plantuml/jawira`.');
}

/**
Expand Down Expand Up @@ -131,6 +134,21 @@ protected function findExecutable(): ?array
return [$candidate];
}

if ($this->isPlantUmlInPath()) {
return ['plantuml'];
}

return null;
}

/**
* Checks `plantuml` is located as path variable.
*/
protected function isPlantUmlInPath(): bool
{
$process = Process::fromShellCommandline('plantuml -help');
$process->run();

return 0 === $process->getExitCode();
}
}
9 changes: 9 additions & 0 deletions src/PlantUmlException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php declare(strict_types=1);

namespace Jawira\PlantUmlToImage;

use Exception;

class PlantUmlException extends Exception
{
}
4 changes: 3 additions & 1 deletion tests/ProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ class ProcessTest extends TestCase
{
/**
* @dataProvider svgConversionProvider
* @covers \Jawira\PlantUmlToImage\PlantUmlProcess::convertTo
* @covers \Jawira\PlantUmlToImage\PlantUml::convertTo
* @covers \Jawira\PlantUmlToImage\PlantUml::findJar
* @covers \Jawira\PlantUmlToImage\PlantUml::findPlantUml
* @testdox Svg from $filePath contains '$needle' .
*/
function testSvgConversion($filePath, $needle, $bytes)
Expand Down

0 comments on commit 28f63d0

Please sign in to comment.