1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of tenside/core. |
5
|
|
|
* |
6
|
|
|
* (c) Christian Schiffler <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* This project is provided in good faith and hope to be usable by anyone. |
12
|
|
|
* |
13
|
|
|
* @package tenside/core |
14
|
|
|
* @author Christian Schiffler <[email protected]> |
15
|
|
|
* @copyright 2015 Christian Schiffler <[email protected]> |
16
|
|
|
* @license https://github.com/tenside/core/blob/master/LICENSE MIT |
17
|
|
|
* @link https://github.com/tenside/core |
18
|
|
|
* @filesource |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace Tenside\Core\Task; |
22
|
|
|
|
23
|
|
|
use Symfony\Component\Process\Exception\ProcessFailedException; |
24
|
|
|
use Symfony\Component\Process\Process; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* This class is an abstract base for running a cli command. |
28
|
|
|
*/ |
29
|
|
|
abstract class AbstractCliSpawningTask extends Task |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* Run a process and throw exception if it failed. |
33
|
|
|
* |
34
|
|
|
* @param Process $process The process to run. |
35
|
|
|
* |
36
|
|
|
* @return void |
37
|
|
|
* |
38
|
|
|
* @throws ProcessFailedException When the process returned a non zero result. |
39
|
|
|
*/ |
40
|
|
|
protected function runProcess(Process $process) |
41
|
|
|
{ |
42
|
|
|
$ioHandler = $this->getIO(); |
43
|
|
|
$process->run( |
44
|
|
|
function ($pipe, $content) use ($ioHandler) { |
45
|
|
|
if (Process::ERR === $pipe) { |
46
|
|
|
$ioHandler->writeError($content, false); |
47
|
|
|
// @codingStandardsIgnoreStart |
48
|
|
|
return; |
49
|
|
|
// @codingStandardsIgnoreEnd |
50
|
|
|
} |
51
|
|
|
$ioHandler->write($content, false); |
52
|
|
|
} |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
if (0 !== $process->getExitCode()) { |
56
|
|
|
throw new ProcessFailedException($process); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|