1 | <?php |
||
13 | class RawConnection { |
||
14 | /** |
||
15 | * @var string |
||
16 | */ |
||
17 | private $command; |
||
18 | |||
19 | /** |
||
20 | * @var string[] |
||
21 | */ |
||
22 | private $env; |
||
23 | |||
24 | /** |
||
25 | * @var resource[] $pipes |
||
26 | * |
||
27 | * $pipes[0] holds STDIN for smbclient |
||
28 | * $pipes[1] holds STDOUT for smbclient |
||
29 | * $pipes[3] holds the authfile for smbclient |
||
30 | * $pipes[4] holds the stream for writing files |
||
31 | * $pipes[5] holds the stream for reading files |
||
32 | */ |
||
33 | private $pipes = []; |
||
34 | |||
35 | /** |
||
36 | * @var resource|null $process |
||
37 | */ |
||
38 | private $process; |
||
39 | |||
40 | /** |
||
41 | * @var resource|null $authStream |
||
42 | */ |
||
43 | private $authStream = null; |
||
44 | |||
45 | /** |
||
46 | * @param string $command |
||
47 | * @param array<string, string> $env |
||
48 | 494 | */ |
|
49 | 494 | public function __construct(string $command, array $env = []) { |
|
53 | |||
54 | /** |
||
55 | * @throws ConnectException |
||
56 | 494 | * @psalm-assert resource $this->process |
|
57 | 494 | */ |
|
58 | public function connect(): void { |
||
84 | |||
85 | /** |
||
86 | * check if the connection is still active |
||
87 | * |
||
88 | * @return bool |
||
89 | 494 | * @psalm-assert-if-true resource $this->process |
|
90 | 494 | */ |
|
91 | 494 | public function isValid(): bool { |
|
99 | |||
100 | /** |
||
101 | * send input to the process |
||
102 | * |
||
103 | 486 | * @param string $input |
|
104 | 486 | * @return int|bool |
|
105 | 486 | */ |
|
106 | 486 | public function write(string $input) { |
|
111 | |||
112 | /** |
||
113 | * read a line of output |
||
114 | 494 | * |
|
115 | 494 | * @return string|false |
|
116 | */ |
||
117 | public function readLine() { |
||
120 | |||
121 | /** |
||
122 | * read a line of output |
||
123 | * |
||
124 | * @return string|false |
||
125 | */ |
||
126 | public function readError() { |
||
130 | |||
131 | /** |
||
132 | 10 | * get all output until the process closes |
|
133 | 10 | * |
|
134 | 10 | * @return string[] |
|
135 | 10 | */ |
|
136 | public function readAll(): array { |
||
143 | |||
144 | 494 | /** |
|
145 | 494 | * @return resource |
|
146 | */ |
||
147 | public function getInputStream() { |
||
150 | |||
151 | /** |
||
152 | 494 | * @return resource |
|
153 | 494 | */ |
|
154 | public function getOutputStream() { |
||
157 | 32 | ||
158 | /** |
||
159 | * @return resource |
||
160 | 32 | */ |
|
161 | 32 | public function getErrorStream() { |
|
164 | 494 | ||
165 | 494 | /** |
|
166 | * @return resource|null |
||
167 | 494 | */ |
|
168 | public function getAuthStream() { |
||
171 | 494 | ||
172 | /** |
||
173 | 494 | * @return resource |
|
174 | 494 | */ |
|
175 | 34 | public function getFileInputStream() { |
|
178 | 494 | ||
179 | /** |
||
180 | 494 | * @return resource |
|
181 | 494 | */ |
|
182 | public function getFileOutputStream() { |
||
185 | 2 | ||
186 | 2 | /** |
|
187 | * @param string|null $user |
||
188 | 494 | * @param string|null $password |
|
189 | 494 | * @psalm-assert resource $this->authStream |
|
190 | 494 | */ |
|
191 | public function writeAuthentication(?string $user, ?string $password): void { |
||
199 | |||
200 | /** |
||
201 | * @param bool $terminate |
||
202 | * @psalm-assert null $this->process |
||
203 | */ |
||
204 | public function close(bool $terminate = true): void { |
||
214 | |||
215 | public function reconnect(): void { |
||
219 | |||
220 | public function __destruct() { |
||
223 | } |
||
224 |