1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/** |
3
|
|
|
* PHP version 7.4 |
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\Builders\TraitGraphBuilder; |
15
|
|
|
use PhUml\Graphviz\DigraphPrinter; |
16
|
|
|
use PhUml\Graphviz\Styles\DigraphStyle; |
17
|
|
|
use PhUml\Parser\Code\ExternalAssociationsResolver; |
18
|
|
|
use PhUml\Parser\Code\ExternalDefinitionsResolver; |
19
|
|
|
use PhUml\Parser\Code\ParserBuilder; |
20
|
|
|
use PhUml\Parser\Code\PhpCodeParser; |
21
|
|
|
use PhUml\Parser\Code\RelationshipsResolver; |
22
|
|
|
use PhUml\Parser\CodebaseDirectory; |
23
|
|
|
use PhUml\Parser\CodeFinder; |
24
|
|
|
use PhUml\Parser\CodeParser; |
25
|
|
|
use PhUml\Parser\SourceCodeFinder; |
26
|
|
|
use PhUml\Processors\GraphvizProcessor; |
27
|
|
|
use PhUml\Templates\TemplateEngine; |
28
|
|
|
|
29
|
|
|
final class DigraphBuilder |
30
|
|
|
{ |
31
|
|
|
private DigraphConfiguration $configuration; |
32
|
|
|
|
33
|
|
|
public function __construct(DigraphConfiguration $configuration) |
34
|
|
|
{ |
35
|
|
|
$this->configuration = $configuration; |
36
|
|
|
} |
37
|
33 |
|
|
38
|
|
|
public function codeFinder(CodebaseDirectory $directory): CodeFinder |
39
|
33 |
|
{ |
40
|
33 |
|
return $this->configuration->searchRecursively() |
41
|
|
|
? SourceCodeFinder::recursive($directory) |
42
|
33 |
|
: SourceCodeFinder::nonRecursive($directory); |
43
|
|
|
} |
44
|
33 |
|
|
45
|
|
|
public function digraphProcessor(): GraphvizProcessor |
46
|
|
|
{ |
47
|
30 |
|
$associationsBuilder = $this->configuration->extractAssociations() |
48
|
|
|
? new EdgesBuilder() |
49
|
30 |
|
: new NoAssociationsBuilder(); |
50
|
30 |
|
|
51
|
30 |
|
return new GraphvizProcessor( |
52
|
30 |
|
new ClassGraphBuilder($associationsBuilder), |
53
|
30 |
|
new InterfaceGraphBuilder(), |
54
|
30 |
|
new TraitGraphBuilder(), |
55
|
|
|
new DigraphPrinter(new TemplateEngine(), $this->digraphStyle()) |
56
|
|
|
); |
57
|
|
|
} |
58
|
30 |
|
|
59
|
|
|
public function codeParser(): CodeParser |
60
|
30 |
|
{ |
61
|
6 |
|
return new CodeParser($this->tokenParser(), $this->externalDefinitionsResolvers()); |
62
|
|
|
} |
63
|
24 |
|
|
64
|
|
|
private function digraphStyle(): DigraphStyle |
65
|
|
|
{ |
66
|
30 |
|
if ($this->configuration->hideEmptyBlocks()) { |
67
|
|
|
return DigraphStyle::withoutEmptyBlocks($this->configuration->theme()); |
68
|
30 |
|
} |
69
|
|
|
return DigraphStyle::default($this->configuration->theme()); |
70
|
|
|
} |
71
|
30 |
|
|
72
|
|
|
private function tokenParser(): PhpCodeParser |
73
|
30 |
|
{ |
74
|
30 |
|
$parserBuilder = new ParserBuilder(); |
75
|
30 |
|
if ($this->configuration->hideAttributes()) { |
76
|
30 |
|
$parserBuilder->excludeAttributes(); |
77
|
|
|
} |
78
|
|
|
if ($this->configuration->hideMethods()) { |
79
|
30 |
|
$parserBuilder->excludeMethods(); |
80
|
|
|
} |
81
|
30 |
|
if ($this->configuration->hidePrivate()) { |
82
|
9 |
|
$parserBuilder->excludePrivateMembers(); |
83
|
|
|
} |
84
|
30 |
|
if ($this->configuration->hideProtected()) { |
85
|
|
|
$parserBuilder->excludeProtectedMembers(); |
86
|
30 |
|
} |
87
|
|
|
return $parserBuilder->build(); |
88
|
30 |
|
} |
89
|
9 |
|
|
90
|
|
|
/** @return RelationshipsResolver[] */ |
91
|
30 |
|
private function externalDefinitionsResolvers(): array |
92
|
|
|
{ |
93
|
30 |
|
$resolvers = [new ExternalDefinitionsResolver()]; |
94
|
|
|
if ($this->configuration->extractAssociations()) { |
95
|
30 |
|
$resolvers[] = new ExternalAssociationsResolver(); |
96
|
6 |
|
} |
97
|
|
|
return $resolvers; |
98
|
30 |
|
} |
99
|
|
|
} |
100
|
|
|
|