1 | <?php |
||
8 | class Manager |
||
9 | { |
||
10 | /** |
||
11 | * An array of arguments passed to the program. |
||
12 | * |
||
13 | * @var Argument[] $arguments |
||
14 | */ |
||
15 | protected $arguments = []; |
||
16 | |||
17 | /** |
||
18 | * A program's description. |
||
19 | * |
||
20 | * @var string $description |
||
21 | */ |
||
22 | protected $description; |
||
23 | |||
24 | /** |
||
25 | * Filter class to find various types of arguments |
||
26 | * |
||
27 | * @var \League\CLImate\Argument\Filter $filter |
||
28 | */ |
||
29 | protected $filter; |
||
30 | |||
31 | /** |
||
32 | * Summary builder class |
||
33 | * |
||
34 | * @var \League\CLImate\Argument\Summary $summary |
||
35 | */ |
||
36 | protected $summary; |
||
37 | |||
38 | /** |
||
39 | * Argument parser class |
||
40 | * |
||
41 | * @var \League\CLImate\Argument\Parser $parser |
||
42 | */ |
||
43 | protected $parser; |
||
44 | 948 | ||
45 | public function __construct() |
||
51 | |||
52 | /** |
||
53 | * Add an argument. |
||
54 | * |
||
55 | * @param Argument|string|array $argument |
||
56 | * @param $options |
||
57 | * |
||
58 | 28 | * @return void |
|
59 | * @throws InvalidArgumentException if $argument isn't an array or Argument object. |
||
60 | 28 | */ |
|
61 | 24 | public function add($argument, array $options = []) |
|
78 | |||
79 | /** |
||
80 | * Add multiple arguments to a CLImate script. |
||
81 | 24 | * |
|
82 | * @param array $arguments |
||
83 | 24 | */ |
|
84 | 24 | protected function addMany(array $arguments = []) |
|
90 | |||
91 | /** |
||
92 | * Determine if an argument exists. |
||
93 | * |
||
94 | 8 | * @param string $name |
|
95 | * @return bool |
||
96 | 8 | */ |
|
97 | public function exists($name) |
||
101 | |||
102 | /** |
||
103 | * Retrieve an argument's value. |
||
104 | * |
||
105 | 8 | * @param string $name |
|
106 | * @return string|int|float|bool|null |
||
107 | 8 | */ |
|
108 | public function get($name) |
||
112 | |||
113 | /** |
||
114 | * Retrieve an argument's all values as an array. |
||
115 | 20 | * |
|
116 | * @param string $name |
||
117 | 20 | * @return string[]|int[]|float[]|bool[] |
|
118 | */ |
||
119 | public function getArray($name) |
||
123 | |||
124 | /** |
||
125 | * Retrieve all arguments. |
||
126 | * |
||
127 | * @return Argument[] |
||
128 | */ |
||
129 | public function all() |
||
133 | |||
134 | 8 | /** |
|
135 | 8 | * Determine if an argument has been defined on the command line. |
|
136 | * |
||
137 | * This can be useful for making sure an argument is present on the command |
||
138 | 8 | * line before parse()'ing them into argument objects. |
|
139 | 8 | * |
|
140 | * @param string $name |
||
141 | 8 | * @param array $argv |
|
142 | 8 | * |
|
143 | 8 | * @return bool |
|
144 | */ |
||
145 | 8 | public function defined($name, array $argv = null) |
|
163 | 8 | ||
164 | /** |
||
165 | 8 | * Check if the defined argument matches the command argument. |
|
166 | 8 | * |
|
167 | 8 | * @param Argument $argument |
|
168 | * @param string $command_argument |
||
169 | 8 | * |
|
170 | * @return bool |
||
171 | 8 | */ |
|
172 | protected function isArgument($argument, $command_argument) |
||
187 | 8 | ||
188 | /** |
||
189 | * Retrieve all arguments as key/value pairs. |
||
190 | * |
||
191 | * @return array |
||
192 | */ |
||
193 | public function toArray() |
||
203 | |||
204 | /** |
||
205 | * Set a program's description. |
||
206 | 4 | * |
|
207 | * @param string $description |
||
208 | 4 | */ |
|
209 | 4 | public function description($description) |
|
213 | 4 | ||
214 | 4 | /** |
|
215 | * Output a script's usage statement. |
||
216 | * |
||
217 | * @param CLImate $climate |
||
218 | * @param array $argv |
||
219 | */ |
||
220 | public function usage(CLImate $climate, array $argv = null) |
||
229 | |||
230 | /** |
||
231 | * Parse command line arguments into CLImate arguments. |
||
232 | * |
||
233 | * @param array $argv |
||
234 | 4 | */ |
|
235 | public function parse(array $argv = null) |
||
241 | |||
242 | /** |
||
243 | * Get the trailing arguments |
||
244 | * |
||
245 | * @return string|null |
||
246 | */ |
||
247 | public function trailing() |
||
251 | |||
252 | /** |
||
253 | * Get the trailing arguments as an array |
||
254 | * |
||
255 | * @return array|null |
||
256 | */ |
||
257 | public function trailingArray() |
||
261 | } |
||
262 |