diff --git a/src/Server.php b/src/Server.php index d291b6f..87aa0ac 100644 --- a/src/Server.php +++ b/src/Server.php @@ -109,6 +109,27 @@ class Server { return $output; } + /** + * Filters the raw output + * + * @param string $filter + * @return array + */ + private function filterRawOutput($rawOutput, $filter) { + $filtered = array(); + + foreach ($rawOutput as $line) { + if (strpos($line, '|')) { + list($type, $name, $description) = explode('|', $line); + if (strtolower($type) === $filter) { + $filtered[$name] = $description; + } + } + } + + return $filtered; + } + /** * @return \Icewind\SMB\IShare[] * @@ -116,15 +137,7 @@ class Server { public function listShares() { $output = $this->listSMB(); - $shareNames = array(); - foreach ($output as $line) { - if (strpos($line, '|')) { - list($type, $name, $description) = explode('|', $line); - if (strtolower($type) === 'disk') { - $shareNames[$name] = $description; - } - } - } + $shareNames = $this->filterRawOutput($output, 'disk'); $shares = array(); foreach ($shareNames as $name => $description) { @@ -140,17 +153,7 @@ class Server { public function listPrinters() { $output = $this->listSMB(); - $printers = array(); - foreach ($output as $line) { - if (strpos($line, '|')) { - list($type, $name, $description) = explode('|', $line); - if (strtolower($type) === 'printer') { - $printers[$name] = $description; - } - } - } - - return $printers; + return $this->filterRawOutput($output, 'printer'); } /**