|
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\DefaultLabelStyle; |
|
12
|
|
|
use PhUml\Graphviz\Builders\EdgesBuilder; |
|
13
|
|
|
use PhUml\Graphviz\Builders\NoAssociationsBuilder; |
|
14
|
|
|
use PhUml\Graphviz\Builders\NodeLabelBuilder; |
|
15
|
|
|
use PhUml\Graphviz\Builders\NodeLabelStyle; |
|
16
|
|
|
use PhUml\Graphviz\Builders\NonEmptyBlocksLabelStyle; |
|
17
|
|
|
use PhUml\Parser\CodeFinder; |
|
18
|
|
|
use PhUml\Parser\CodeParser; |
|
19
|
|
|
use PhUml\Parser\NonRecursiveCodeFinder; |
|
20
|
|
|
use PhUml\Parser\Raw\Builders\AttributesBuilder; |
|
21
|
|
|
use PhUml\Parser\Raw\Builders\Filters\MembersFilter; |
|
22
|
|
|
use PhUml\Parser\Raw\Builders\Filters\PrivateMembersFilter; |
|
23
|
|
|
use PhUml\Parser\Raw\Builders\Filters\ProtectedMembersFilter; |
|
24
|
|
|
use PhUml\Parser\Raw\Builders\MethodsBuilder; |
|
25
|
|
|
use PhUml\Parser\Raw\Builders\NoAttributesBuilder; |
|
26
|
|
|
use PhUml\Parser\Raw\Builders\NoMethodsBuilder; |
|
27
|
|
|
use PhUml\Parser\Raw\Builders\RawClassBuilder; |
|
28
|
|
|
use PhUml\Parser\Raw\Builders\RawInterfaceBuilder; |
|
29
|
|
|
use PhUml\Parser\Raw\Php5Parser; |
|
30
|
|
|
use PhUml\Parser\Raw\PhpParser; |
|
31
|
|
|
use PhUml\Parser\StructureBuilder; |
|
32
|
|
|
use PhUml\Processors\GraphvizProcessor; |
|
33
|
|
|
use PhUml\Templates\TemplateEngine; |
|
34
|
|
|
|
|
35
|
|
|
class DigraphBuilder |
|
36
|
|
|
{ |
|
37
|
|
|
/** @var DigraphConfiguration */ |
|
38
|
|
|
protected $configuration; |
|
39
|
|
|
|
|
40
|
30 |
|
public function codeFinder(): CodeFinder |
|
41
|
|
|
{ |
|
42
|
30 |
|
return $this->configuration->searchRecursively() ? new CodeFinder() : new NonRecursiveCodeFinder(); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
27 |
|
protected function digraphProcessor(): GraphvizProcessor |
|
46
|
|
|
{ |
|
47
|
27 |
|
$associationsBuilder = $this->configuration->extractAssociations() ? new EdgesBuilder() : new NoAssociationsBuilder(); |
|
48
|
27 |
|
$digraphProcessor = new GraphvizProcessor( |
|
49
|
27 |
|
new ClassGraphBuilder($this->nodeLabelBuilder(), $associationsBuilder) |
|
50
|
|
|
); |
|
51
|
27 |
|
return $digraphProcessor; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
27 |
|
protected function nodeLabelBuilder(): NodeLabelBuilder |
|
55
|
|
|
{ |
|
56
|
27 |
|
return new NodeLabelBuilder(new TemplateEngine(), $this->nodeLabelStyle()); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
27 |
|
protected function nodeLabelStyle(): NodeLabelStyle |
|
60
|
|
|
{ |
|
61
|
27 |
|
return $this->configuration->hideEmptyBlocks() ? new NonEmptyBlocksLabelStyle() : new DefaultLabelStyle(); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
27 |
|
protected function codeParser(): CodeParser |
|
65
|
|
|
{ |
|
66
|
27 |
|
return new CodeParser(new StructureBuilder(), $this->tokenParser()); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
27 |
|
protected function tokenParser(): PhpParser |
|
70
|
|
|
{ |
|
71
|
27 |
|
return new Php5Parser( |
|
72
|
27 |
|
new RawClassBuilder($this->attributesBuilder(), $this->methodsBuilder()), |
|
73
|
27 |
|
new RawInterfaceBuilder($this->methodsBuilder()) |
|
74
|
|
|
); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
27 |
|
private function attributesBuilder(): AttributesBuilder |
|
78
|
|
|
{ |
|
79
|
27 |
|
if ($this->configuration->hideAttributes()) { |
|
80
|
6 |
|
return new NoAttributesBuilder(); |
|
81
|
|
|
} |
|
82
|
21 |
|
return new AttributesBuilder($this->filters()); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
27 |
|
private function methodsBuilder(): MethodsBuilder |
|
86
|
|
|
{ |
|
87
|
27 |
|
if ($this->configuration->hideMethods()) { |
|
88
|
6 |
|
return new NoMethodsBuilder(); |
|
89
|
|
|
} |
|
90
|
21 |
|
return new MethodsBuilder($this->filters()); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** @return MembersFilter[] */ |
|
94
|
21 |
|
protected function filters(): array |
|
95
|
|
|
{ |
|
96
|
21 |
|
$filters = []; |
|
97
|
21 |
|
if ($this->configuration->hidePrivate()) { |
|
98
|
6 |
|
$filters[] = new PrivateMembersFilter(); |
|
99
|
|
|
} |
|
100
|
21 |
|
if ($this->configuration->hideProtected()) { |
|
101
|
6 |
|
$filters[] = new ProtectedMembersFilter(); |
|
102
|
|
|
} |
|
103
|
21 |
|
return $filters; |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|