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\Console\Commands; |
9
|
|
|
|
10
|
|
|
use PhUml\Configuration\ClassDiagramBuilder; |
11
|
|
|
use PhUml\Configuration\ClassDiagramConfiguration; |
12
|
|
|
use PhUml\Parser\CodebaseDirectory; |
13
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
14
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
15
|
|
|
use Symfony\Component\Console\Input\InputOption; |
16
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* This command will generate a UML class diagram by reading an OO codebase |
20
|
|
|
* |
21
|
|
|
* This command has 2 required arguments |
22
|
|
|
* |
23
|
|
|
* 1. `directory`. The path where your codebase lives |
24
|
|
|
* 2. `output`. The path to where the generated `png` image will be saved |
25
|
|
|
* |
26
|
|
|
* There are 3 options |
27
|
|
|
* |
28
|
|
|
* 1. `processor`. The command to be used to create the `png` image, it can be either `neato` or `dot` |
29
|
|
|
* This is the only required option |
30
|
|
|
* 2. `recursive`. If present it will look recursively within the `directory` provided |
31
|
|
|
* 3. `associations`. If present the command will generate associations to the classes/interfaces |
32
|
|
|
* injected through the constructor and the attributes of the class |
33
|
|
|
*/ |
34
|
|
|
class GenerateClassDiagramCommand extends GeneratorCommand |
35
|
|
|
{ |
36
|
|
|
/** @throws \InvalidArgumentException */ |
37
|
45 |
|
protected function configure() |
38
|
|
|
{ |
39
|
|
|
$this |
40
|
45 |
|
->setName('phuml:diagram') |
41
|
45 |
|
->setDescription('Generate a class diagram scanning the given directory') |
42
|
45 |
|
->setHelp( |
43
|
|
|
<<<HELP |
44
|
45 |
|
Example: |
45
|
|
|
php bin/phuml phuml:diagram -r -a -p neato ./src out.png |
46
|
|
|
|
47
|
|
|
This example will scan the `./src` directory recursively for php files. |
48
|
|
|
It will process them with the option `associations` set to true. After that it |
49
|
|
|
will be send to the `neato` processor and saved to the file `out.png`. |
50
|
|
|
HELP |
51
|
|
|
) |
52
|
45 |
|
->addArgument( |
53
|
45 |
|
'directory', |
54
|
45 |
|
InputArgument::REQUIRED, |
55
|
45 |
|
'The directory to be scanned to generate the class diagram' |
56
|
|
|
) |
57
|
45 |
|
->addArgument( |
58
|
45 |
|
'output', |
59
|
45 |
|
InputArgument::REQUIRED, |
60
|
45 |
|
'The file name for your class diagram' |
61
|
|
|
) |
62
|
45 |
|
->addOption( |
63
|
45 |
|
'recursive', |
64
|
45 |
|
'r', |
65
|
45 |
|
InputOption::VALUE_NONE, |
66
|
45 |
|
'Look for classes in the given directory recursively' |
67
|
|
|
) |
68
|
45 |
|
->addOption( |
69
|
45 |
|
'processor', |
70
|
45 |
|
'p', |
71
|
45 |
|
InputOption::VALUE_REQUIRED, |
72
|
45 |
|
'Choose between the neato and dot processors' |
73
|
|
|
) |
74
|
45 |
|
->addOption( |
75
|
45 |
|
'associations', |
76
|
45 |
|
'a', |
77
|
45 |
|
InputOption::VALUE_NONE, |
78
|
45 |
|
'If present, the Graphviz processor will generate association among classes' |
79
|
|
|
) |
80
|
45 |
|
->addOption( |
81
|
45 |
|
'hide-private', |
82
|
45 |
|
'i', |
83
|
45 |
|
InputOption::VALUE_NONE, |
84
|
45 |
|
'If present, no private attributes or methods will be processed' |
85
|
|
|
) |
86
|
45 |
|
->addOption( |
87
|
45 |
|
'hide-protected', |
88
|
45 |
|
'o', |
89
|
45 |
|
InputOption::VALUE_NONE, |
90
|
45 |
|
'If present, no protected attributes or methods will be processed' |
91
|
|
|
) |
92
|
|
|
; |
93
|
45 |
|
} |
94
|
|
|
|
95
|
18 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
96
|
|
|
{ |
97
|
18 |
|
$codebasePath = $input->getArgument('directory'); |
98
|
18 |
|
$classDiagramPath = $input->getArgument('output'); |
99
|
|
|
|
100
|
18 |
|
$builder = new ClassDiagramBuilder(new ClassDiagramConfiguration($input->getOptions())); |
101
|
|
|
|
102
|
12 |
|
$codeFinder = $builder->codeFinder(); |
103
|
12 |
|
$codeFinder->addDirectory(CodebaseDirectory::from($codebasePath)); |
104
|
|
|
|
105
|
9 |
|
$classDiagramGenerator = $builder->classDiagramGenerator(); |
106
|
9 |
|
$classDiagramGenerator->attach($this->display); |
107
|
|
|
|
108
|
9 |
|
$classDiagramGenerator->generate($codeFinder, $classDiagramPath); |
109
|
|
|
|
110
|
9 |
|
return 0; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|