mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-04 01:34:07 +02:00
all the types
This commit is contained in:
parent
515b42586e
commit
84fa890ea7
28 changed files with 330 additions and 110 deletions
|
|
@ -30,7 +30,7 @@ class RawConnection {
|
|||
* $pipes[4] holds the stream for writing files
|
||||
* $pipes[5] holds the stream for reading files
|
||||
*/
|
||||
private $pipes;
|
||||
private $pipes = [];
|
||||
|
||||
/**
|
||||
* @var resource|null $process
|
||||
|
|
@ -42,6 +42,10 @@ class RawConnection {
|
|||
*/
|
||||
private $authStream = null;
|
||||
|
||||
/**
|
||||
* @param string $command
|
||||
* @param array<string, string> $env
|
||||
*/
|
||||
public function __construct(string $command, array $env = []) {
|
||||
$this->command = $command;
|
||||
$this->env = $env;
|
||||
|
|
@ -49,8 +53,9 @@ class RawConnection {
|
|||
|
||||
/**
|
||||
* @throws ConnectException
|
||||
* @psalm-assert resource $this->process
|
||||
*/
|
||||
public function connect() {
|
||||
public function connect(): void {
|
||||
if (is_null($this->getAuthStream())) {
|
||||
throw new ConnectException('Authentication not set before connecting');
|
||||
}
|
||||
|
|
@ -81,6 +86,7 @@ class RawConnection {
|
|||
* check if the connection is still active
|
||||
*
|
||||
* @return bool
|
||||
* @psalm-assert-if-true resource $this->process
|
||||
*/
|
||||
public function isValid(): bool {
|
||||
if (is_resource($this->process)) {
|
||||
|
|
@ -118,7 +124,8 @@ class RawConnection {
|
|||
* @return string|false
|
||||
*/
|
||||
public function readError() {
|
||||
return trim(stream_get_line($this->getErrorStream(), 4086));
|
||||
$line = stream_get_line($this->getErrorStream(), 4086);
|
||||
return $line !== false ? trim($line) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -134,40 +141,67 @@ class RawConnection {
|
|||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return resource
|
||||
*/
|
||||
public function getInputStream() {
|
||||
return $this->pipes[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return resource
|
||||
*/
|
||||
public function getOutputStream() {
|
||||
return $this->pipes[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return resource
|
||||
*/
|
||||
public function getErrorStream() {
|
||||
return $this->pipes[2];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return resource|null
|
||||
*/
|
||||
public function getAuthStream() {
|
||||
return $this->authStream;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return resource
|
||||
*/
|
||||
public function getFileInputStream() {
|
||||
return $this->pipes[4];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return resource
|
||||
*/
|
||||
public function getFileOutputStream() {
|
||||
return $this->pipes[5];
|
||||
}
|
||||
|
||||
public function writeAuthentication(?string $user, ?string $password) {
|
||||
/**
|
||||
* @param string|null $user
|
||||
* @param string|null $password
|
||||
* @psalm-assert resource $this->authStream
|
||||
*/
|
||||
public function writeAuthentication(?string $user, ?string $password): void {
|
||||
$auth = ($password === null)
|
||||
? "username=$user"
|
||||
: "username=$user\npassword=$password\n";
|
||||
|
||||
$this->authStream = fopen('php://temp', 'w+');
|
||||
fwrite($this->getAuthStream(), $auth);
|
||||
fwrite($this->authStream, $auth);
|
||||
}
|
||||
|
||||
public function close(bool $terminate = true) {
|
||||
/**
|
||||
* @param bool $terminate
|
||||
* @psalm-assert null $this->process
|
||||
*/
|
||||
public function close(bool $terminate = true): void {
|
||||
if (!is_resource($this->process)) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -175,9 +209,10 @@ class RawConnection {
|
|||
proc_terminate($this->process);
|
||||
}
|
||||
proc_close($this->process);
|
||||
$this->process = null;
|
||||
}
|
||||
|
||||
public function reconnect() {
|
||||
public function reconnect(): void {
|
||||
$this->close();
|
||||
$this->connect();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue