1
|
|
|
<?php |
2
|
|
|
namespace Consolidation\AnnotatedCommand; |
3
|
|
|
|
4
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
5
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
6
|
|
|
|
7
|
|
|
class CommandData |
8
|
|
|
{ |
9
|
|
|
/** var AnnotationData */ |
10
|
|
|
protected $annotationData; |
11
|
|
|
/** var InputInterface */ |
12
|
|
|
protected $input; |
13
|
|
|
/** var OutputInterface */ |
14
|
|
|
protected $output; |
15
|
|
|
/** var boolean */ |
16
|
|
|
protected $usesInputInterface; |
17
|
|
|
/** var boolean */ |
18
|
|
|
protected $usesOutputInterface; |
19
|
|
|
/** var boolean */ |
20
|
|
|
protected $includeOptionsInArgs; |
21
|
|
|
|
22
|
|
|
public function __construct( |
23
|
|
|
AnnotationData $annotationData, |
24
|
|
|
InputInterface $input, |
25
|
|
|
OutputInterface $output, |
26
|
|
|
$usesInputInterface = false, |
|
|
|
|
27
|
|
|
$usesOutputInterface = false |
|
|
|
|
28
|
|
|
) { |
29
|
|
|
$this->annotationData = $annotationData; |
30
|
|
|
$this->input = $input; |
31
|
|
|
$this->output = $output; |
32
|
|
|
$this->usesInputInterface = false; |
33
|
|
|
$this->usesOutputInterface = false; |
34
|
|
|
$this->includeOptionsInArgs = true; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* For internal use only; indicates that the function to be called |
39
|
|
|
* should be passed an InputInterface &/or an OutputInterface. |
40
|
|
|
* @param booean $usesInputInterface |
41
|
|
|
* @param boolean $usesOutputInterface |
42
|
|
|
* @return self |
43
|
|
|
*/ |
44
|
|
|
public function setUseIOInterfaces($usesInputInterface, $usesOutputInterface) |
45
|
|
|
{ |
46
|
|
|
$this->usesInputInterface = $usesInputInterface; |
47
|
|
|
$this->usesOutputInterface = $usesOutputInterface; |
48
|
|
|
|
49
|
|
|
return $this; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* For backwards-compatibility mode only: disable addition of |
54
|
|
|
* options on the end of the arguments list. |
55
|
|
|
*/ |
56
|
|
|
public function setIncludeOptionsInArgs($includeOptionsInArgs) |
57
|
|
|
{ |
58
|
|
|
$this->includeOptionsInArgs = $includeOptionsInArgs; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function annotationData() |
62
|
|
|
{ |
63
|
|
|
return $this->annotationData; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function input() |
67
|
|
|
{ |
68
|
|
|
return $this->input; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function output() |
72
|
|
|
{ |
73
|
|
|
return $this->output; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function arguments() |
77
|
|
|
{ |
78
|
|
|
return $this->input->getArguments(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function options() |
82
|
|
|
{ |
83
|
|
|
return $this->input->getOptions(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function getArgsWithoutAppName() |
87
|
|
|
{ |
88
|
|
|
$args = $this->arguments(); |
89
|
|
|
|
90
|
|
|
// When called via the Application, the first argument |
91
|
|
|
// will be the command name. The Application alters the |
92
|
|
|
// input definition to match, adding a 'command' argument |
93
|
|
|
// to the beginning. |
94
|
|
|
array_shift($args); |
95
|
|
|
|
96
|
|
|
if ($this->usesInputInterface) { |
97
|
|
|
array_unshift($args, $this->input()); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
if ($this->usesOutputInterface) { |
101
|
|
|
array_unshift($args, $this->output()); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return $args; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function getArgsAndOptions() |
108
|
|
|
{ |
109
|
|
|
// Get passthrough args, and add the options on the end. |
110
|
|
|
$args = $this->getArgsWithoutAppName(); |
111
|
|
|
if ($this->includeOptionsInArgs) { |
112
|
|
|
$args['options'] = $this->options(); |
113
|
|
|
} |
114
|
|
|
return $args; |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.