Error handling in NativeStream

This commit is contained in:
Robin Appelman 2014-08-03 14:49:00 +02:00
commit fdb606257d
3 changed files with 17 additions and 11 deletions

View file

@ -24,9 +24,6 @@ class NativeServer extends Server {
} }
protected function connect() { protected function connect() {
if ($this->state and is_resource($this->state)) {
return;
}
$user = $this->getUser(); $user = $this->getUser();
$workgroup = null; $workgroup = null;
if (strpos($user, '/')) { if (strpos($user, '/')) {

View file

@ -222,7 +222,7 @@ class NativeShare implements IShare {
public function read($source) { public function read($source) {
$this->connect(); $this->connect();
$handle = $this->state->open($this->buildUrl($source), 'r'); $handle = $this->state->open($this->buildUrl($source), 'r');
return NativeStream::wrap($this->state->getState(), $handle, 'r'); return NativeStream::wrap($this->state, $handle, 'r');
} }
/** /**
@ -237,7 +237,7 @@ class NativeShare implements IShare {
public function write($source) { public function write($source) {
$this->connect(); $this->connect();
$handle = $this->state->create($this->buildUrl($source)); $handle = $this->state->create($this->buildUrl($source));
return NativeStream::wrap($this->state->getState(), $handle, 'w'); return NativeStream::wrap($this->state, $handle, 'w');
} }
/** /**

View file

@ -8,16 +8,25 @@
namespace Icewind\SMB; namespace Icewind\SMB;
class NativeStream { class NativeStream {
/**
* @var resource
*/
public $context; public $context;
/**
* @var \Icewind\SMB\NativeState
*/
private $state; private $state;
/**
* @var resource
*/
private $handle; private $handle;
/** /**
* Wrap a stream from libsmbclient-php into a regular php stream * Wrap a stream from libsmbclient-php into a regular php stream
* *
* @param resource $state * @param \Icewind\SMB\NativeState $state
* @param resource $smbStream * @param resource $smbStream
* @param string $mode * @param string $mode
* @return resource * @return resource
@ -36,7 +45,7 @@ class NativeStream {
} }
public function stream_close() { public function stream_close() {
return smbclient_close($this->state, $this->handle); return $this->state->close($this->handle);
} }
public function stream_eof() { public function stream_eof() {
@ -54,15 +63,15 @@ class NativeStream {
} }
public function stream_read($count) { public function stream_read($count) {
return smbclient_read($this->state, $this->handle, $count); return $this->state->read($this->handle, $count);
} }
public function stream_seek($offset, $whence = SEEK_SET) { public function stream_seek($offset, $whence = SEEK_SET) {
return smbclient_lseek($this->state, $this->handle, $offset, $whence); return $this->state->lseek($this->handle, $offset, $whence);
} }
public function stream_stat() { public function stream_stat() {
return smbclient_fstat($this->state, $this->handle); return $this->state->fstat($this->handle);
} }
public function stream_tell() { public function stream_tell() {
@ -70,6 +79,6 @@ class NativeStream {
} }
public function stream_write($data) { public function stream_write($data) {
return smbclient_write($this->state, $this->handle, $data); return $this->state->write($this->handle, $data);
} }
} }