1 | <?php |
||
12 | class CommandDocBlockParser |
||
13 | { |
||
14 | /** |
||
15 | * @var CommandInfo |
||
16 | */ |
||
17 | protected $commandInfo; |
||
18 | |||
19 | /** |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $tagProcessors = [ |
||
23 | 'command' => 'processCommandTag', |
||
24 | 'name' => 'processCommandTag', |
||
25 | 'param' => 'processArgumentTag', |
||
26 | 'option' => 'processOptionTag', |
||
27 | 'default' => 'processDefaultTag', |
||
28 | 'aliases' => 'processAliases', |
||
29 | 'usage' => 'processUsageTag', |
||
30 | 'description' => 'processAlternateDescriptionTag', |
||
31 | 'desc' => 'processAlternateDescriptionTag', |
||
32 | ]; |
||
33 | |||
34 | public function __construct(CommandInfo $commandInfo) |
||
38 | |||
39 | /** |
||
40 | * Parse the docBlock comment for this command, and set the |
||
41 | * fields of this class with the data thereby obtained. |
||
42 | */ |
||
43 | public function parse($docblock) |
||
60 | |||
61 | /** |
||
62 | * Save any tag that we do not explicitly recognize in the |
||
63 | * 'otherAnnotations' map. |
||
64 | */ |
||
65 | protected function processGenericTag($tag) |
||
69 | |||
70 | /** |
||
71 | * Set the name of the command from a @command or @name annotation. |
||
72 | */ |
||
73 | protected function processCommandTag($tag) |
||
80 | |||
81 | /** |
||
82 | * The @description and @desc annotations may be used in |
||
83 | * place of the synopsis (which we call 'description'). |
||
84 | * This is discouraged. |
||
85 | * |
||
86 | * @deprecated |
||
87 | */ |
||
88 | protected function processAlternateDescriptionTag($tag) |
||
92 | |||
93 | /** |
||
94 | * Store the data from a @param annotation in our argument descriptions. |
||
95 | */ |
||
96 | protected function processArgumentTag($tag) |
||
106 | |||
107 | /** |
||
108 | * Given a docblock description in the form "$variable description", |
||
109 | * return the variable name and description via the 'match' parameter. |
||
110 | */ |
||
111 | protected function pregMatchNameAndDescription($source, &$match) |
||
119 | |||
120 | /** |
||
121 | * Store the data from an @option annotation in our option descriptions. |
||
122 | */ |
||
123 | protected function processOptionTag($tag) |
||
133 | |||
134 | /** |
||
135 | * Store the data from a @default annotation in our argument or option store, |
||
136 | * as appropriate. |
||
137 | */ |
||
138 | protected function processDefaultTag($tag) |
||
154 | |||
155 | protected function interpretDefaultValue($defaultValue) |
||
171 | |||
172 | /** |
||
173 | * Process the comma-separated list of aliases |
||
174 | */ |
||
175 | protected function processAliases($tag) |
||
179 | |||
180 | /** |
||
181 | * Store the data from a @usage annotation in our example usage list. |
||
182 | */ |
||
183 | protected function processUsageTag($tag) |
||
191 | |||
192 | /** |
||
193 | * Given a list that might be 'a b c' or 'a, b, c' or 'a,b,c', |
||
194 | * convert the data into the last of these forms. |
||
195 | */ |
||
196 | protected static function convertListToCommaSeparated($text) |
||
200 | |||
201 | /** |
||
202 | * Take a multiline description and convert it into a single |
||
203 | * long unbroken line. |
||
204 | */ |
||
205 | protected static function removeLineBreaks($text) |
||
209 | } |
||
210 |