-
Notifications
You must be signed in to change notification settings - Fork 16
/
TestStreamWrapper.php
171 lines (129 loc) · 2.83 KB
/
TestStreamWrapper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
/*
* This file is part of the webmozart/glob package.
*
* (c) Bernhard Schussek <bschussek@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Webmozart\Glob\Tests;
/**
* @since 1.0
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class TestStreamWrapper
{
/**
* @var string[]
*/
private static $basePaths = array();
/**
* @var resource
*/
private $handle;
public static function register($scheme, $basePath)
{
self::$basePaths[$scheme] = $basePath;
stream_wrapper_register($scheme, __CLASS__);
}
public static function unregister($scheme)
{
if (!isset(self::$basePaths[$scheme])) {
return;
}
unset(self::$basePaths[$scheme]);
stream_wrapper_unregister($scheme);
}
public function dir_opendir($uri, $options)
{
$this->handle = opendir($this->uriToPath($uri));
return true;
}
public function dir_closedir()
{
assert(null !== $this->handle);
closedir($this->handle);
return false;
}
public function dir_readdir()
{
assert(null !== $this->handle);
return readdir($this->handle);
}
public function dir_rewinddir()
{
assert(null !== $this->handle);
rewinddir($this->handle);
return true;
}
public function mkdir($uri, $mode, $options)
{
}
public function rename($uriFrom, $uriTo)
{
}
public function rmdir($uri, $options)
{
}
public function stream_cast($castAs)
{
return $this->handle;
}
public function stream_close()
{
}
public function stream_eof()
{
}
public function stream_flush()
{
}
public function stream_lock($operation)
{
}
public function stream_metadata($uri, $option, $value)
{
}
public function stream_open($uri, $mode, $options, &$openedPath)
{
}
public function stream_read($length)
{
}
public function stream_seek($offset, $whence = SEEK_SET)
{
}
public function stream_set_option($option, $arg1, $arg2)
{
}
public function stream_stat()
{
}
public function stream_tell()
{
}
public function stream_truncate($newSize)
{
}
public function stream_write($data)
{
}
public function unlink($uri)
{
}
public function url_stat($uri, $flags)
{
$path = $this->uriToPath($uri);
if ($flags & STREAM_URL_STAT_LINK) {
return lstat($path);
}
return stat($path);
}
private function uriToPath($uri)
{
$parts = explode('://', $uri);
return self::$basePaths[$parts[0]].$parts[1];
}
}