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;
|
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[]
|
* @return \Icewind\SMB\IShare[]
|
||||||
*
|
*
|
||||||
|
|
@ -116,15 +137,7 @@ class Server {
|
||||||
public function listShares() {
|
public function listShares() {
|
||||||
$output = $this->listSMB();
|
$output = $this->listSMB();
|
||||||
|
|
||||||
$shareNames = array();
|
$shareNames = $this->filterRawOutput($output, 'disk');
|
||||||
foreach ($output as $line) {
|
|
||||||
if (strpos($line, '|')) {
|
|
||||||
list($type, $name, $description) = explode('|', $line);
|
|
||||||
if (strtolower($type) === 'disk') {
|
|
||||||
$shareNames[$name] = $description;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$shares = array();
|
$shares = array();
|
||||||
foreach ($shareNames as $name => $description) {
|
foreach ($shareNames as $name => $description) {
|
||||||
|
|
@ -140,17 +153,7 @@ class Server {
|
||||||
public function listPrinters() {
|
public function listPrinters() {
|
||||||
$output = $this->listSMB();
|
$output = $this->listSMB();
|
||||||
|
|
||||||
$printers = array();
|
return $this->filterRawOutput($output, 'printer');
|
||||||
foreach ($output as $line) {
|
|
||||||
if (strpos($line, '|')) {
|
|
||||||
list($type, $name, $description) = explode('|', $line);
|
|
||||||
if (strtolower($type) === 'printer') {
|
|
||||||
$printers[$name] = $description;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $printers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue