some extra type checks

This commit is contained in:
Robin Appelman 2019-03-11 17:16:21 +01:00
commit 782e09ec62
8 changed files with 24 additions and 13 deletions

View file

@ -58,7 +58,7 @@ class CallbackWrapper extends Wrapper {
* @param callable|null $close (optional) * @param callable|null $close (optional)
* @param callable|null $readDir (optional) * @param callable|null $readDir (optional)
* @param callable|null $preClose (optional) * @param callable|null $preClose (optional)
* @return resource * @return resource|bool
* *
*/ */
public static function wrap($source, $read = null, $write = null, $close = null, $readDir = null, $preClose = null) { public static function wrap($source, $read = null, $write = null, $close = null, $readDir = null, $preClose = null) {

View file

@ -55,7 +55,7 @@ class CountWrapper extends Wrapper {
* *
* @param resource $source * @param resource $source
* @param callable $callback * @param callable $callback
* @return resource * @return resource|bool
* *
* @throws \BadMethodCallException * @throws \BadMethodCallException
*/ */

View file

@ -19,7 +19,7 @@ interface Directory {
public function dir_opendir($path, $options); public function dir_opendir($path, $options);
/** /**
* @return string * @return string|bool
*/ */
public function dir_readdir(); public function dir_readdir();

View file

@ -46,7 +46,7 @@ class DirectoryFilter extends DirectoryWrapper {
/** /**
* @param resource $source * @param resource $source
* @param callable $filter * @param callable $filter
* @return resource * @return resource|bool
*/ */
public static function wrap($source, callable $filter) { public static function wrap($source, callable $filter) {
return self::wrapSource($source, [ return self::wrapSource($source, [

View file

@ -61,7 +61,7 @@ class IteratorDirectory extends WrapperHandler implements Directory {
} }
/** /**
* @return string * @return string|bool
*/ */
public function dir_readdir() { public function dir_readdir() {
if ($this->iterator->valid()) { if ($this->iterator->valid()) {
@ -92,7 +92,7 @@ class IteratorDirectory extends WrapperHandler implements Directory {
* Creates a directory handle from the provided array or iterator * Creates a directory handle from the provided array or iterator
* *
* @param \Iterator | array $source * @param \Iterator | array $source
* @return resource * @return resource|bool
* *
* @throws \BadMethodCallException * @throws \BadMethodCallException
*/ */

View file

@ -35,7 +35,11 @@ class SeekableWrapper extends Wrapper {
public function stream_open($path, $mode, $options, &$opened_path) { public function stream_open($path, $mode, $options, &$opened_path) {
$this->loadContext(); $this->loadContext();
$this->cache = fopen('php://temp', 'w+'); $cache = fopen('php://temp', 'w+');
if ($cache === false) {
return false;
}
$this->cache = $cache;
return true; return true;
} }

View file

@ -47,7 +47,6 @@ class UrlCallback extends Wrapper implements Url {
* @return \Icewind\Streams\Path * @return \Icewind\Streams\Path
* *
* @throws \BadMethodCallException * @throws \BadMethodCallException
* @throws \Exception
*/ */
public static function wrap($source, $fopen = null, $opendir = null, $mkdir = null, $rename = null, $rmdir = null, public static function wrap($source, $fopen = null, $opendir = null, $mkdir = null, $rename = null, $rmdir = null,
$unlink = null, $stat = null) { $unlink = null, $stat = null) {
@ -78,21 +77,29 @@ class UrlCallback extends Wrapper implements Url {
public function stream_open($path, $mode, $options, &$opened_path) { public function stream_open($path, $mode, $options, &$opened_path) {
$context = $this->loadUrlContext($path); $context = $this->loadUrlContext($path);
$this->callCallBack($context, 'fopen'); $this->callCallBack($context, 'fopen');
$this->setSourceStream(fopen($context['source'], $mode)); $source = fopen($context['source'], $mode);
if ($source === false) {
return false;
}
$this->setSourceStream($source);
return true; return true;
} }
public function dir_opendir($path, $options) { public function dir_opendir($path, $options) {
$context = $this->loadUrlContext($path); $context = $this->loadUrlContext($path);
$this->callCallBack($context, 'opendir'); $this->callCallBack($context, 'opendir');
$this->setSourceStream(opendir($context['source'])); $source = opendir($context['source']);
if ($source === false) {
return false;
}
$this->setSourceStream($source);
return true; return true;
} }
public function mkdir($path, $mode, $options) { public function mkdir($path, $mode, $options) {
$context = $this->loadUrlContext($path); $context = $this->loadUrlContext($path);
$this->callCallBack($context, 'mkdir'); $this->callCallBack($context, 'mkdir');
return mkdir($context['source'], $mode, $options & STREAM_MKDIR_RECURSIVE); return mkdir($context['source'], $mode, ($options & STREAM_MKDIR_RECURSIVE) > 0);
} }
public function rmdir($path, $options) { public function rmdir($path, $options) {

View file

@ -42,8 +42,8 @@ class WrapperHandler {
/** /**
* @param resource|int $source * @param resource|int $source
* @param resource|array $context * @param resource|array $context
* @param null $protocol deprecated, protocol is now automatically generated * @param string|null $protocol deprecated, protocol is now automatically generated
* @param null $class deprecated, class is now automatically generated * @param string|null $class deprecated, class is now automatically generated
* @return bool|resource * @return bool|resource
*/ */
protected static function wrapSource($source, $context = [], $protocol = null, $class = null) { protected static function wrapSource($source, $context = [], $protocol = null, $class = null) {