1 | <?php |
||
59 | abstract class OutputPlugin |
||
60 | { |
||
61 | protected $writer = null; |
||
62 | |||
63 | const COLOUR_MODE_OFF = 1; |
||
64 | const COLOUR_MODE_ON = 2; |
||
65 | const COLOUR_MODE_AUTO = 3; |
||
66 | |||
67 | public function __construct() |
||
68 | { |
||
69 | $this->writer = new OutputWriter(self::COLOUR_MODE_AUTO); |
||
|
|||
70 | } |
||
71 | |||
72 | // ================================================================== |
||
73 | // |
||
74 | // Support for outputting to various places |
||
75 | // |
||
76 | // ------------------------------------------------------------------ |
||
77 | |||
78 | /** |
||
79 | * @return void |
||
80 | */ |
||
81 | public function addOutputToStdout() |
||
82 | { |
||
83 | $this->writer->addOutputToStdout(); |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * @return void |
||
88 | */ |
||
89 | public function addOutputToStderr() |
||
90 | { |
||
91 | $this->writer->addOutputToStderr(); |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * @param string $filename |
||
96 | * @return void |
||
97 | */ |
||
98 | public function addOutputToFile($filename) |
||
99 | { |
||
100 | // make sure $filename isn't a reserved name |
||
101 | switch($filename) |
||
102 | { |
||
103 | case 'stdout': |
||
104 | case 'stderr': |
||
105 | case 'null': |
||
106 | throw new E4xx_OutputFilenameIsAReservedName($filename); |
||
107 | } |
||
108 | |||
109 | $this->writer->addOutputToFile($filename); |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * @param string $output |
||
114 | * @param array|null $style |
||
115 | * @return void |
||
116 | */ |
||
117 | public function write($output, $style = null) |
||
118 | { |
||
119 | $this->writer->write($output, $style); |
||
120 | } |
||
121 | |||
122 | /** |
||
123 | * @param float $duration |
||
124 | * @param array|null $style |
||
125 | * @return void |
||
126 | */ |
||
127 | public function writeDuration($duration, $style = null) |
||
128 | { |
||
129 | // break down the duration into reportable units |
||
130 | $hours = $mins = 0; |
||
131 | |||
132 | // this gives us the ability to report on durations of |
||
133 | // less than one second |
||
134 | $secs = round($duration, 2); |
||
135 | if ($duration > 59) { |
||
136 | $mins = (int)($duration / 60); |
||
137 | // when things take a minute or more, we don't care |
||
138 | // about sub-second accuracy any more |
||
139 | $secs = $duration % 60; |
||
140 | } |
||
141 | else { |
||
142 | } |
||
143 | if ($duration > 3600) { |
||
144 | $hours = (int)($duration / 3600); |
||
145 | } |
||
146 | |||
147 | // turn the breakdown into a printable string |
||
148 | $output = ''; |
||
149 | if ($hours) { |
||
150 | if ($hours > 1) { |
||
151 | $output = "{$hours} hours"; |
||
152 | } |
||
153 | else { |
||
154 | $output = "1 hour"; |
||
155 | } |
||
156 | } |
||
157 | if ($mins) { |
||
158 | $minsUnit = 'mins'; |
||
159 | if ($mins == 1) { |
||
160 | $minsUnit = 'min'; |
||
161 | } |
||
162 | if ($hours && $secs) { |
||
163 | $output .= ", {$mins} {$minsUnit}"; |
||
164 | } |
||
165 | else if ($hours) { |
||
166 | $output .= " and {$mins} {$minsUnit}"; |
||
167 | } |
||
168 | else { |
||
169 | $output = "{$mins} {$minsUnit}"; |
||
170 | } |
||
171 | } |
||
172 | |||
173 | $secsUnit = 'secs'; |
||
174 | if ($secs == 1) { |
||
175 | $secsUnit = 'sec'; |
||
176 | } |
||
177 | if (($hours || $mins) && $secs) { |
||
178 | $output .= " and {$secs} {$secsUnit}"; |
||
179 | } |
||
180 | else { |
||
181 | $output = "{$secs} {$secsUnit}"; |
||
182 | } |
||
183 | |||
184 | // are we using our default style? |
||
185 | if (!$style) { |
||
186 | $style = $this->writer->durationStyle; |
||
187 | } |
||
188 | |||
189 | // send the string out to the user |
||
190 | $this->writer->write($output, $style); |
||
191 | } |
||
192 | |||
193 | /** |
||
194 | * @return OutputWriter |
||
195 | */ |
||
196 | public function getWriter() |
||
197 | { |
||
198 | return $this->writer; |
||
199 | } |
||
200 | |||
201 | // ================================================================== |
||
202 | // |
||
203 | // Colour support |
||
204 | // |
||
205 | // ------------------------------------------------------------------ |
||
206 | |||
207 | /** |
||
208 | * @return void |
||
209 | */ |
||
210 | public function disableColourSupport() |
||
211 | { |
||
212 | $this->writer->setColourMode(self::COLOUR_MODE_OFF); |
||
213 | } |
||
214 | |||
215 | /** |
||
216 | * @return void |
||
217 | */ |
||
218 | public function enableColourSupport() |
||
219 | { |
||
220 | $this->writer->setColourMode(self::COLOUR_MODE_AUTO); |
||
221 | } |
||
222 | |||
223 | /** |
||
224 | * @return void |
||
225 | */ |
||
226 | public function enforceColourSupport() |
||
227 | { |
||
228 | $this->writer->setColourMode(self::COLOUR_MODE_ON); |
||
229 | } |
||
230 | |||
231 | // ================================================================== |
||
232 | // |
||
233 | // These are the methods that Storyplayer will call as things |
||
234 | // happen ... |
||
235 | // |
||
236 | // ------------------------------------------------------------------ |
||
237 | |||
238 | /** |
||
239 | * @param string $version |
||
240 | * @param string $url |
||
241 | * @param string $copyright |
||
242 | * @param string $license |
||
243 | * @return void |
||
244 | */ |
||
245 | abstract public function startStoryplayer($version, $url, $copyright, $license); |
||
246 | |||
247 | /** |
||
248 | * @return void |
||
249 | */ |
||
250 | abstract public function endStoryplayer($duration); |
||
251 | |||
252 | /** |
||
253 | * @return void |
||
254 | */ |
||
255 | abstract public function resetSilentMode(); |
||
256 | |||
257 | /** |
||
258 | * @return void |
||
259 | */ |
||
260 | abstract public function setSilentMode(); |
||
261 | |||
262 | /** |
||
263 | * @return void |
||
264 | */ |
||
265 | abstract public function startPhaseGroup($activity, $name, $details = null); |
||
266 | |||
267 | /** |
||
268 | * @return void |
||
269 | */ |
||
270 | abstract public function endPhaseGroup($result); |
||
271 | |||
272 | /** |
||
273 | * @return void |
||
274 | */ |
||
275 | abstract public function startPhase($phase); |
||
276 | |||
277 | /** |
||
278 | * @return void |
||
279 | */ |
||
280 | abstract public function endPhase($phase, $phaseResult); |
||
281 | |||
282 | /** |
||
283 | * @param string $msg |
||
284 | * @return void |
||
285 | */ |
||
286 | abstract public function logPhaseActivity($msg); |
||
287 | |||
288 | /** |
||
289 | * called when a story logs the (possibly partial) output from |
||
290 | * running a subprocess |
||
291 | * |
||
292 | * @param string $msg the output to log |
||
293 | * @return void |
||
294 | */ |
||
295 | abstract public function logPhaseSubprocessOutput($msg); |
||
296 | |||
297 | /** |
||
298 | * @param string $phaseName |
||
299 | * @param string $msg |
||
300 | * @return void |
||
301 | */ |
||
302 | abstract public function logPhaseError($phaseName, $msg); |
||
303 | |||
304 | /** |
||
305 | * @param string $phaseName |
||
306 | * @param string $msg |
||
307 | * @return void |
||
308 | */ |
||
309 | abstract public function logPhaseSkipped($phaseName, $msg); |
||
310 | |||
311 | /** |
||
312 | * @param string $msg |
||
313 | * |
||
314 | * @return void |
||
315 | */ |
||
316 | abstract public function logCliWarning($msg); |
||
317 | |||
318 | /** |
||
319 | * @param string $msg |
||
320 | * |
||
321 | * @return void |
||
322 | */ |
||
323 | abstract public function logCliError($msg); |
||
324 | |||
325 | /** |
||
326 | * |
||
327 | * @param string $msg |
||
328 | * @param Exception $e |
||
329 | * @return void |
||
330 | */ |
||
331 | abstract public function logCliErrorWithException($msg, $e); |
||
332 | |||
333 | /** |
||
334 | * @param string $msg |
||
335 | * |
||
336 | * @return void |
||
337 | */ |
||
338 | abstract public function logCliInfo($msg); |
||
339 | |||
340 | /** |
||
341 | * @param string $name |
||
342 | * |
||
343 | * @return void |
||
344 | */ |
||
345 | abstract public function logVardump($name, $var); |
||
346 | } |
||
347 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.