1 | <?php |
||
13 | class CommandDocBlockParser |
||
14 | { |
||
15 | /** |
||
16 | * @var CommandInfo |
||
17 | */ |
||
18 | protected $commandInfo; |
||
19 | |||
20 | /** |
||
21 | * @var array |
||
22 | */ |
||
23 | protected $tagProcessors = [ |
||
24 | 'command' => 'processCommandTag', |
||
25 | 'name' => 'processCommandTag', |
||
26 | 'arg' => 'processArgumentTag', |
||
27 | 'param' => 'processParamTag', |
||
28 | 'return' => 'processReturnTag', |
||
29 | 'option' => 'processOptionTag', |
||
30 | 'default' => 'processDefaultTag', |
||
31 | 'aliases' => 'processAliases', |
||
32 | 'usage' => 'processUsageTag', |
||
33 | 'description' => 'processAlternateDescriptionTag', |
||
34 | 'desc' => 'processAlternateDescriptionTag', |
||
35 | ]; |
||
36 | |||
37 | public function __construct(CommandInfo $commandInfo) |
||
41 | |||
42 | /** |
||
43 | * Parse the docBlock comment for this command, and set the |
||
44 | * fields of this class with the data thereby obtained. |
||
45 | */ |
||
46 | public function parse($docblock) |
||
63 | |||
64 | /** |
||
65 | * Save any tag that we do not explicitly recognize in the |
||
66 | * 'otherAnnotations' map. |
||
67 | */ |
||
68 | protected function processGenericTag($tag) |
||
72 | |||
73 | /** |
||
74 | * Set the name of the command from a @command or @name annotation. |
||
75 | */ |
||
76 | protected function processCommandTag($tag) |
||
83 | |||
84 | /** |
||
85 | * The @description and @desc annotations may be used in |
||
86 | * place of the synopsis (which we call 'description'). |
||
87 | * This is discouraged. |
||
88 | * |
||
89 | * @deprecated |
||
90 | */ |
||
91 | protected function processAlternateDescriptionTag($tag) |
||
95 | |||
96 | /** |
||
97 | * Store the data from a @arg annotation in our argument descriptions. |
||
98 | */ |
||
99 | protected function processArgumentTag($tag) |
||
103 | |||
104 | /** |
||
105 | * Store the data from a @param annotation in our argument descriptions. |
||
106 | */ |
||
107 | protected function processParamTag($tag) |
||
117 | |||
118 | /** |
||
119 | * Store the data from a @return annotation in our argument descriptions. |
||
120 | */ |
||
121 | protected function processReturnTag($tag) |
||
128 | |||
129 | /** |
||
130 | * Given a docblock description in the form "$variable description", |
||
131 | * return the variable name and description via the 'match' parameter. |
||
132 | */ |
||
133 | protected function pregMatchNameAndDescription($source, &$match) |
||
141 | |||
142 | /** |
||
143 | * Store the data from an @option annotation in our option descriptions. |
||
144 | */ |
||
145 | protected function processOptionTag($tag) |
||
149 | |||
150 | protected function addOptionOrArgumentTag($tag, DefaultsWithDescriptions $set) |
||
160 | |||
161 | /** |
||
162 | * Store the data from a @default annotation in our argument or option store, |
||
163 | * as appropriate. |
||
164 | */ |
||
165 | protected function processDefaultTag($tag) |
||
181 | |||
182 | protected function interpretDefaultValue($defaultValue) |
||
198 | |||
199 | /** |
||
200 | * Process the comma-separated list of aliases |
||
201 | */ |
||
202 | protected function processAliases($tag) |
||
206 | |||
207 | /** |
||
208 | * Store the data from a @usage annotation in our example usage list. |
||
209 | */ |
||
210 | protected function processUsageTag($tag) |
||
218 | |||
219 | /** |
||
220 | * Given a list that might be 'a b c' or 'a, b, c' or 'a,b,c', |
||
221 | * convert the data into the last of these forms. |
||
222 | */ |
||
223 | protected static function convertListToCommaSeparated($text) |
||
227 | |||
228 | /** |
||
229 | * Take a multiline description and convert it into a single |
||
230 | * long unbroken line. |
||
231 | */ |
||
232 | protected static function removeLineBreaks($text) |
||
236 | } |
||
237 |