mirror of
https://codeberg.org/icewind/streams.git
synced 2026-06-04 00:54:08 +02:00
use better method to determine when a stream is a directory stream
This commit is contained in:
parent
851b822ac2
commit
0a78597117
1 changed files with 11 additions and 3 deletions
|
|
@ -26,12 +26,15 @@ abstract class Wrapper implements File, Directory {
|
|||
protected $source;
|
||||
|
||||
protected static function wrapSource($source, $context, $protocol, $class) {
|
||||
if (!is_resource($source)) {
|
||||
throw new \BadMethodCallException();
|
||||
}
|
||||
try {
|
||||
stream_wrapper_register($protocol, $class);
|
||||
if (@rewinddir($source) === false) {
|
||||
$wrapped = fopen($protocol . '://', 'r+', false, $context);
|
||||
} else {
|
||||
if (self::isDirectoryHandle($source)) {
|
||||
$wrapped = opendir($protocol . '://', $context);
|
||||
} else {
|
||||
$wrapped = fopen($protocol . '://', 'r+', false, $context);
|
||||
}
|
||||
} catch (\BadMethodCallException $e) {
|
||||
stream_wrapper_unregister($protocol);
|
||||
|
|
@ -41,6 +44,11 @@ abstract class Wrapper implements File, Directory {
|
|||
return $wrapped;
|
||||
}
|
||||
|
||||
protected static function isDirectoryHandle($resource) {
|
||||
$meta = stream_get_meta_data($resource);
|
||||
return $meta['stream_type'] == 'dir';
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the source from the stream context and return the context options
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue