-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #603 from phpDocumentor/feat/plantuml-rendering
Feat: Add plantuml server rendering
- Loading branch information
Showing
12 changed files
with
217 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
37 changes: 37 additions & 0 deletions
37
packages/guides-graphs/src/Graphs/DependencyInjection/Configuration.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace phpDocumentor\Guides\Graphs\DependencyInjection; | ||
|
||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | ||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
|
||
use function assert; | ||
|
||
class Configuration implements ConfigurationInterface | ||
{ | ||
public function getConfigTreeBuilder(): TreeBuilder | ||
{ | ||
$treeBuilder = new TreeBuilder('Graphs'); | ||
$rootNode = $treeBuilder->getRootNode(); | ||
assert($rootNode instanceof ArrayNodeDefinition); | ||
|
||
$rootNode->children() | ||
->scalarNode('renderer') | ||
->defaultValue('plantuml-server') | ||
->info('Render engine to use for generating graphs') | ||
->end() | ||
->scalarNode('plantuml_server') | ||
->defaultValue('https://www.plantuml.com/plantuml') | ||
->info('URL of the PlantUML server to use') | ||
->end() | ||
->scalarNode('plantuml_binary') | ||
->defaultValue('plantuml') | ||
->info('Path to your local PlantUML binary') | ||
->end(); | ||
|
||
return $treeBuilder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
packages/guides-graphs/src/Graphs/Renderer/PlantumlServerRenderer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace phpDocumentor\Guides\Graphs\Renderer; | ||
|
||
use Psr\Log\LoggerInterface; | ||
use Symfony\Contracts\HttpClient\HttpClientInterface; | ||
|
||
use function Jawira\PlantUml\encodep; | ||
|
||
final class PlantumlServerRenderer implements DiagramRenderer | ||
{ | ||
public function __construct( | ||
private readonly HttpClientInterface $httpClient, | ||
private readonly string $plantumlServerUrl, | ||
private readonly LoggerInterface $logger, | ||
) { | ||
} | ||
|
||
public function render(string $diagram): string|null | ||
{ | ||
$encodedDiagram = encodep($diagram); | ||
|
||
$response = $this->httpClient->request( | ||
'GET', | ||
$this->plantumlServerUrl . '/svg/' . $encodedDiagram, | ||
); | ||
|
||
if ($response->getStatusCode() !== 200) { | ||
$this->logger->error('Failed to render diagram using server:' . $this->plantumlServerUrl); | ||
|
||
return null; | ||
} | ||
|
||
return $response->getContent(); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/Integration/tests/graphs/plantuml-inline/expected/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>Uml Directive</title> | ||
|
||
</head> | ||
<body> | ||
<div class="section" id="uml-directive"> | ||
<h1>Uml Directive</h1> | ||
|
||
<figure | ||
class="uml-diagram" | ||
><?xml version="1.0" encoding="us-ascii" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentStyleType="text/css" height="120px" preserveAspectRatio="none" style="width:163px;height:120px;background:#FFFFFF;" version="1.1" viewBox="0 0 163 120" width="163px" zoomAndPan="magnify"><defs/><g><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="29" x2="29" y1="36.2969" y2="85.4297"/><line style="stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;" x1="112" x2="112" y1="36.2969" y2="85.4297"/><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="48" x="5" y="5"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="34" x="12" y="24.9951">class</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="48" x="5" y="84.4297"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="34" x="12" y="104.4248">class</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="90" x="67" y="5"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="76" x="74" y="24.9951">otherClass</text><rect fill="#E2E2F0" height="30.2969" rx="2.5" ry="2.5" style="stroke:#181818;stroke-width:0.5;" width="90" x="67" y="84.4297"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacing" textLength="76" x="74" y="104.4248">otherClass</text><polygon fill="#181818" points="100,63.4297,110,67.4297,100,71.4297,104,67.4297" style="stroke:#181818;stroke-width:1.0;"/><line style="stroke:#181818;stroke-width:1.0;" x1="29" x2="106" y1="67.4297" y2="67.4297"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacing" textLength="59" x="36" y="62.3638">message</text><!--SRC=[Iyv9B2vMqBLJo2_9I2ro1lEi579JYuiJqrC1]--></g></svg></figure> | ||
</div> | ||
|
||
</body> | ||
</html> |
9 changes: 9 additions & 0 deletions
9
tests/Integration/tests/graphs/plantuml-inline/input/guides.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<guides xmlns="https://www.phpdoc.org/guides" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="https://www.phpdoc.org/guides packages/guides-cli/resources/schema/guides.xsd"> | ||
<extension class="phpDocumentor\Guides\Graphs"> | ||
<renderer>plantuml-server</renderer> | ||
<plantuml-binary>/usr/bin/plantuml</plantuml-binary> | ||
</extension> | ||
</guides> |
7 changes: 7 additions & 0 deletions
7
tests/Integration/tests/graphs/plantuml-inline/input/index.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
============== | ||
Uml Directive | ||
============== | ||
|
||
.. uml:: | ||
|
||
class -> otherClass : message |