mirror of
https://codeberg.org/icewind/streams.git
synced 2026-06-04 00:54:08 +02:00
Add directory support to wrappers
This commit is contained in:
parent
448dfc577c
commit
53cfe7f4f1
5 changed files with 121 additions and 28 deletions
|
|
@ -12,7 +12,7 @@ namespace Icewind\Streams;
|
|||
*
|
||||
* This wrapper itself doesn't implement any functionality but is just a base class for other wrappers to extend
|
||||
*/
|
||||
abstract class Wrapper implements File {
|
||||
abstract class Wrapper implements File, Directory {
|
||||
/**
|
||||
* @var resource
|
||||
*/
|
||||
|
|
@ -25,6 +25,22 @@ abstract class Wrapper implements File {
|
|||
*/
|
||||
protected $source;
|
||||
|
||||
protected static function wrapSource($source, $context, $protocol, $class) {
|
||||
try {
|
||||
stream_wrapper_register($protocol, $class);
|
||||
if (@rewinddir($source) === false) {
|
||||
$wrapped = fopen($protocol . '://', 'r+', false, $context);
|
||||
} else {
|
||||
$wrapped = opendir($protocol . '://', $context);
|
||||
}
|
||||
} catch (\BadMethodCallException $e) {
|
||||
stream_wrapper_unregister($protocol);
|
||||
throw $e;
|
||||
}
|
||||
stream_wrapper_unregister($protocol);
|
||||
return $wrapped;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the source from the stream context and return the context options
|
||||
*
|
||||
|
|
@ -107,4 +123,17 @@ abstract class Wrapper implements File {
|
|||
public function stream_close() {
|
||||
return fclose($this->source);
|
||||
}
|
||||
|
||||
public function dir_readdir() {
|
||||
return readdir($this->source);
|
||||
}
|
||||
|
||||
public function dir_closedir() {
|
||||
closedir($this->source);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function dir_rewinddir() {
|
||||
return rewind($this->source);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue