|
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
|
|
|
|
|
8
|
|
|
namespace PhUml\Processors; |
|
9
|
|
|
|
|
10
|
|
|
use PhUml\Code\ClassDefinition; |
|
11
|
|
|
use PhUml\Code\Definition; |
|
12
|
|
|
use PhUml\Code\InterfaceDefinition; |
|
13
|
|
|
use PhUml\Code\Codebase; |
|
14
|
|
|
use PhUml\Graphviz\Builders\ClassGraphBuilder; |
|
15
|
|
|
use PhUml\Graphviz\Builders\InterfaceGraphBuilder; |
|
16
|
|
|
use PhUml\Graphviz\Digraph; |
|
17
|
|
|
use PhUml\Graphviz\DigraphPrinter; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* It creates a digraph from a `Structure` and returns it as a string in DOT format |
|
21
|
|
|
*/ |
|
22
|
|
|
class GraphvizProcessor extends Processor |
|
23
|
|
|
{ |
|
24
|
|
|
/** @var ClassGraphBuilder */ |
|
25
|
|
|
private $classBuilder; |
|
26
|
|
|
|
|
27
|
|
|
/** @var InterfaceGraphBuilder */ |
|
28
|
|
|
private $interfaceBuilder; |
|
29
|
|
|
|
|
30
|
|
|
/** @var DigraphPrinter */ |
|
31
|
|
|
private $printer; |
|
32
|
|
|
|
|
33
|
72 |
|
public function __construct( |
|
34
|
|
|
ClassGraphBuilder $classBuilder = null, |
|
35
|
|
|
InterfaceGraphBuilder $interfaceBuilder = null, |
|
36
|
|
|
DigraphPrinter $printer = null |
|
37
|
|
|
) { |
|
38
|
72 |
|
$this->classBuilder = $classBuilder ?? new ClassGraphBuilder(); |
|
39
|
72 |
|
$this->interfaceBuilder = $interfaceBuilder ?? new InterfaceGraphBuilder(); |
|
40
|
72 |
|
$this->printer = $printer ?? new DigraphPrinter(); |
|
41
|
72 |
|
} |
|
42
|
|
|
|
|
43
|
30 |
|
public function name(): string |
|
44
|
|
|
{ |
|
45
|
30 |
|
return 'Graphviz'; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
57 |
|
public function process(Codebase $codebase): string |
|
49
|
|
|
{ |
|
50
|
57 |
|
$digraph = new Digraph(); |
|
51
|
57 |
|
foreach ($codebase->definitions() as $definition) { |
|
52
|
54 |
|
$this->extractElements($definition, $codebase, $digraph); |
|
53
|
|
|
} |
|
54
|
57 |
|
return $this->printer->toDot($digraph); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
54 |
|
protected function extractElements( |
|
58
|
|
|
Definition $definition, |
|
59
|
|
|
Codebase $codebase, |
|
60
|
|
|
Digraph $digraph |
|
61
|
|
|
): void { |
|
62
|
54 |
|
if ($definition instanceof ClassDefinition) { |
|
63
|
54 |
|
$digraph->add($this->classBuilder->extractFrom($definition, $codebase)); |
|
64
|
36 |
|
} elseif ($definition instanceof InterfaceDefinition) { |
|
65
|
36 |
|
$digraph->add($this->interfaceBuilder->extractFrom($definition)); |
|
66
|
|
|
} |
|
67
|
54 |
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|