1 | <?php |
||
13 | class RealtimeOutputHandler |
||
14 | { |
||
15 | protected $stdout; |
||
16 | protected $stderr; |
||
17 | protected $stdoutMarker = ''; |
||
18 | protected $stderrMarker = ''; |
||
19 | |||
20 | /** |
||
21 | * Provide the output streams to use for stdout and stderr |
||
22 | */ |
||
23 | const MARKER_ERR = '> '; |
||
24 | |||
25 | public function __construct(OutputInterface $stdout, OutputInterface $stderr) |
||
33 | |||
34 | /** |
||
35 | * This gives us an opportunity to adapt to the settings of the |
||
36 | * process object (e.g. do we need to do anything differently if |
||
37 | * it is in tty mode, etc.) |
||
38 | */ |
||
39 | public function configure(Process $process) |
||
43 | |||
44 | /** |
||
45 | * setStderrMarker defines the string that should be added at |
||
46 | * the beginning of every line of stderr that is printed. |
||
47 | */ |
||
48 | public function setStderrMarker($marker) |
||
53 | |||
54 | /** |
||
55 | * setStdoutMarker defines the string that should be added at |
||
56 | * the beginning of every line of stdout that is printed. |
||
57 | */ |
||
58 | public function setStdoutMarker($marker) |
||
63 | |||
64 | /** |
||
65 | * hideStdout overrides whatever was formerly stored in $this->stdout |
||
66 | * with a null output buffer so that none of the standard output data |
||
67 | * is visible. |
||
68 | */ |
||
69 | public function hideStdout() |
||
75 | |||
76 | /** |
||
77 | * hideStderr serves the same function as hideStdout, but for the |
||
78 | * standard error stream. Note that it is not useful to unconditionally |
||
79 | * call both hideStdout and hideStderr; if no output is desired, then |
||
80 | * the RealtimeOutputHandler should not be used. |
||
81 | */ |
||
82 | public function hideStderr() |
||
88 | |||
89 | /** |
||
90 | * If this object is used as a callable, then run 'handleOutput'. |
||
91 | */ |
||
92 | public function __invoke($type, $buffer) |
||
96 | |||
97 | /** |
||
98 | * Helper method when you want real-time output from a Process call. |
||
99 | * @param string $type |
||
100 | * @param string $buffer |
||
101 | */ |
||
102 | public function handleOutput($type, $buffer) |
||
110 | |||
111 | /** |
||
112 | * Make sure that every line in $buffer begins with a MARKER_ERR. |
||
113 | */ |
||
114 | protected function addMarker($buffer, $marker) |
||
123 | } |
||
124 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.