|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Paraunit\Process; |
|
5
|
|
|
|
|
6
|
|
|
use Paraunit\Configuration\EnvVariables; |
|
7
|
|
|
use Symfony\Component\Process\Process; |
|
8
|
|
|
use Symfony\Component\Process\ProcessBuilder; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class SymfonyProcessWrapper |
|
12
|
|
|
* @package Paraunit\Process |
|
13
|
|
|
*/ |
|
14
|
|
|
class SymfonyProcessWrapper extends AbstractParaunitProcess |
|
15
|
|
|
{ |
|
16
|
|
|
/** @var ProcessBuilder */ |
|
17
|
|
|
private $processBuilder; |
|
18
|
|
|
|
|
19
|
|
|
/** @var Process */ |
|
20
|
|
|
private $process; |
|
21
|
|
|
|
|
22
|
|
|
/** @var string */ |
|
23
|
|
|
protected $commandLine; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* {@inheritdoc} |
|
27
|
|
|
*/ |
|
28
|
20 |
|
public function __construct(ProcessBuilder $processBuilder, string $filename) |
|
29
|
|
|
{ |
|
30
|
20 |
|
parent::__construct($filename); |
|
31
|
20 |
|
$this->processBuilder = $processBuilder; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
16 |
|
public function isTerminated(): bool |
|
35
|
|
|
{ |
|
36
|
16 |
|
return $this->process->isTerminated(); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param array $env |
|
41
|
|
|
* @throws \Symfony\Component\Process\Exception\LogicException |
|
42
|
|
|
* @throws \Symfony\Component\Process\Exception\RuntimeException |
|
43
|
|
|
*/ |
|
44
|
17 |
|
public function start(array $env = []) |
|
45
|
|
|
{ |
|
46
|
17 |
|
$env[EnvVariables::PROCESS_UNIQUE_ID] = $this->getUniqueId(); |
|
47
|
17 |
|
$this->processBuilder->addEnvironmentVariables($env); |
|
48
|
|
|
|
|
49
|
17 |
|
$this->process = $this->processBuilder->getProcess(); |
|
50
|
17 |
|
$this->process->start(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @return string |
|
55
|
|
|
* @throws \Symfony\Component\Process\Exception\LogicException |
|
56
|
|
|
*/ |
|
57
|
5 |
|
public function getOutput(): string |
|
58
|
|
|
{ |
|
59
|
5 |
|
return $this->process->getOutput() ?? ''; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @return int|null |
|
64
|
|
|
* @throws \Symfony\Component\Process\Exception\RuntimeException |
|
65
|
|
|
*/ |
|
66
|
16 |
|
public function getExitCode() |
|
67
|
|
|
{ |
|
68
|
16 |
|
return $this->process->getExitCode(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @return void |
|
73
|
|
|
* @throws \Symfony\Component\Process\Exception\RuntimeException |
|
74
|
|
|
*/ |
|
75
|
5 |
|
public function reset() |
|
76
|
|
|
{ |
|
77
|
5 |
|
parent::reset(); |
|
78
|
|
|
|
|
79
|
5 |
|
$this->process = null; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @return string |
|
84
|
|
|
*/ |
|
85
|
1 |
|
public function getCommandLine(): string |
|
86
|
|
|
{ |
|
87
|
1 |
|
return $this->process->getCommandLine(); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|