aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/varstream.php
diff options
context:
space:
mode:
authorJan-Hendrik Willms <tleilax+studip@gmail.com>2024-05-16 11:05:47 +0000
committerDavid Siegfried <david.siegfried@uni-vechta.de>2024-05-16 11:05:47 +0000
commitefaeea07319c63be2f2c6a8bd076e4de8ac8f11d (patch)
treeb6c4f4f976cee1e156f8f9dd0fec39a9f09e6242 /tests/unit/varstream.php
parentbb2278c43c4992c2cc0fc2d468ad98a395e13962 (diff)
relocate flexi, fixes #4101
Closes #4101 Merge request studip/studip!2977
Diffstat (limited to 'tests/unit/varstream.php')
-rw-r--r--tests/unit/varstream.php106
1 files changed, 67 insertions, 39 deletions
diff --git a/tests/unit/varstream.php b/tests/unit/varstream.php
index 9a3acb5..d2047c0 100644
--- a/tests/unit/varstream.php
+++ b/tests/unit/varstream.php
@@ -7,15 +7,17 @@ class ArrayFileStream
private static $fs;
- static function set_filesystem(array $fs) {
+ static function set_filesystem(array $fs)
+ {
ArrayFileStream::$fs = $fs;
}
- private static function &get_element($path) {
+ private static function &get_element($path)
+ {
$result =& ArrayFileStream::$fs;
foreach (preg_split('/\//', $path, -1, PREG_SPLIT_NO_EMPTY) as $element) {
if (!isset($result[$element])) {
- $null = NULL;
+ $null = null;
return $null;
}
$result =& $result[$element];
@@ -23,9 +25,10 @@ class ArrayFileStream
return $result;
}
- private static function &get_file($path) {
+ private static function &get_file($path)
+ {
$url = parse_url($path);
- $file =& self::get_element($url['host'] . $url['path']);
+ $file =& self::get_element($url['host'] . ($url['path'] ?? ''));
if (is_null($file)) {
throw new Exception("file not found.");
@@ -33,15 +36,18 @@ class ArrayFileStream
return $file;
}
- public function stream_close() {
+ public function stream_close()
+ {
# nothing to do
}
- public function stream_flush() {
+ public function stream_flush()
+ {
# nothing to do
}
- public function stream_open($path, $mode, $options, $opened_path) {
+ public function stream_open($path, $mode, $options, $opened_path)
+ {
try {
$this->open_file =& self::get_file($path);
$this->position = 0;
@@ -51,37 +57,41 @@ class ArrayFileStream
}
}
- public function stream_read($count) {
+ public function stream_read($count)
+ {
$ret = mb_substr($this->open_file, $this->position, $count);
$this->position += mb_strlen($ret);
return $ret;
}
- public function stream_write($data) {
- $left = mb_substr($this->open_file, 0, $this->position);
+ public function stream_write($data)
+ {
+ $left = mb_substr($this->open_file, 0, $this->position);
$right = mb_substr($this->open_file, $this->position + mb_strlen($data));
$this->open_file = $left . $data . $right;
$this->position += mb_strlen($data);
return mb_strlen($data);
}
- public function stream_tell() {
+ public function stream_tell()
+ {
return $this->position;
}
- public function stream_eof() {
+ public function stream_eof()
+ {
return $this->position >= mb_strlen($this->open_file);
}
- public function stream_seek($offset, $whence) {
+ public function stream_seek($offset, $whence)
+ {
switch ($whence) {
case SEEK_SET:
if ($offset < mb_strlen($this->open_file) && $offset >= 0) {
$this->position = $offset;
return true;
- }
- else {
+ } else {
return false;
}
break;
@@ -90,8 +100,7 @@ class ArrayFileStream
if ($offset >= 0) {
$this->position += $offset;
return true;
- }
- else {
+ } else {
return false;
}
break;
@@ -100,8 +109,7 @@ class ArrayFileStream
if (mb_strlen($this->open_file) + $offset >= 0) {
$this->position = mb_strlen($this->open_file) + $offset;
return true;
- }
- else {
+ } else {
return false;
}
break;
@@ -115,44 +123,61 @@ class ArrayFileStream
{
}
- public function stream_stat() {
- return array('size' => is_array($this->open_file)
- ? sizeof($this->open_file)
- : mb_strlen($this->open_file));
+ public function stream_stat()
+ {
+ return [
+ 'size' => is_array($this->open_file)
+ ? sizeof($this->open_file)
+ : mb_strlen($this->open_file),
+ ];
}
- public function unlink($path) {
+ public function unlink($path)
+ {
$parent =& self::get_file(dirname($path));
if (is_array($parent) && isset($parent[basename($path)])) {
unset($parent[basename($path)]);
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
}
- public function rename($path_from, $path_to) {
+ public function rename($path_from, $path_to)
+ {
throw new Exception('not implemented yet');
}
- public function mkdir($path, $mode, $options) {
+ public function mkdir($path, $mode, $options)
+ {
throw new Exception('not implemented yet');
}
- public function rmdir($path, $options) {
+ public function rmdir($path, $options)
+ {
throw new Exception('not implemented yet');
}
- public function dir_opendir($path, $options) {
+ public function dir_opendir($path, $options)
+ {
throw new Exception('not implemented yet');
}
- public function url_stat($path, $flags) {
+ public function url_stat($path, $flags)
+ {
+ try {
+ if (!self::get_file($path)) {
+ return false;
+ }
+ } catch (Exception $e) {
+ return false;
+ }
+
$time = time();
- $keys = array(
+ $keys = [
'dev' => 0,
'ino' => 0,
'mode' => 33216, // chmod 700
@@ -161,25 +186,28 @@ class ArrayFileStream
'gid' => function_exists('posix_getgid') ? posix_getgid() : 0,
'rdev' => 0,
'size' => $flags & STREAM_URL_STAT_QUIET
- ? @mb_strlen($this->open_file) : mb_strlen($this->open_file),
+ ? @mb_strlen($this->open_file) : mb_strlen($this->open_file),
'atime' => $time,
'mtime' => $time,
'ctime' => $time,
'blksize' => 0,
- 'blocks' => 0
- );
+ 'blocks' => 0,
+ ];
return array_merge(array_values($keys), $keys);
}
- public function dir_readdir() {
+ public function dir_readdir()
+ {
throw new Exception('not implemented yet');
}
- public function dir_rewinddir() {
+ public function dir_rewinddir()
+ {
throw new Exception('not implemented yet');
}
- public function dir_closedir() {
+ public function dir_closedir()
+ {
throw new Exception('not implemented yet');
}
}