mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-04 01:34:07 +02:00
Remove duplicate code
This commit is contained in:
parent
8d6286e6b4
commit
d4b44ebde2
1 changed files with 21 additions and 18 deletions
|
|
@ -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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue