|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Debug\Tests\Support\Stub; |
|
6
|
|
|
|
|
7
|
|
|
use Yiisoft\Yii\Debug\Helper\StreamWrapper\StreamWrapper; |
|
8
|
|
|
use Yiisoft\Yii\Debug\Helper\StreamWrapper\StreamWrapperInterface; |
|
9
|
|
|
|
|
10
|
|
|
final class PhpStreamProxy implements StreamWrapperInterface |
|
11
|
|
|
{ |
|
12
|
|
|
public static bool $registered = false; |
|
13
|
|
|
/** |
|
14
|
|
|
* @var resource|null |
|
15
|
|
|
*/ |
|
16
|
|
|
public $context; |
|
17
|
|
|
public StreamWrapperInterface $decorated; |
|
18
|
|
|
public bool $ignored = false; |
|
19
|
|
|
|
|
20
|
|
|
public array $operations = []; |
|
21
|
|
|
|
|
22
|
|
|
public function __construct() |
|
23
|
|
|
{ |
|
24
|
|
|
$this->decorated = new StreamWrapper(); |
|
25
|
|
|
$this->decorated->context = $this->context; |
|
|
|
|
|
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function __destruct() |
|
29
|
|
|
{ |
|
30
|
|
|
self::unregister(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function __call(string $name, array $arguments) |
|
34
|
|
|
{ |
|
35
|
|
|
try { |
|
36
|
|
|
self::unregister(); |
|
37
|
|
|
return $this->decorated->{$name}(...$arguments); |
|
38
|
|
|
} finally { |
|
39
|
|
|
self::register(); |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function __get(string $name) |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->decorated->{$name}; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public static function register(): void |
|
49
|
|
|
{ |
|
50
|
|
|
if (self::$registered) { |
|
51
|
|
|
return; |
|
52
|
|
|
} |
|
53
|
|
|
/** |
|
54
|
|
|
* It's important to trigger autoloader before unregistering the file stream handler |
|
55
|
|
|
*/ |
|
56
|
|
|
class_exists(StreamWrapper::class); |
|
57
|
|
|
stream_wrapper_unregister('php'); |
|
58
|
|
|
stream_wrapper_register('php', self::class, STREAM_IS_URL); |
|
59
|
|
|
|
|
60
|
|
|
self::$registered = true; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public static function unregister(): void |
|
64
|
|
|
{ |
|
65
|
|
|
if (!self::$registered) { |
|
66
|
|
|
return; |
|
67
|
|
|
} |
|
68
|
|
|
@stream_wrapper_restore('php'); |
|
|
|
|
|
|
69
|
|
|
self::$registered = false; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function stream_open(string $path, string $mode, int $options, ?string &$opened_path): bool |
|
|
|
|
|
|
73
|
|
|
{ |
|
74
|
|
|
return $this->__call(__FUNCTION__, func_get_args()); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function stream_read(int $count): string|false |
|
|
|
|
|
|
78
|
|
|
{ |
|
79
|
|
|
return $this->__call(__FUNCTION__, func_get_args()); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function stream_set_option(int $option, int $arg1, ?int $arg2): bool |
|
|
|
|
|
|
83
|
|
|
{ |
|
84
|
|
|
return $this->__call(__FUNCTION__, func_get_args()); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function stream_tell(): int |
|
|
|
|
|
|
88
|
|
|
{ |
|
89
|
|
|
return $this->__call(__FUNCTION__, func_get_args()); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function stream_eof(): bool |
|
|
|
|
|
|
93
|
|
|
{ |
|
94
|
|
|
return $this->__call(__FUNCTION__, func_get_args()); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function stream_seek(int $offset, int $whence = SEEK_SET): bool |
|
|
|
|
|
|
98
|
|
|
{ |
|
99
|
|
|
return $this->__call(__FUNCTION__, func_get_args()); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function stream_cast(int $castAs) |
|
|
|
|
|
|
103
|
|
|
{ |
|
104
|
|
|
return $this->__call(__FUNCTION__, func_get_args()); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function stream_stat(): array|false |
|
|
|
|
|
|
108
|
|
|
{ |
|
109
|
|
|
return $this->__call(__FUNCTION__, func_get_args()); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
public function dir_closedir(): bool |
|
|
|
|
|
|
113
|
|
|
{ |
|
114
|
|
|
return $this->__call(__FUNCTION__, func_get_args()); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
public function dir_opendir(string $path, int $options): bool |
|
|
|
|
|
|
118
|
|
|
{ |
|
119
|
|
|
return $this->__call(__FUNCTION__, func_get_args()); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
public function dir_readdir(): false|string |
|
|
|
|
|
|
123
|
|
|
{ |
|
124
|
|
|
return $this->__call(__FUNCTION__, func_get_args()); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
public function dir_rewinddir(): bool |
|
|
|
|
|
|
128
|
|
|
{ |
|
129
|
|
|
return $this->__call(__FUNCTION__, func_get_args()); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
public function mkdir(string $path, int $mode, int $options): bool |
|
133
|
|
|
{ |
|
134
|
|
|
return $this->__call(__FUNCTION__, func_get_args()); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
public function rename(string $path_from, string $path_to): bool |
|
138
|
|
|
{ |
|
139
|
|
|
return $this->__call(__FUNCTION__, func_get_args()); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
public function rmdir(string $path, int $options): bool |
|
143
|
|
|
{ |
|
144
|
|
|
return $this->__call(__FUNCTION__, func_get_args()); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
public function stream_close(): void |
|
|
|
|
|
|
148
|
|
|
{ |
|
149
|
|
|
$this->__call(__FUNCTION__, func_get_args()); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
public function stream_flush(): bool |
|
|
|
|
|
|
153
|
|
|
{ |
|
154
|
|
|
return $this->__call(__FUNCTION__, func_get_args()); |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
public function stream_lock(int $operation): bool |
|
|
|
|
|
|
158
|
|
|
{ |
|
159
|
|
|
return $this->__call(__FUNCTION__, func_get_args()); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
public function stream_metadata(string $path, int $option, mixed $value): bool |
|
|
|
|
|
|
163
|
|
|
{ |
|
164
|
|
|
return $this->__call(__FUNCTION__, func_get_args()); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
public function stream_truncate(int $new_size): bool |
|
|
|
|
|
|
168
|
|
|
{ |
|
169
|
|
|
return $this->__call(__FUNCTION__, func_get_args()); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
public function stream_write(string $data): int |
|
|
|
|
|
|
173
|
|
|
{ |
|
174
|
|
|
return $this->__call(__FUNCTION__, func_get_args()); |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
public function unlink(string $path): bool |
|
178
|
|
|
{ |
|
179
|
|
|
return $this->__call(__FUNCTION__, func_get_args()); |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
public function url_stat(string $path, int $flags): array|false |
|
|
|
|
|
|
183
|
|
|
{ |
|
184
|
|
|
return $this->__call(__FUNCTION__, func_get_args()); |
|
185
|
|
|
} |
|
186
|
|
|
} |
|
187
|
|
|
|