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; |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
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'); |
||||
0 ignored issues
–
show
It seems like you do not handle an error condition for
stream_wrapper_restore() . This can introduce security issues, and is generally not recommended.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||||
69 | self::$registered = false; |
||||
70 | } |
||||
71 | |||||
72 | public function stream_open(string $path, string $mode, int $options, ?string &$opened_path): bool |
||||
0 ignored issues
–
show
|
|||||
73 | { |
||||
74 | return $this->__call(__FUNCTION__, func_get_args()); |
||||
75 | } |
||||
76 | |||||
77 | public function stream_read(int $count): string|false |
||||
0 ignored issues
–
show
|
|||||
78 | { |
||||
79 | return $this->__call(__FUNCTION__, func_get_args()); |
||||
80 | } |
||||
81 | |||||
82 | public function stream_set_option(int $option, int $arg1, ?int $arg2): bool |
||||
0 ignored issues
–
show
|
|||||
83 | { |
||||
84 | return $this->__call(__FUNCTION__, func_get_args()); |
||||
85 | } |
||||
86 | |||||
87 | public function stream_tell(): int |
||||
0 ignored issues
–
show
|
|||||
88 | { |
||||
89 | return $this->__call(__FUNCTION__, func_get_args()); |
||||
90 | } |
||||
91 | |||||
92 | public function stream_eof(): bool |
||||
0 ignored issues
–
show
|
|||||
93 | { |
||||
94 | return $this->__call(__FUNCTION__, func_get_args()); |
||||
95 | } |
||||
96 | |||||
97 | public function stream_seek(int $offset, int $whence = SEEK_SET): bool |
||||
0 ignored issues
–
show
|
|||||
98 | { |
||||
99 | return $this->__call(__FUNCTION__, func_get_args()); |
||||
100 | } |
||||
101 | |||||
102 | public function stream_cast(int $castAs) |
||||
0 ignored issues
–
show
|
|||||
103 | { |
||||
104 | return $this->__call(__FUNCTION__, func_get_args()); |
||||
105 | } |
||||
106 | |||||
107 | public function stream_stat(): array|false |
||||
0 ignored issues
–
show
|
|||||
108 | { |
||||
109 | return $this->__call(__FUNCTION__, func_get_args()); |
||||
110 | } |
||||
111 | |||||
112 | public function dir_closedir(): bool |
||||
0 ignored issues
–
show
|
|||||
113 | { |
||||
114 | return $this->__call(__FUNCTION__, func_get_args()); |
||||
115 | } |
||||
116 | |||||
117 | public function dir_opendir(string $path, int $options): bool |
||||
0 ignored issues
–
show
|
|||||
118 | { |
||||
119 | return $this->__call(__FUNCTION__, func_get_args()); |
||||
120 | } |
||||
121 | |||||
122 | public function dir_readdir(): false|string |
||||
0 ignored issues
–
show
|
|||||
123 | { |
||||
124 | return $this->__call(__FUNCTION__, func_get_args()); |
||||
125 | } |
||||
126 | |||||
127 | public function dir_rewinddir(): bool |
||||
0 ignored issues
–
show
|
|||||
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 |
||||
0 ignored issues
–
show
|
|||||
148 | { |
||||
149 | $this->__call(__FUNCTION__, func_get_args()); |
||||
150 | } |
||||
151 | |||||
152 | public function stream_flush(): bool |
||||
0 ignored issues
–
show
|
|||||
153 | { |
||||
154 | return $this->__call(__FUNCTION__, func_get_args()); |
||||
155 | } |
||||
156 | |||||
157 | public function stream_lock(int $operation): bool |
||||
0 ignored issues
–
show
|
|||||
158 | { |
||||
159 | return $this->__call(__FUNCTION__, func_get_args()); |
||||
160 | } |
||||
161 | |||||
162 | public function stream_metadata(string $path, int $option, mixed $value): bool |
||||
0 ignored issues
–
show
|
|||||
163 | { |
||||
164 | return $this->__call(__FUNCTION__, func_get_args()); |
||||
165 | } |
||||
166 | |||||
167 | public function stream_truncate(int $new_size): bool |
||||
0 ignored issues
–
show
|
|||||
168 | { |
||||
169 | return $this->__call(__FUNCTION__, func_get_args()); |
||||
170 | } |
||||
171 | |||||
172 | public function stream_write(string $data): int |
||||
0 ignored issues
–
show
|
|||||
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 |
||||
0 ignored issues
–
show
|
|||||
183 | { |
||||
184 | return $this->__call(__FUNCTION__, func_get_args()); |
||||
185 | } |
||||
186 | } |
||||
187 |