Rename Connection to Server and fix some other naming inconsistencies

This commit is contained in:
Robin Appelman 2013-03-03 22:14:08 +01:00
commit 89cb5a2104
10 changed files with 53 additions and 33 deletions

View file

@ -10,12 +10,12 @@ namespace SMB\Command;
abstract class Command { abstract class Command {
/** /**
* @var \SMB\Share $connection * @var \SMB\Share $share
*/ */
protected $share; protected $share;
/** /**
* @param \SMB\Share $connection * @param \SMB\Share $share
*/ */
public function __construct($share) { public function __construct($share) {
$this->share = $share; $this->share = $share;

View file

@ -9,8 +9,8 @@
namespace SMB\Command; namespace SMB\Command;
class Del extends Simple { class Del extends Simple {
public function __construct($connection) { public function __construct($share) {
parent::__construct($connection); parent::__construct($share);
$this->command = 'del'; $this->command = 'del';
} }
} }

View file

@ -9,8 +9,8 @@
namespace SMB\Command; namespace SMB\Command;
class Dir extends Command { class Dir extends Command {
public function __construct($connection) { public function __construct($share) {
parent::__construct($connection); parent::__construct($share);
} }
public function run($arguments) { public function run($arguments) {

View file

@ -8,10 +8,23 @@
namespace SMB\Command; namespace SMB\Command;
class ListShares extends Command { class ListShares {
public function run($arguments) {
$auth = $this->escape($this->connection->getAuthString()); /**
$command = self::CLIENT . ' -N -U ' . $auth . ' ' . '-gL ' . $this->escape($this->connection->getHost()) . ' 2> /dev/null'; * @var \SMB\Server $server
*/
private $server;
/**
* @param \SMB\Server $server
*/
public function __construct($server){
$this->server=$server;
}
public function run() {
$auth = escapeshellarg($this->server->getAuthString());
$command = \SMB\Server::CLIENT . ' -N -U ' . $auth . ' ' . '-gL ' . escapeshellarg($this->server->getHost()) . ' 2> /dev/null';
exec($command, $output); exec($command, $output);
return $this->parseOutput($output); return $this->parseOutput($output);
} }

View file

@ -9,8 +9,8 @@
namespace SMB\Command; namespace SMB\Command;
class Mkdir extends Simple { class Mkdir extends Simple {
public function __construct($connection) { public function __construct($share) {
parent::__construct($connection); parent::__construct($share);
$this->command = 'mkdir'; $this->command = 'mkdir';
} }
} }

View file

@ -9,8 +9,8 @@
namespace SMB\Command; namespace SMB\Command;
class Rename extends Double { class Rename extends Double {
public function __construct($connection) { public function __construct($share) {
parent::__construct($connection); parent::__construct($share);
$this->command = 'rename'; $this->command = 'rename';
} }
} }

View file

@ -9,8 +9,8 @@
namespace SMB\Command; namespace SMB\Command;
class Rmdir extends Simple { class Rmdir extends Simple {
public function __construct($connection) { public function __construct($share) {
parent::__construct($connection); parent::__construct($share);
$this->command = 'rmdir'; $this->command = 'rmdir';
} }
} }

View file

@ -8,7 +8,7 @@
namespace SMB; namespace SMB;
class Connection { class Server {
const CLIENT = 'smbclient'; const CLIENT = 'smbclient';
const LOCALE = 'en_US.UTF-8'; const LOCALE = 'en_US.UTF-8';

View file

@ -10,9 +10,9 @@ namespace SMB;
class Share { class Share {
/** /**
* @var Connection $connection * @var Server $server
*/ */
private $connection; private $server;
/** /**
* @var resource $process * @var resource $process
@ -33,23 +33,23 @@ class Share {
private $name; private $name;
/** /**
* @param Connection $connection * @param Server $server
* @param string $share * @param string $share
*/ */
public function __construct($connection, $name) { public function __construct($server, $name) {
$this->connection = $connection; $this->server = $server;
$this->name = $name; $this->name = $name;
$descriptorSpec = array( $descriptorSpec = array(
0 => array("pipe", "r"), 0 => array("pipe", "r"),
1 => array("pipe", "w"), 1 => array("pipe", "w"),
2 => array("file", "/tmp/smberror", "a") // 2 => array("file", "/tmp/smberror", "a")
); );
putenv('LC_ALL=' . Connection::LOCALE); putenv('LC_ALL=' . Server::LOCALE);
setlocale(LC_ALL, Connection::LOCALE); setlocale(LC_ALL, Server::LOCALE);
$command = Connection::CLIENT . ' -N -U ' . $this->connection->getAuthString() . $command = Server::CLIENT . ' -N -U ' . $this->server->getAuthString() .
' //' . $this->connection->getHost() . '/' . $this->name; ' //' . $this->server->getHost() . '/' . $this->name;
$this->process = proc_open($command, $descriptorSpec, $this->pipes, null, array( $this->process = proc_open($command, $descriptorSpec, $this->pipes, null, array(
'CLI_FORCE_INTERACTIVE' => 'y' // Needed or the prompt isn't displayed!! 'CLI_FORCE_INTERACTIVE' => 'y' // Needed or the prompt isn't displayed!!
)); ));
@ -161,4 +161,11 @@ class Share {
} }
return $output; return $output;
} }
/**
* @return Server
*/
public function getServer(){
return $this->server;
}
} }

View file

@ -2,9 +2,9 @@
class Test extends PHPUnit_Framework_TestCase { class Test extends PHPUnit_Framework_TestCase {
/** /**
* @var SMB\Connection $connection * @var SMB\Server $server
*/ */
private $connection; private $server;
/** /**
* @var SMB\Share $share * @var SMB\Share $share
@ -17,14 +17,14 @@ class Test extends PHPUnit_Framework_TestCase {
private $root; private $root;
public function setUp() { public function setUp() {
$this->connection = new SMB\Connection('localhost', 'test', 'test'); $this->server = new SMB\Server('localhost', 'test', 'test');
$this->share = $this->connection->getShare('test'); $this->share = $this->server->getShare('test');
$this->root = '/' . uniqid(); $this->root = '/' . uniqid();
$this->share->mkdir($this->root); $this->share->mkdir($this->root);
} }
public function tearDown() { public function tearDown() {
$this->share->rmdir($this->root); // $this->share->rmdir($this->root);
} }
public function testDirectory() { public function testDirectory() {
@ -77,7 +77,7 @@ class Test extends PHPUnit_Framework_TestCase {
public function testEscaping() { public function testEscaping() {
// / ? < > \ : * | ” are illegal characters in path on windows, no use trying to get them working // / ? < > \ : * | ” are illegal characters in path on windows, no use trying to get them working
$names = array('simple', 'with spaces', "single'quote'"); $names = array('simple', 'with spaces', "single'quote'", '$as#d');
$text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua'; $text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua';
$tmpFile1 = tempnam('/tmp', 'smb_test_'); $tmpFile1 = tempnam('/tmp', 'smb_test_');