1 | <?php |
||
7 | class Parser |
||
8 | { |
||
9 | /** |
||
10 | * Filter class to find various types of arguments |
||
11 | * |
||
12 | * @var \League\CLImate\Argument\Filter $filter |
||
13 | */ |
||
14 | protected $filter; |
||
15 | |||
16 | /** |
||
17 | * Summary builder class |
||
18 | * |
||
19 | * @var \League\CLImate\Argument\Summary $summary |
||
20 | */ |
||
21 | protected $summary; |
||
22 | |||
23 | 948 | protected $trailing; |
|
24 | |||
25 | 948 | protected $trailingArray; |
|
26 | 948 | ||
27 | public function __construct() |
||
31 | |||
32 | /** |
||
33 | * @param Filter $filter |
||
34 | 16 | * @param Argument[] $arguments |
|
35 | * |
||
36 | 16 | * @return \League\CLImate\Argument\Parser |
|
37 | 16 | */ |
|
38 | public function setFilter($filter, $arguments) |
||
45 | |||
46 | /** |
||
47 | * Parse command line arguments into CLImate arguments. |
||
48 | 16 | * |
|
49 | * @param array $argv |
||
50 | 16 | * |
|
51 | * @return void |
||
52 | 16 | * @throws InvalidArgumentException if required arguments aren't defined. |
|
53 | 4 | */ |
|
54 | 4 | public function parse(array $argv = null) |
|
77 | |||
78 | /** |
||
79 | 4 | * Get the command name. |
|
80 | * |
||
81 | 4 | * @param array $argv |
|
82 | * |
||
83 | * @return string |
||
84 | */ |
||
85 | public function command(array $argv = null) |
||
89 | |||
90 | /** |
||
91 | 20 | * Get the passed arguments. |
|
92 | * |
||
93 | 20 | * @param array $argv |
|
94 | * |
||
95 | * @return array |
||
96 | */ |
||
97 | public function arguments(array $argv = null) |
||
101 | 4 | ||
102 | /** |
||
103 | 4 | * Get the trailing arguments |
|
104 | * |
||
105 | * @return string|null |
||
106 | */ |
||
107 | public function trailing() |
||
111 | |||
112 | /** |
||
113 | 4 | * Get the trailing arguments as an array |
|
114 | * |
||
115 | 4 | * @return array|null |
|
116 | 4 | */ |
|
117 | 4 | public function trailingArray() |
|
121 | |||
122 | /** |
||
123 | * Remove the trailing arguments from the parser and set them aside |
||
124 | * |
||
125 | * @param array $arguments |
||
126 | * |
||
127 | * @return array |
||
128 | */ |
||
129 | protected function removeTrailingArguments(array $arguments) |
||
138 | 16 | ||
139 | /** |
||
140 | * Parse command line options into prefixed CLImate arguments. |
||
141 | 16 | * |
|
142 | * Prefixed arguments are arguments with a prefix (-) or a long prefix (--) |
||
143 | * on the command line. |
||
144 | * |
||
145 | * Return the arguments passed on the command line that didn't match up with |
||
146 | * prefixed arguments so they can be assigned to non-prefixed arguments. |
||
147 | * |
||
148 | * @param array $argv |
||
149 | * @return array |
||
150 | */ |
||
151 | protected function prefixedArguments(array $argv = []) |
||
160 | |||
161 | /** |
||
162 | * Parse unset command line options into non-prefixed CLImate arguments. |
||
163 | * |
||
164 | * Non-prefixed arguments are parsed after the prefixed arguments on the |
||
165 | * command line, in the order that they're defined in the script. |
||
166 | * |
||
167 | 16 | * @param array $unParsedArguments |
|
168 | */ |
||
169 | protected function nonPrefixedArguments(array $unParsedArguments = []) |
||
177 | 16 | ||
178 | /** |
||
179 | * Parse the name and value of the argument passed in |
||
180 | * |
||
181 | * @param string $cliArgument |
||
182 | * @return string[] [$name, $value] |
||
183 | */ |
||
184 | protected function getNameAndValue($cliArgument) |
||
196 | 16 | ||
197 | 12 | /** |
|
198 | * Attempt to set the an argument's value and remove applicable |
||
199 | * arguments from array |
||
200 | * |
||
201 | 16 | * @param array $argv |
|
202 | * @param int $key |
||
203 | 16 | * @param string $passed_argument |
|
204 | * |
||
205 | * @return array The new $argv |
||
206 | */ |
||
207 | protected function trySettingArgumentValue($argv, $key, $passed_argument) |
||
222 | 4 | ||
223 | /** |
||
224 | * Set the argument's value |
||
225 | 16 | * |
|
226 | 16 | * @param array $argv |
|
227 | 4 | * @param Argument $argument |
|
228 | * @param int $key |
||
229 | * @param string|null $value |
||
230 | * |
||
231 | * @return array The new $argv |
||
232 | 12 | */ |
|
233 | 12 | protected function setArgumentValue($argv, $argument, $key, $value) |
|
261 | |||
262 | /** |
||
263 | * Check if the value is considered a valid input value. |
||
264 | * |
||
265 | * @param $argumentValue |
||
266 | 24 | * @return bool |
|
267 | */ |
||
268 | protected function isValidArgumentValue($argumentValue) |
||
272 | |||
273 | 24 | /** |
|
274 | 24 | * Search for argument in defined prefix arguments |
|
275 | * |
||
276 | 24 | * @param string $name |
|
277 | * |
||
278 | * @return Argument|false |
||
279 | */ |
||
280 | protected function findPrefixedArgument($name) |
||
290 | |||
291 | /** |
||
292 | * Pull a command name and arguments from $argv. |
||
293 | * |
||
294 | * @param array $argv |
||
295 | * @return array |
||
296 | */ |
||
297 | protected function getCommandAndArguments(array $argv = null) |
||
309 | } |
||
310 |