mirror of
https://codeberg.org/icewind/SMB.git
synced 2026-06-03 09:14:06 +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 {
|
||||
/**
|
||||
* @var \SMB\Share $share
|
||||
* @var \SMB\Connection $connection
|
||||
*/
|
||||
protected $share;
|
||||
protected $connection;
|
||||
|
||||
/**
|
||||
* @param \SMB\Share $share
|
||||
* @param \SMB\Connection $connection
|
||||
*/
|
||||
public function __construct($share) {
|
||||
$this->share = $share;
|
||||
public function __construct($connection) {
|
||||
$this->connection = $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -26,8 +26,8 @@ abstract class Command {
|
|||
* @return array
|
||||
*/
|
||||
protected function execute($command) {
|
||||
$this->share->write($command . PHP_EOL);
|
||||
$output = $this->share->read();
|
||||
$this->connection->write($command . PHP_EOL);
|
||||
$output = $this->connection->read();
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@
|
|||
namespace SMB\Command;
|
||||
|
||||
class Del extends Simple {
|
||||
public function __construct($share) {
|
||||
parent::__construct($share);
|
||||
public function __construct($connection) {
|
||||
parent::__construct($connection);
|
||||
$this->command = 'del';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@
|
|||
namespace SMB\Command;
|
||||
|
||||
class Mkdir extends Simple {
|
||||
public function __construct($share) {
|
||||
parent::__construct($share);
|
||||
public function __construct($connection) {
|
||||
parent::__construct($connection);
|
||||
$this->command = 'mkdir';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@
|
|||
namespace SMB\Command;
|
||||
|
||||
class Rename extends Double {
|
||||
public function __construct($share) {
|
||||
parent::__construct($share);
|
||||
public function __construct($connection) {
|
||||
parent::__construct($connection);
|
||||
$this->command = 'rename';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@
|
|||
namespace SMB\Command;
|
||||
|
||||
class Rmdir extends Simple {
|
||||
public function __construct($share) {
|
||||
parent::__construct($share);
|
||||
public function __construct($connection) {
|
||||
parent::__construct($connection);
|
||||
$this->command = 'rmdir';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ class Share {
|
|||
* @return array
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
public function get($source, $target) {
|
||||
return (new Command\Get($this))->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();
|
||||
return (new Command\Get($this->connection))->run(array('path1' => $source, 'path2' => $target));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue