|
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\Actions\GenerateDotFile; |
|
11
|
|
|
use PhUml\Parser\CodeFinder; |
|
12
|
|
|
use PhUml\Parser\TokenParser; |
|
13
|
|
|
use PhUml\Processors\GraphvizProcessor; |
|
14
|
|
|
use RuntimeException; |
|
15
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
16
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
17
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
18
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
19
|
|
|
|
|
20
|
|
|
class GenerateDotFileCommand extends GeneratorCommand |
|
21
|
|
|
{ |
|
22
|
36 |
|
protected function configure() |
|
23
|
|
|
{ |
|
24
|
|
|
$this |
|
25
|
36 |
|
->setName('phuml:dot') |
|
26
|
36 |
|
->setDescription('Generates a digraph in DOT format of a given directory') |
|
27
|
36 |
|
->setHelp(<<<HELP |
|
28
|
36 |
|
Example: |
|
29
|
|
|
php bin/phuml phuml:dot -r -a ./src dot.gv |
|
30
|
|
|
|
|
31
|
|
|
This example will scan the `./src` directory recursively for php files. |
|
32
|
|
|
It will process them with the option `associations` set to true. |
|
33
|
|
|
It will generate a digraph in dot format and save it to the file `dot.gv`. |
|
34
|
|
|
HELP |
|
35
|
|
|
) |
|
36
|
36 |
|
->addOption( |
|
37
|
36 |
|
'recursive', |
|
38
|
36 |
|
'r', |
|
39
|
36 |
|
InputOption::VALUE_NONE, |
|
40
|
36 |
|
'Look for classes in the given directory recursively' |
|
41
|
|
|
) |
|
42
|
36 |
|
->addOption( |
|
43
|
36 |
|
'associations', |
|
44
|
36 |
|
'a', |
|
45
|
36 |
|
InputOption::VALUE_NONE, |
|
46
|
36 |
|
'If present, the Graphviz processor will generate association among classes' |
|
47
|
|
|
) |
|
48
|
36 |
|
->addArgument( |
|
49
|
36 |
|
'directory', |
|
50
|
36 |
|
InputArgument::REQUIRED, |
|
51
|
36 |
|
'The directory to be scanned to generate the dot file' |
|
52
|
|
|
) |
|
53
|
36 |
|
->addArgument( |
|
54
|
36 |
|
'output', |
|
55
|
36 |
|
InputArgument::REQUIRED, |
|
56
|
36 |
|
'The file name for your dot file' |
|
57
|
|
|
) |
|
58
|
|
|
; |
|
59
|
36 |
|
} |
|
60
|
|
|
|
|
61
|
9 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
62
|
|
|
{ |
|
63
|
9 |
|
$directory = $input->getArgument('directory'); |
|
64
|
9 |
|
$dotFile = $input->getArgument('output'); |
|
65
|
9 |
|
$associations = (bool)$input->getOption('associations'); |
|
66
|
9 |
|
$recursive = (bool)$input->getOption('recursive'); |
|
67
|
|
|
|
|
68
|
9 |
|
if (!is_dir($directory)) { |
|
69
|
3 |
|
throw new RuntimeException("'$directory' is not a valid directory"); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
6 |
|
$action = new GenerateDotFile(new TokenParser(), new GraphvizProcessor($associations)); |
|
73
|
6 |
|
$action->attach($this->display); |
|
74
|
|
|
|
|
75
|
6 |
|
$finder = new CodeFinder(); |
|
76
|
6 |
|
$finder->addDirectory($directory, $recursive); |
|
77
|
|
|
|
|
78
|
6 |
|
$output->writeln('[|] Running... (This may take some time)'); |
|
79
|
|
|
|
|
80
|
6 |
|
$action->generate($finder, $dotFile); |
|
81
|
|
|
|
|
82
|
6 |
|
return 0; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|