1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/** |
3
|
|
|
* PHP version 8.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\Generators; |
9
|
|
|
|
10
|
|
|
use League\Pipeline\Pipeline; |
11
|
|
|
use PhUml\Console\Commands\GeneratorInput; |
12
|
|
|
use PhUml\Processors\OutputContent; |
13
|
|
|
use PhUml\Stages\CreateClassDiagram; |
14
|
|
|
use PhUml\Stages\CreateDigraph; |
15
|
|
|
use PhUml\Stages\FindCode; |
16
|
|
|
use PhUml\Stages\ParseCode; |
17
|
|
|
use PhUml\Stages\SaveFile; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* It generates a UML class diagram from a directory with PHP code |
21
|
|
|
* |
22
|
|
|
* The image produced is a `.png` that will be saved in a specified path |
23
|
|
|
*/ |
24
|
|
|
final class ClassDiagramGenerator |
25
|
|
|
{ |
26
|
7 |
|
public static function fromConfiguration(ClassDiagramConfiguration $configuration): ClassDiagramGenerator |
27
|
|
|
{ |
28
|
7 |
|
return new self( |
29
|
7 |
|
new FindCode($configuration->codeFinder(), $configuration->display()), |
30
|
7 |
|
new ParseCode($configuration->codeParser(), $configuration->display()), |
31
|
7 |
|
new CreateDigraph($configuration->graphvizProcessor(), $configuration->display()), |
32
|
7 |
|
new CreateClassDiagram($configuration->imageProcessor(), $configuration->display()), |
33
|
7 |
|
new SaveFile($configuration->writer(), $configuration->display()), |
34
|
|
|
); |
35
|
|
|
} |
36
|
|
|
|
37
|
7 |
|
private function __construct( |
38
|
|
|
private readonly FindCode $findCode, |
|
|
|
|
39
|
|
|
private readonly ParseCode $parseCode, |
40
|
|
|
private readonly CreateDigraph $createDigraph, |
41
|
|
|
private readonly CreateClassDiagram $createClassDiagram, |
42
|
|
|
private readonly SaveFile $saveFile, |
43
|
|
|
) { |
44
|
|
|
} |
45
|
|
|
|
46
|
6 |
|
public function generate(GeneratorInput $input): void |
47
|
|
|
{ |
48
|
6 |
|
$pipeline = (new Pipeline()) |
49
|
6 |
|
->pipe($this->findCode) |
50
|
6 |
|
->pipe($this->parseCode) |
51
|
6 |
|
->pipe($this->createDigraph) |
52
|
6 |
|
->pipe($this->createClassDiagram) |
53
|
6 |
|
->pipe(fn (OutputContent $content) => $this->saveFile->saveTo($content, $input->filePath())); |
54
|
|
|
|
55
|
6 |
|
$pipeline->process($input->codebaseDirectory()); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|