add basic smb notify support

at the moment this only works when using the smbclient based backend
This commit is contained in:
Robin Appelman 2016-04-25 18:15:34 +02:00
commit cf23de2702
4 changed files with 56 additions and 2 deletions

View file

@ -28,6 +28,7 @@ class Connection extends RawConnection {
/**
* get all unprocessed output from smbclient until the next prompt
*
* @param callable $callback (optional) callback to call for every line read
* @return string
* @throws AuthenticationException
* @throws ConnectException
@ -35,7 +36,7 @@ class Connection extends RawConnection {
* @throws InvalidHostException
* @throws NoLoginServerException
*/
public function read() {
public function read(callable $callback = null) {
if (!$this->isValid()) {
throw new ConnectionException('Connection not valid');
}
@ -57,7 +58,13 @@ class Connection extends RawConnection {
}
}
$length = mb_strlen(self::DELIMITER);
while (mb_substr($line, 0, $length) !== self::DELIMITER) { //next prompt functions as delimiter
while (mb_substr($line, 0, $length) !== self::DELIMITER && $line) { //next prompt functions as delimiter
if (is_callable($callback)) {
$result = $callback($line);
if ($result === false) { // allow the callback to close the connection for infinite running commands
$this->close(true);
}
}
$output[] .= $line;
$line = $this->readLine();
}