|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* PHP version 7.1 |
|
4
|
|
|
* |
|
5
|
|
|
* This source file is subject to the license that is bundled with this package in the file LICENSE. |
|
6
|
|
|
*/ |
|
7
|
|
|
namespace PhUml\Processors; |
|
8
|
|
|
|
|
9
|
|
|
use PhUml\Graphviz\ClassGraphElements; |
|
10
|
|
|
use PhUml\Graphviz\Digraph; |
|
11
|
|
|
use PhUml\Graphviz\HtmlLabelStyle; |
|
12
|
|
|
use PhUml\Graphviz\InterfaceGraphElements; |
|
13
|
|
|
use PhUml\Graphviz\NodeLabelBuilder; |
|
14
|
|
|
use plGraphvizProcessorOptions; |
|
15
|
|
|
use plProcessor; |
|
16
|
|
|
use Twig_Environment as TemplateEngine; |
|
17
|
|
|
use Twig_Loader_Filesystem as Filesystem; |
|
18
|
|
|
|
|
19
|
|
|
class GraphvizProcessor extends plProcessor |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var plGraphvizProcessorOptions */ |
|
22
|
|
|
public $options; |
|
23
|
|
|
|
|
24
|
|
|
/** @var Digraph */ |
|
25
|
|
|
private $digraph; |
|
26
|
|
|
|
|
27
|
15 |
|
public function __construct(Digraph $digraph = null) |
|
28
|
|
|
{ |
|
29
|
15 |
|
$this->options = new plGraphvizProcessorOptions(); |
|
30
|
15 |
|
$labelBuilder = new NodeLabelBuilder(new TemplateEngine( |
|
31
|
15 |
|
new FileSystem(__DIR__ . '/../Graphviz/templates') |
|
32
|
15 |
|
), new HtmlLabelStyle()); |
|
33
|
15 |
|
$classElements = new ClassGraphElements($this->options->createAssociations, $labelBuilder); |
|
|
|
|
|
|
34
|
15 |
|
$interfaceElements = new InterfaceGraphElements($labelBuilder); |
|
35
|
15 |
|
$this->digraph = $digraph ?? new Digraph($interfaceElements, $classElements); |
|
36
|
15 |
|
} |
|
37
|
|
|
|
|
38
|
3 |
|
public function name(): string |
|
39
|
|
|
{ |
|
40
|
3 |
|
return 'Graphviz'; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
9 |
|
public function getInputType(): string |
|
44
|
|
|
{ |
|
45
|
9 |
|
return 'application/phuml-structure'; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
3 |
|
public function getOutputType(): string |
|
49
|
|
|
{ |
|
50
|
3 |
|
return 'text/dot'; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
6 |
|
public function process($input) |
|
54
|
|
|
{ |
|
55
|
6 |
|
$this->digraph->fromCodeStructure($input); |
|
56
|
|
|
|
|
57
|
6 |
|
return $this->digraph->toDotLanguage(); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|