|
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\Configuration; |
|
9
|
|
|
|
|
10
|
|
|
use PhUml\Graphviz\Builders\ClassGraphBuilder; |
|
11
|
|
|
use PhUml\Graphviz\Builders\EdgesBuilder; |
|
12
|
|
|
use PhUml\Graphviz\Builders\InterfaceGraphBuilder; |
|
13
|
|
|
use PhUml\Graphviz\Builders\NoAssociationsBuilder; |
|
14
|
|
|
use PhUml\Graphviz\DigraphPrinter; |
|
15
|
|
|
use PhUml\Graphviz\Styles\DefaultDigraphStyle; |
|
16
|
|
|
use PhUml\Graphviz\Styles\DigraphStyle; |
|
17
|
|
|
use PhUml\Graphviz\Styles\NonEmptyBlocksStyle; |
|
18
|
|
|
use PhUml\Parser\CodeFinder; |
|
19
|
|
|
use PhUml\Parser\CodeParser; |
|
20
|
|
|
use PhUml\Parser\NonRecursiveCodeFinder; |
|
21
|
|
|
use PhUml\Parser\Raw\ParserBuilder; |
|
22
|
|
|
use PhUml\Parser\Raw\PhpParser; |
|
23
|
|
|
use PhUml\Parser\CodebaseBuilder; |
|
24
|
|
|
use PhUml\Processors\GraphvizProcessor; |
|
25
|
|
|
use PhUml\Templates\TemplateEngine; |
|
26
|
|
|
|
|
27
|
|
|
class DigraphBuilder |
|
28
|
|
|
{ |
|
29
|
|
|
/** @var DigraphConfiguration */ |
|
30
|
|
|
protected $configuration; |
|
31
|
|
|
|
|
32
|
|
|
/** @var ParserBuilder */ |
|
33
|
|
|
protected $parserBuilder; |
|
34
|
|
|
|
|
35
|
33 |
|
public function __construct() |
|
36
|
|
|
{ |
|
37
|
33 |
|
$this->parserBuilder = new ParserBuilder(); |
|
38
|
33 |
|
} |
|
39
|
|
|
|
|
40
|
33 |
|
public function codeFinder(): CodeFinder |
|
41
|
|
|
{ |
|
42
|
33 |
|
return $this->configuration->searchRecursively() ? new CodeFinder() : new NonRecursiveCodeFinder(); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
30 |
|
protected function digraphProcessor(): GraphvizProcessor |
|
46
|
|
|
{ |
|
47
|
30 |
|
$associationsBuilder = $this->configuration->extractAssociations() ? new EdgesBuilder() : new NoAssociationsBuilder(); |
|
48
|
30 |
|
return new GraphvizProcessor( |
|
49
|
30 |
|
new ClassGraphBuilder($associationsBuilder), |
|
50
|
30 |
|
new InterfaceGraphBuilder(), |
|
51
|
30 |
|
new DigraphPrinter(new TemplateEngine(), $this->digraphStyle()) |
|
52
|
|
|
); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
30 |
|
protected function digraphStyle(): DigraphStyle |
|
56
|
|
|
{ |
|
57
|
30 |
|
if ($this->configuration->hideEmptyBlocks()) { |
|
58
|
6 |
|
return new NonEmptyBlocksStyle($this->configuration->theme()); |
|
59
|
|
|
} |
|
60
|
24 |
|
return new DefaultDigraphStyle($this->configuration->theme()); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
30 |
|
protected function codeParser(): CodeParser |
|
64
|
|
|
{ |
|
65
|
30 |
|
return new CodeParser(new CodebaseBuilder(), $this->tokenParser()); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
30 |
|
protected function tokenParser(): PhpParser |
|
69
|
|
|
{ |
|
70
|
30 |
|
$this->configureAttributes(); |
|
71
|
30 |
|
$this->configureMethods(); |
|
72
|
30 |
|
$this->configureFilters(); |
|
73
|
30 |
|
return $this->parserBuilder->build(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
30 |
|
private function configureAttributes(): void |
|
77
|
|
|
{ |
|
78
|
30 |
|
if ($this->configuration->hideAttributes()) { |
|
79
|
9 |
|
$this->parserBuilder->excludeAttributes(); |
|
80
|
|
|
} |
|
81
|
30 |
|
} |
|
82
|
|
|
|
|
83
|
30 |
|
private function configureMethods(): void |
|
84
|
|
|
{ |
|
85
|
30 |
|
if ($this->configuration->hideMethods()) { |
|
86
|
9 |
|
$this->parserBuilder->excludeMethods(); |
|
87
|
|
|
} |
|
88
|
30 |
|
} |
|
89
|
|
|
|
|
90
|
30 |
|
private function configureFilters(): void |
|
91
|
|
|
{ |
|
92
|
30 |
|
if ($this->configuration->hidePrivate()) { |
|
93
|
6 |
|
$this->parserBuilder->excludePrivateMembers(); |
|
94
|
|
|
} |
|
95
|
30 |
|
if ($this->configuration->hideProtected()) { |
|
96
|
6 |
|
$this->parserBuilder->excludeProtectedMembers(); |
|
97
|
|
|
} |
|
98
|
30 |
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|