Total Complexity | 10 |
Total Lines | 66 |
Duplicated Lines | 0 % |
Coverage | 0% |
Changes | 0 |
1 | <?php |
||
9 | class Process implements ProcessInterface |
||
10 | { |
||
11 | /** |
||
12 | * @var resource A 'process' resource |
||
13 | */ |
||
14 | private $process; |
||
15 | |||
16 | /** |
||
17 | * @var IPC - |
||
18 | */ |
||
19 | private $ipc; |
||
20 | |||
21 | /** |
||
22 | * @var bool |
||
23 | */ |
||
24 | private $running = true; |
||
25 | |||
26 | public function __construct(string $executable, array $overrideDescriptors = []) |
||
27 | { |
||
28 | $pipes = []; |
||
29 | $process = proc_open($executable, IPC::buildDescriptors($overrideDescriptors), $pipes); |
||
30 | if (!(is_resource($process) && get_resource_type($process) === "process")) { |
||
31 | throw new Exception\PinEntryException("Failed to start process"); |
||
32 | } |
||
33 | |||
34 | $this->ipc = new IPC($pipes); |
||
35 | $this->process = $process; |
||
36 | } |
||
37 | |||
38 | public function __destruct() |
||
39 | { |
||
40 | $this->close(); |
||
41 | } |
||
42 | |||
43 | public function close(): bool |
||
44 | { |
||
45 | if ($this->running) { |
||
46 | $this->stopRunning(); |
||
47 | } |
||
48 | return true; |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * Called during shutdown routine. Per documentation, |
||
53 | * file handles should be closed before we call proc_close |
||
54 | */ |
||
55 | private function stopRunning() |
||
56 | { |
||
57 | $this->ipc->close(); |
||
58 | proc_close($this->process); |
||
59 | $this->running = false; |
||
60 | } |
||
61 | |||
62 | public function getStatus(): array |
||
65 | } |
||
66 | |||
67 | public function send(string $data) |
||
68 | { |
||
69 | $this->ipc->send($data); |
||
70 | } |
||
71 | |||
72 | public function recv(): string |
||
75 | } |
||
76 | } |
||
77 |