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