-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProcess.php
More file actions
62 lines (52 loc) · 1.39 KB
/
Process.php
File metadata and controls
62 lines (52 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
namespace Task\Plugin\Process;
use Symfony\Component\Process\Process as BaseProcess;
use Task\Plugin\Stream\WritableInterface;
use Task\Plugin\Stream\ReadableInterface;
class Process extends BaseProcess implements WritableInterface, ReadableInterface
{
public static function extend(BaseProcess $proc)
{
return new static(
$proc->getCommandLine(),
$proc->getWorkingDirectory(),
$proc->getEnv(),
$proc->getStdin(),
$proc->getTimeout(),
$proc->getOptions()
);
}
public function run($callback = null)
{
$exitcode = parent::run($callback);
if ($this->isSuccessful()) {
return $exitcode;
} else {
throw new \RuntimeException(
sprintf(
"%s returned %d\n%s",
$this->getCommandLine(),
$this->getExitCode(),
$this->getErrorOutput()
)
);
}
return $this;
}
public function read()
{
$this->run();
return $this->getOutput();
}
public function write($data)
{
return $this->setStdin($data);
}
public function pipe(WritableInterface $to)
{
$this->run(function ($type, $data) use ($to) {
$to->write($data);
});
return $to;
}
}