factor out checking for next prompt

This commit is contained in:
Robin Appelman 2016-04-26 15:04:43 +02:00
commit 2522f2f63f

View file

@ -15,6 +15,7 @@ use Icewind\SMB\Exception\NoLoginServerException;
class Connection extends RawConnection { class Connection extends RawConnection {
const DELIMITER = 'smb:'; const DELIMITER = 'smb:';
const DELIMITER_LENGTH = 4;
/** /**
* send input to smbclient * send input to smbclient
@ -48,8 +49,7 @@ class Connection extends RawConnection {
if ($line === false) { if ($line === false) {
$this->unknownError($promptLine); $this->unknownError($promptLine);
} }
$length = mb_strlen(self::DELIMITER); while (!$this->isPrompt($line)) { //next prompt functions as delimiter
while (mb_substr($line, 0, $length) !== self::DELIMITER && $line !== false) { //next prompt functions as delimiter
if (is_callable($callback)) { if (is_callable($callback)) {
$result = $callback($line); $result = $callback($line);
if ($result === false) { // allow the callback to close the connection for infinite running commands if ($result === false) { // allow the callback to close the connection for infinite running commands
@ -63,6 +63,16 @@ class Connection extends RawConnection {
return $output; return $output;
} }
/**
* Check
*
* @param $line
* @return bool
*/
private function isPrompt($line) {
return mb_substr($line, 0, self::DELIMITER_LENGTH) === self::DELIMITER || $line === false;
}
/** /**
* @param string $promptLine (optional) prompt line that might contain some info about the error * @param string $promptLine (optional) prompt line that might contain some info about the error
* @throws ConnectException * @throws ConnectException