1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Transfer. |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE file located |
7
|
|
|
* in the root directory. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Transfer\Console\Command\Manifest; |
11
|
|
|
|
12
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
13
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
14
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
15
|
|
|
use Transfer\Exception\ManifestNotFoundException; |
16
|
|
|
use Transfer\Manifest\ManifestInterface; |
17
|
|
|
use Transfer\Procedure\Procedure; |
18
|
|
|
use Transfer\Procedure\ProcedureBuilder; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Command for describing a manifest in a manifest chain. |
22
|
|
|
*/ |
23
|
|
|
class DescribeCommand extends ManifestCommand |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
4 |
|
protected function configure() |
29
|
|
|
{ |
30
|
4 |
|
parent::configure(); |
31
|
|
|
|
32
|
4 |
|
$this |
33
|
4 |
|
->setName('manifest:describe') |
34
|
4 |
|
->setDescription('Describe a specific manifest') |
35
|
4 |
|
->addArgument('name', InputArgument::OPTIONAL, 'Name of the manifest'); |
36
|
4 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* {@inheritdoc} |
40
|
|
|
*/ |
41
|
2 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
42
|
|
|
{ |
43
|
2 |
|
parent::execute($input, $output); |
44
|
|
|
|
45
|
1 |
|
$name = $input->getArgument('name'); |
46
|
|
|
|
47
|
1 |
|
if (!($manifest = $this->chain->getManifest($name))) { |
|
|
|
|
48
|
1 |
|
throw new ManifestNotFoundException($name); |
|
|
|
|
49
|
|
|
} |
50
|
|
|
|
51
|
1 |
|
$this->describeManifest($manifest, $output); |
52
|
1 |
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Describes a manifest. |
56
|
|
|
* |
57
|
|
|
* @param ManifestInterface $manifest Manifest |
58
|
|
|
* @param OutputInterface $output Output |
59
|
|
|
*/ |
60
|
1 |
|
private function describeManifest(ManifestInterface $manifest, OutputInterface $output) |
61
|
|
|
{ |
62
|
1 |
|
$builder = new ProcedureBuilder(); |
63
|
1 |
|
$manifest->configureProcedureBuilder($builder); |
64
|
|
|
|
65
|
1 |
|
$output->writeln(sprintf("Manifest description for <info>%s</info>\n", $manifest->getName())); |
66
|
1 |
|
$output->writeln("<fg=blue;options=bold>PROCEDURE CONFIGURATION</fg=blue;options=bold>\n"); |
67
|
|
|
|
68
|
1 |
|
$this->describeProcedure($builder->getProcedure(), $output); |
69
|
1 |
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Describes a procedure. |
73
|
|
|
* |
74
|
|
|
* @param Procedure $procedure Procedure |
75
|
|
|
* @param OutputInterface $output Console output handle |
76
|
|
|
* @param int $depth Current depth |
77
|
|
|
*/ |
78
|
1 |
|
private function describeProcedure(Procedure $procedure, OutputInterface $output, $depth = 0) |
79
|
|
|
{ |
80
|
1 |
|
$output->writeln(sprintf('%sProcedure <info>%s</info>', str_repeat(' ', $depth), $procedure->getName())); |
81
|
|
|
|
82
|
1 |
|
$this->describeComponents($procedure->getSources(), 'SOURCES', $output, $depth); |
83
|
1 |
|
$this->describeComponents($procedure->getWorkers(), 'WORKERS', $output, $depth); |
84
|
1 |
|
$this->describeComponents($procedure->getTargets(), 'TARGETS', $output, $depth); |
85
|
1 |
|
$this->describeChildProcedures($procedure->getChildren(), $output, $depth); |
86
|
|
|
|
87
|
1 |
|
$output->write("\n"); |
88
|
1 |
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Describes child procedures. |
92
|
|
|
* |
93
|
|
|
* @param array $children Procedure children |
94
|
|
|
* @param OutputInterface $output Console output handle |
95
|
|
|
* @param int $depth Current depth |
96
|
|
|
*/ |
97
|
1 |
|
private function describeChildProcedures($children, $output, $depth) |
98
|
|
|
{ |
99
|
1 |
|
if (is_array($children)) { |
100
|
1 |
|
$output->writeln(sprintf('%s<comment>SUB-PROCEDURES</comment>', str_repeat(' ', $depth))); |
101
|
|
|
|
102
|
1 |
|
foreach ($children as $child) { |
103
|
1 |
|
$this->describeProcedure($child, $output, $depth + 2); |
104
|
1 |
|
$output->writeln(''); |
105
|
1 |
|
} |
106
|
1 |
|
} |
107
|
1 |
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Describes components. |
111
|
|
|
* |
112
|
|
|
* @param array $components Components |
113
|
|
|
* @param string $name Component type |
114
|
|
|
* @param OutputInterface $output Console output handle |
115
|
|
|
* @param int $depth Current depth |
116
|
|
|
*/ |
117
|
1 |
|
private function describeComponents($components, $name, OutputInterface $output, $depth = 0) |
118
|
|
|
{ |
119
|
1 |
|
if (is_array($components)) { |
120
|
1 |
|
$output->writeln(sprintf('%s<comment>%s</comment>', str_repeat(' ', $depth), $name)); |
121
|
|
|
|
122
|
1 |
|
foreach ($components as $component) { |
123
|
1 |
|
$output->writeln(sprintf( |
124
|
1 |
|
'%s%s', |
125
|
1 |
|
str_repeat(' ', $depth + 4), |
126
|
1 |
|
is_object($component) ? get_class($component) : get_class($component[0]) |
127
|
1 |
|
)); |
128
|
1 |
|
} |
129
|
1 |
|
} |
130
|
1 |
|
} |
131
|
|
|
} |
132
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.