1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Flagbit\Plantuml\Command; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Command\Command; |
6
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
9
|
|
|
|
10
|
|
|
class WriteCommand extends Command |
11
|
|
|
{ |
12
|
10 |
|
protected function configure() |
13
|
|
|
{ |
14
|
10 |
|
$this |
15
|
10 |
|
->setName('write') |
16
|
10 |
|
->setDescription('Generates PlantUML diagram from php source') |
17
|
10 |
|
->addArgument( |
18
|
10 |
|
'files', |
19
|
|
|
InputArgument::IS_ARRAY |
20
|
10 |
|
) |
21
|
10 |
|
->addOption('without-constants', null, null, 'Disables rendering of constants') |
22
|
10 |
|
->addOption('without-methods', null, null, 'Disables rendering of methods') |
23
|
10 |
|
->addOption('without-properties', null, null, 'Disables rendering of properties') |
24
|
10 |
|
->addOption('without-doc-content', null, null, 'Disables parsing doc block for methods or properties') |
25
|
10 |
|
->addOption('grouping', null, null, 'Enable deprecated and todo grouping for methods'), |
|
|
|
|
26
|
|
|
->addOption('without-function-params', null, null, 'Do not display function param, only count'); |
27
|
10 |
|
} |
28
|
|
|
|
29
|
10 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
30
|
|
|
{ |
31
|
10 |
|
$broker = new \TokenReflection\Broker(new \TokenReflection\Broker\Backend\Memory()); |
32
|
10 |
|
|
33
|
|
|
foreach ($input->getArgument('files') as $fileToProcess) { |
34
|
|
|
if (is_dir($fileToProcess)) { |
35
|
|
|
$broker->processDirectory($fileToProcess); |
36
|
10 |
|
} |
37
|
|
|
else { |
38
|
10 |
|
$broker->processFile($fileToProcess); |
39
|
|
|
} |
40
|
10 |
|
} |
41
|
10 |
|
|
42
|
10 |
|
$classWriter = new \Flagbit\Plantuml\TokenReflection\ClassWriter(); |
43
|
10 |
|
if (!$input->getOption('without-constants')) { |
44
|
10 |
|
$classWriter->setConstantWriter(new \Flagbit\Plantuml\TokenReflection\ConstantWriter()); |
45
|
10 |
|
} |
46
|
10 |
|
if (!$input->getOption('without-properties')) { |
47
|
10 |
|
if ($input->getOption('grouping')) { |
48
|
10 |
|
$classWriter->setPropertyWriter(new \Flagbit\Plantuml\TokenReflection\PropertyGroupingWriter()); |
49
|
10 |
|
} else { |
50
|
10 |
|
$classWriter->setPropertyWriter(new \Flagbit\Plantuml\TokenReflection\PropertyWriter()); |
51
|
10 |
|
} |
52
|
10 |
|
} |
53
|
|
|
if (!$input->getOption('without-methods')) { |
54
|
10 |
|
if ($input->getOption('grouping')) { |
55
|
10 |
|
$classWriter->setMethodWriter(new \Flagbit\Plantuml\TokenReflection\MethodGroupingWriter()); |
56
|
|
|
} else { |
57
|
10 |
|
$classWriter->setMethodWriter(new \Flagbit\Plantuml\TokenReflection\MethodWriter()); |
58
|
10 |
|
} |
59
|
10 |
|
} |
60
|
10 |
|
if (!$input->getOption('without-doc-content')) { |
61
|
|
|
$classWriter->setDocContentWriter(new \Flagbit\Plantuml\TokenReflection\DocContentWriter()); |
62
|
1 |
|
} |
63
|
|
|
|
64
|
|
|
$output->write('@startuml', "\n"); |
65
|
|
|
foreach ($broker->getClasses() as $class) { |
66
|
|
|
/** @var $class \TokenReflection\IReflectionClass */ |
67
|
|
|
$output->write($classWriter->writeElement($class)); |
68
|
|
|
} |
69
|
|
|
$output->write('@enduml', "\n"); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|