|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This software package is licensed under `AGPL-3.0-only, proprietary` license[s]. |
|
5
|
|
|
* |
|
6
|
|
|
* @package maslosoft/signals |
|
7
|
|
|
* @license AGPL-3.0-only, proprietary |
|
8
|
|
|
* |
|
9
|
|
|
* @copyright Copyright (c) Peter Maselkowski <[email protected]> |
|
10
|
|
|
* @link https://maslosoft.com/signals/ |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Maslosoft\Signals\Application\Commands; |
|
14
|
|
|
|
|
15
|
|
|
use Maslosoft\Addendum\Interfaces\AnnotatedInterface; |
|
16
|
|
|
use Maslosoft\Signals\Helpers\Preview; |
|
17
|
|
|
use Maslosoft\Signals\Signal; |
|
18
|
|
|
use Maslosoft\Sitcom\Command; |
|
19
|
|
|
use Symfony\Component\Console\Command\Command as ConsoleCommand; |
|
20
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
21
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* PreviewCommand |
|
25
|
|
|
* |
|
26
|
|
|
* @author Piotr Maselkowski <pmaselkowski at gmail.com> |
|
27
|
|
|
*/ |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* PreviewCommand |
|
31
|
|
|
* |
|
32
|
|
|
* @author Piotr Maselkowski <pmaselkowski at gmail.com> |
|
33
|
|
|
* @codeCoverageIgnore |
|
34
|
|
|
*/ |
|
35
|
|
|
class PreviewCommand extends ConsoleCommand implements AnnotatedInterface |
|
36
|
|
|
{ |
|
37
|
|
|
|
|
38
|
|
|
protected function configure() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->setName("preview"); |
|
41
|
|
|
$this->setDescription("Show list of signals and slots"); |
|
42
|
|
|
$this->setDefinition([ |
|
43
|
|
|
]); |
|
44
|
|
|
|
|
45
|
|
|
$help = <<<EOT |
|
46
|
|
|
The <info>preview</info> command will display list of signals and slots. |
|
47
|
|
|
No files will be modified at this stage. |
|
48
|
|
|
Use -vv option to also get list of processed files. |
|
49
|
|
|
EOT; |
|
50
|
|
|
$this->setHelp($help); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
54
|
|
|
{ |
|
55
|
|
|
$preview = new Preview(); |
|
56
|
|
|
$signal = new Signal; |
|
57
|
|
|
|
|
58
|
|
|
$output->writeln("Scanning sources of... "); |
|
59
|
|
|
$paths = []; |
|
60
|
|
|
foreach ($signal->paths as $path) |
|
61
|
|
|
{ |
|
62
|
|
|
$paths[] = '<info>' . realpath($path) . '</info>'; |
|
63
|
|
|
} |
|
64
|
|
|
$output->writeln(implode("\n", $paths)); |
|
65
|
|
|
|
|
66
|
|
|
$lines = []; |
|
67
|
|
|
foreach ($preview->cli($signal) as $line) |
|
68
|
|
|
{ |
|
69
|
|
|
if (!strstr($line, "\t")) |
|
70
|
|
|
{ |
|
71
|
|
|
$lines[] = "<info>$line</info>"; |
|
72
|
|
|
} |
|
73
|
|
|
else |
|
74
|
|
|
{ |
|
75
|
|
|
$lines[] = $line; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
$output->writeln('Processed files:', OutputInterface::VERBOSITY_VERY_VERBOSE); |
|
80
|
|
|
$output->writeln(implode("\n", $preview->getPaths()), OutputInterface::VERBOSITY_VERY_VERBOSE); |
|
81
|
|
|
|
|
82
|
|
|
$output->writeln("Following signals and slots was found:"); |
|
83
|
|
|
foreach ($lines as $line) |
|
84
|
|
|
{ |
|
85
|
|
|
$output->writeln($line); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @SlotFor(Command) |
|
91
|
|
|
* @param Command $signal |
|
92
|
|
|
*/ |
|
93
|
|
|
public function reactOn(Command $signal) |
|
94
|
|
|
{ |
|
95
|
|
|
$signal->add($this, 'signals'); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
} |
|
99
|
|
|
|