remove code duplication for listShares

This commit is contained in:
Robin Appelman 2016-08-26 23:45:29 +02:00
commit b43c129ed9
4 changed files with 58 additions and 55 deletions

View file

@ -135,32 +135,11 @@ class Server {
$connection = new RawConnection($command);
$connection->writeAuthentication($this->getUser(), $this->getPassword());
$output = $connection->readAll();
$parser = new Parser($this->timezoneProvider);
$line = $output[0];
$parser->checkConnectionError($output[0]);
$line = rtrim($line, ')');
if (substr($line, -23) === ErrorCodes::LogonFailure) {
throw new AuthenticationException();
}
if (substr($line, -26) === ErrorCodes::BadHostName) {
throw new InvalidHostException();
}
if (substr($line, -22) === ErrorCodes::Unsuccessful) {
throw new InvalidHostException();
}
if (substr($line, -28) === ErrorCodes::ConnectionRefused) {
throw new InvalidHostException();
}
$shareNames = array();
foreach ($output as $line) {
if (strpos($line, '|')) {
list($type, $name, $description) = explode('|', $line);
if (strtolower($type) === 'disk') {
$shareNames[$name] = $description;
}
}
}
$shareNames = $parser->parseListShares($output);
$shares = array();
foreach ($shareNames as $name => $description) {