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 | public function __construct() |
|
29 | |||
30 | /** |
||
31 | * @param Filter $filter |
||
32 | * @param Argument[] $arguments |
||
33 | * |
||
34 | 16 | * @return \League\CLImate\Argument\Parser |
|
35 | */ |
||
36 | 16 | public function setFilter($filter, $arguments) |
|
43 | |||
44 | /** |
||
45 | * Parse command line arguments into CLImate arguments. |
||
46 | * |
||
47 | * @param array $argv |
||
48 | 16 | * |
|
49 | * @return void |
||
50 | 16 | * @throws InvalidArgumentException if required arguments aren't defined. |
|
51 | */ |
||
52 | 16 | public function parse(array $argv = null) |
|
75 | |||
76 | /** |
||
77 | * Get the command name. |
||
78 | * |
||
79 | 4 | * @param array $argv |
|
80 | * |
||
81 | 4 | * @return string |
|
82 | */ |
||
83 | public function command(array $argv = null) |
||
87 | |||
88 | /** |
||
89 | * Get the passed arguments. |
||
90 | * |
||
91 | 20 | * @param array $argv |
|
92 | * |
||
93 | 20 | * @return array |
|
94 | */ |
||
95 | public function arguments(array $argv = null) |
||
99 | |||
100 | /** |
||
101 | 4 | * Get the trailing arguments |
|
102 | * |
||
103 | 4 | * @return string|null |
|
104 | */ |
||
105 | public function trailing() |
||
109 | |||
110 | /** |
||
111 | * Remove the trailing arguments from the parser and set them aside |
||
112 | * |
||
113 | 4 | * @param array $arguments |
|
114 | * |
||
115 | 4 | * @return array |
|
116 | 4 | */ |
|
117 | 4 | protected function removeTrailingArguments(array $arguments) |
|
125 | |||
126 | /** |
||
127 | * Parse command line options into prefixed CLImate arguments. |
||
128 | * |
||
129 | * Prefixed arguments are arguments with a prefix (-) or a long prefix (--) |
||
130 | * on the command line. |
||
131 | * |
||
132 | * Return the arguments passed on the command line that didn't match up with |
||
133 | * prefixed arguments so they can be assigned to non-prefixed arguments. |
||
134 | 16 | * |
|
135 | * @param array $argv |
||
136 | 16 | * @return array |
|
137 | 16 | */ |
|
138 | 16 | protected function prefixedArguments(array $argv = []) |
|
147 | |||
148 | /** |
||
149 | * Parse unset command line options into non-prefixed CLImate arguments. |
||
150 | * |
||
151 | * Non-prefixed arguments are parsed after the prefixed arguments on the |
||
152 | 16 | * command line, in the order that they're defined in the script. |
|
153 | * |
||
154 | 16 | * @param array $unParsedArguments |
|
155 | 4 | */ |
|
156 | 4 | protected function nonPrefixedArguments(array $unParsedArguments = []) |
|
164 | |||
165 | /** |
||
166 | * Parse the name and value of the argument passed in |
||
167 | 16 | * |
|
168 | * @param string $cliArgument |
||
169 | * @return string[] [$name, $value] |
||
170 | 16 | */ |
|
171 | 8 | protected function getNameAndValue($cliArgument) |
|
183 | |||
184 | /** |
||
185 | * Attempt to set the an argument's value and remove applicable |
||
186 | * arguments from array |
||
187 | * |
||
188 | * @param array $argv |
||
189 | * @param int $key |
||
190 | 16 | * @param string $passed_argument |
|
191 | * |
||
192 | 16 | * @return array The new $argv |
|
193 | */ |
||
194 | protected function trySettingArgumentValue($argv, $key, $passed_argument) |
||
209 | |||
210 | /** |
||
211 | * Set the argument's value |
||
212 | * |
||
213 | * @param array $argv |
||
214 | * @param Argument $argument |
||
215 | * @param int $key |
||
216 | 16 | * @param string|null $value |
|
217 | * |
||
218 | * @return array The new $argv |
||
219 | */ |
||
220 | 16 | protected function setArgumentValue($argv, $argument, $key, $value) |
|
248 | |||
249 | 16 | /** |
|
250 | * Check if the value is considered a valid input value. |
||
251 | 16 | * |
|
252 | 16 | * @param $argumentValue |
|
253 | 16 | * @return bool |
|
254 | */ |
||
255 | 12 | protected function isValidArgumentValue($argumentValue) |
|
259 | |||
260 | /** |
||
261 | * Search for argument in defined prefix arguments |
||
262 | * |
||
263 | * @param string $name |
||
264 | * |
||
265 | * @return Argument|false |
||
266 | 24 | */ |
|
267 | protected function findPrefixedArgument($name) |
||
277 | |||
278 | /** |
||
279 | * Pull a command name and arguments from $argv. |
||
280 | * |
||
281 | * @param array $argv |
||
282 | * @return array |
||
283 | */ |
||
284 | protected function getCommandAndArguments(array $argv = null) |
||
296 | } |
||
297 |