1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Symfony package. |
5
|
|
|
* |
6
|
|
|
* (c) Fabien Potencier <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Symfony\Component\Console\Command; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Console\Helper\DescriptorHelper; |
15
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
16
|
|
|
use Symfony\Component\Console\Input\InputOption; |
17
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
18
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
19
|
|
|
use Symfony\Component\Console\Input\InputDefinition; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* ListCommand displays the list of all available commands for the application. |
23
|
|
|
* |
24
|
|
|
* @author Fabien Potencier <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class TestCommand extends Command |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
*/ |
31
|
|
|
protected function configure() |
32
|
|
|
{ |
33
|
|
|
$this |
34
|
|
|
->setName('test') |
35
|
|
|
->setDefinition($this->createDefinition()) |
36
|
|
|
->setDescription('Test commands') |
37
|
|
|
->setHelp(<<<'EOF' |
38
|
|
|
This is test commands |
39
|
|
|
EOF |
40
|
|
|
) |
41
|
|
|
; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritdoc} |
46
|
|
|
*/ |
47
|
|
|
public function getNativeDefinition() |
48
|
|
|
{ |
49
|
|
|
return $this->createDefinition(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritdoc} |
54
|
|
|
*/ |
55
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
56
|
|
|
{ |
57
|
|
|
$helper = new DescriptorHelper(); |
58
|
|
|
$helper->describe($output, $this->getApplication(), array( |
|
|
|
|
59
|
|
|
'valuename' => $input->getOption('valuename'), |
60
|
|
|
)); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* {@inheritdoc} |
65
|
|
|
*/ |
66
|
|
|
private function createDefinition() |
67
|
|
|
{ |
68
|
|
|
return new InputDefinition(array( |
69
|
|
|
new InputArgument('valuename', InputArgument::OPTIONAL, 'The value name'), |
70
|
|
|
// new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list'), |
|
|
|
|
71
|
|
|
// new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt'), |
72
|
|
|
)); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: