mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-03 17:24:07 +02:00
Pass a connection to a command instead of the share
This commit is contained in:
parent
0b2dd15499
commit
2be5320595
6 changed files with 22 additions and 40 deletions
|
|
@ -10,15 +10,15 @@ namespace SMB\Command;
|
||||||
|
|
||||||
abstract class Command {
|
abstract class Command {
|
||||||
/**
|
/**
|
||||||
* @var \SMB\Share $share
|
* @var \SMB\Connection $connection
|
||||||
*/
|
*/
|
||||||
protected $share;
|
protected $connection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \SMB\Share $share
|
* @param \SMB\Connection $connection
|
||||||
*/
|
*/
|
||||||
public function __construct($share) {
|
public function __construct($connection) {
|
||||||
$this->share = $share;
|
$this->connection = $connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -26,8 +26,8 @@ abstract class Command {
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function execute($command) {
|
protected function execute($command) {
|
||||||
$this->share->write($command . PHP_EOL);
|
$this->connection->write($command . PHP_EOL);
|
||||||
$output = $this->share->read();
|
$output = $this->connection->read();
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,8 @@
|
||||||
namespace SMB\Command;
|
namespace SMB\Command;
|
||||||
|
|
||||||
class Del extends Simple {
|
class Del extends Simple {
|
||||||
public function __construct($share) {
|
public function __construct($connection) {
|
||||||
parent::__construct($share);
|
parent::__construct($connection);
|
||||||
$this->command = 'del';
|
$this->command = 'del';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,8 @@
|
||||||
namespace SMB\Command;
|
namespace SMB\Command;
|
||||||
|
|
||||||
class Mkdir extends Simple {
|
class Mkdir extends Simple {
|
||||||
public function __construct($share) {
|
public function __construct($connection) {
|
||||||
parent::__construct($share);
|
parent::__construct($connection);
|
||||||
$this->command = 'mkdir';
|
$this->command = 'mkdir';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,8 @@
|
||||||
namespace SMB\Command;
|
namespace SMB\Command;
|
||||||
|
|
||||||
class Rename extends Double {
|
class Rename extends Double {
|
||||||
public function __construct($share) {
|
public function __construct($connection) {
|
||||||
parent::__construct($share);
|
parent::__construct($connection);
|
||||||
$this->command = 'rename';
|
$this->command = 'rename';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,8 @@
|
||||||
namespace SMB\Command;
|
namespace SMB\Command;
|
||||||
|
|
||||||
class Rmdir extends Simple {
|
class Rmdir extends Simple {
|
||||||
public function __construct($share) {
|
public function __construct($connection) {
|
||||||
parent::__construct($share);
|
parent::__construct($connection);
|
||||||
$this->command = 'rmdir';
|
$this->command = 'rmdir';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ class Share {
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function dir($path) {
|
public function dir($path) {
|
||||||
return (new Command\Dir($this))->run(array('path' => $path));
|
return (new Command\Dir($this->connection))->run(array('path' => $path));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -66,7 +66,7 @@ class Share {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function mkdir($path) {
|
public function mkdir($path) {
|
||||||
return (new Command\Mkdir($this))->run(array('path' => $path));
|
return (new Command\Mkdir($this->connection))->run(array('path' => $path));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -76,7 +76,7 @@ class Share {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function rmdir($path) {
|
public function rmdir($path) {
|
||||||
return (new Command\Rmdir($this))->run(array('path' => $path));
|
return (new Command\Rmdir($this->connection))->run(array('path' => $path));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -86,7 +86,7 @@ class Share {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function del($path) {
|
public function del($path) {
|
||||||
return (new Command\Del($this))->run(array('path' => $path));
|
return (new Command\Del($this->connection))->run(array('path' => $path));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -97,7 +97,7 @@ class Share {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function rename($from, $to) {
|
public function rename($from, $to) {
|
||||||
return (new Command\Rename($this))->run(array('path1' => $from, 'path2' => $to));
|
return (new Command\Rename($this->connection))->run(array('path1' => $from, 'path2' => $to));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -108,7 +108,7 @@ class Share {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function put($source, $target) {
|
public function put($source, $target) {
|
||||||
return (new Command\Put($this))->run(array('path1' => $source, 'path2' => $target));
|
return (new Command\Put($this->connection))->run(array('path1' => $source, 'path2' => $target));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -119,25 +119,7 @@ class Share {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function get($source, $target) {
|
public function get($source, $target) {
|
||||||
return (new Command\Get($this))->run(array('path1' => $source, 'path2' => $target));
|
return (new Command\Get($this->connection))->run(array('path1' => $source, 'path2' => $target));
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* send input to smbclient
|
|
||||||
*
|
|
||||||
* @param string $input
|
|
||||||
*/
|
|
||||||
public function write($input) {
|
|
||||||
$this->connection->write($input);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get all unprocessed output from smbclient
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function read() {
|
|
||||||
return $this->connection->read();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue