| 1 | <?php |
||
| 9 | class InteractiveProcess |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var Pipe |
||
| 13 | */ |
||
| 14 | private $pipe; |
||
| 15 | /** |
||
| 16 | * @var WaitStrategy |
||
| 17 | */ |
||
| 18 | private $waitStrategy; |
||
| 19 | /** |
||
| 20 | * @var Process |
||
| 21 | */ |
||
| 22 | private $process; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @param Process $process |
||
| 26 | * @param Pipe $pipe |
||
| 27 | * @param WaitStrategy $waitStrategy |
||
| 28 | */ |
||
| 29 | public function __construct(Process $process, Pipe $pipe, WaitStrategy $waitStrategy) |
||
| 30 | { |
||
| 31 | $this->pipe = $pipe; |
||
| 32 | $this->waitStrategy = $waitStrategy; |
||
| 33 | $this->process = $process; |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @param Pipe $pipe |
||
| 38 | */ |
||
| 39 | public function updatePipe(Pipe $pipe) |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @param WaitStrategy $waitStrategy |
||
| 46 | */ |
||
| 47 | public function updateWaitStrategy(WaitStrategy $waitStrategy) |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Run the process. |
||
| 54 | */ |
||
| 55 | public function run() |
||
| 56 | { |
||
| 57 | $this->process->start(function ($type, $buffer) { |
||
| 58 | if (Process::ERR === $type) { |
||
| 59 | $this->pipe->error($buffer); |
||
| 60 | } else { |
||
| 61 | $this->pipe->output($buffer); |
||
| 62 | } |
||
| 63 | }); |
||
| 64 | |||
| 65 | $this->waitStrategy->wait($this->process); |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @return Process |
||
| 70 | */ |
||
| 71 | public function getProcess() |
||
| 75 | } |
||
| 76 |