PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.1.0
Defender Security – Malware Scanner, Login Security & Firewall v6.1.0
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / vendor / thecodingmachine / safe / generated / stream.php

stream.php in Defender Security – Malware Scanner, Login Security & Firewall 6.1.0, at vendor/thecodingmachine/safe/generated/stream.php

615 lines 19.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Safe;
4
5 use Safe\Exceptions\StreamException;
6
7 /**
8 * Sets parameters on the specified context.
9 *
10 * @param resource $stream_or_context The stream or context to apply the parameters too.
11 * @param array $params An array of parameters to set.
12 *
13 * params should be an associative array of the structure:
14 * $params['paramname'] = "paramvalue";.
15 * @throws StreamException
16 *
17 */
18 function stream_context_set_params($stream_or_context, array $params): void
19 {
20 error_clear_last();
21 $result = \stream_context_set_params($stream_or_context, $params);
22 if ($result === false) {
23 throw StreamException::createFromPhpError();
24 }
25 }
26
27
28 /**
29 * Makes a copy of up to maxlength bytes
30 * of data from the current position (or from the
31 * offset position, if specified) in
32 * source to dest. If
33 * maxlength is not specified, all remaining content in
34 * source will be copied.
35 *
36 * @param resource $source The source stream
37 * @param resource $dest The destination stream
38 * @param int $maxlength Maximum bytes to copy
39 * @param int $offset The offset where to start to copy data
40 * @return int Returns the total count of bytes copied.
41 * @throws StreamException
42 *
43 */
44 function stream_copy_to_stream($source, $dest, int $maxlength = -1, int $offset = 0): int
45 {
46 error_clear_last();
47 $result = \stream_copy_to_stream($source, $dest, $maxlength, $offset);
48 if ($result === false) {
49 throw StreamException::createFromPhpError();
50 }
51 return $result;
52 }
53
54
55 /**
56 * Adds filtername to the list of filters
57 * attached to stream.
58 *
59 * @param resource $stream The target stream.
60 * @param string $filtername The filter name.
61 * @param int|null $read_write By default, stream_filter_append will
62 * attach the filter to the read filter chain
63 * if the file was opened for reading (i.e. File Mode:
64 * r, and/or +). The filter
65 * will also be attached to the write filter chain
66 * if the file was opened for writing (i.e. File Mode:
67 * w, a, and/or +).
68 * STREAM_FILTER_READ,
69 * STREAM_FILTER_WRITE, and/or
70 * STREAM_FILTER_ALL can also be passed to the
71 * read_write parameter to override this behavior.
72 * @param mixed $params This filter will be added with the specified
73 * params to the end of
74 * the list and will therefore be called last during stream operations.
75 * To add a filter to the beginning of the list, use
76 * stream_filter_prepend.
77 *
78 * @return resource Returns a resource on success. The resource can be
79 * used to refer to this filter instance during a call to
80 * stream_filter_remove.
81 *
82 * FALSE is returned if stream is not a resource or
83 * if filtername cannot be located.
84 * @throws StreamException
85 *
86 */
87 function stream_filter_append($stream, string $filtername, ?int $read_write = null, $params = null)
88 {
89 error_clear_last();
90 if ($params !== null) {
91 $result = \stream_filter_append($stream, $filtername, $read_write, $params);
92 } elseif ($read_write !== null) {
93 $result = \stream_filter_append($stream, $filtername, $read_write);
94 } else {
95 $result = \stream_filter_append($stream, $filtername);
96 }
97 if ($result === false) {
98 throw StreamException::createFromPhpError();
99 }
100 return $result;
101 }
102
103
104 /**
105 * Adds filtername to the list of filters
106 * attached to stream.
107 *
108 * @param resource $stream The target stream.
109 * @param string $filtername The filter name.
110 * @param int|null $read_write By default, stream_filter_prepend will
111 * attach the filter to the read filter chain
112 * if the file was opened for reading (i.e. File Mode:
113 * r, and/or +). The filter
114 * will also be attached to the write filter chain
115 * if the file was opened for writing (i.e. File Mode:
116 * w, a, and/or +).
117 * STREAM_FILTER_READ,
118 * STREAM_FILTER_WRITE, and/or
119 * STREAM_FILTER_ALL can also be passed to the
120 * read_write parameter to override this behavior.
121 * See stream_filter_append for an example of
122 * using this parameter.
123 * @param mixed $params This filter will be added with the specified params
124 * to the beginning of the list and will therefore be
125 * called first during stream operations. To add a filter to the end of the
126 * list, use stream_filter_append.
127 *
128 * @return resource Returns a resource on success. The resource can be
129 * used to refer to this filter instance during a call to
130 * stream_filter_remove.
131 *
132 * FALSE is returned if stream is not a resource or
133 * if filtername cannot be located.
134 * @throws StreamException
135 *
136 */
137 function stream_filter_prepend($stream, string $filtername, ?int $read_write = null, $params = null)
138 {
139 error_clear_last();
140 if ($params !== null) {
141 $result = \stream_filter_prepend($stream, $filtername, $read_write, $params);
142 } elseif ($read_write !== null) {
143 $result = \stream_filter_prepend($stream, $filtername, $read_write);
144 } else {
145 $result = \stream_filter_prepend($stream, $filtername);
146 }
147 if ($result === false) {
148 throw StreamException::createFromPhpError();
149 }
150 return $result;
151 }
152
153
154 /**
155 * stream_filter_register allows you to implement
156 * your own filter on any registered stream used with all the other
157 * filesystem functions (such as fopen,
158 * fread etc.).
159 *
160 * @param string $filtername The filter name to be registered.
161 * @param string $classname To implement a filter, you need to define a class as an extension of
162 * php_user_filter with a number of member
163 * functions. When performing read/write operations on the stream
164 * to which your filter is attached, PHP will pass the data through your
165 * filter (and any other filters attached to that stream) so that the
166 * data may be modified as desired. You must implement the methods
167 * exactly as described in php_user_filter - doing
168 * otherwise will lead to undefined behaviour.
169 * @throws StreamException
170 *
171 */
172 function stream_filter_register(string $filtername, string $classname): void
173 {
174 error_clear_last();
175 $result = \stream_filter_register($filtername, $classname);
176 if ($result === false) {
177 throw StreamException::createFromPhpError();
178 }
179 }
180
181
182 /**
183 * Removes a stream filter previously added to a stream with
184 * stream_filter_prepend or
185 * stream_filter_append. Any data remaining in the
186 * filter's internal buffer will be flushed through to the next filter before
187 * removing it.
188 *
189 * @param resource $stream_filter The stream filter to be removed.
190 * @throws StreamException
191 *
192 */
193 function stream_filter_remove($stream_filter): void
194 {
195 error_clear_last();
196 $result = \stream_filter_remove($stream_filter);
197 if ($result === false) {
198 throw StreamException::createFromPhpError();
199 }
200 }
201
202
203 /**
204 * Identical to file_get_contents, except that
205 * stream_get_contents operates on an already open
206 * stream resource and returns the remaining contents in a string, up to
207 * maxlength bytes and starting at the specified
208 * offset.
209 *
210 * @param resource $handle A stream resource (e.g. returned from fopen)
211 * @param int $maxlength The maximum bytes to read. Defaults to -1 (read all the remaining
212 * buffer).
213 * @param int $offset Seek to the specified offset before reading. If this number is negative,
214 * no seeking will occur and reading will start from the current position.
215 * @return string Returns a string.
216 * @throws StreamException
217 *
218 */
219 function stream_get_contents($handle, int $maxlength = -1, int $offset = -1): string
220 {
221 error_clear_last();
222 $result = \stream_get_contents($handle, $maxlength, $offset);
223 if ($result === false) {
224 throw StreamException::createFromPhpError();
225 }
226 return $result;
227 }
228
229
230 /**
231 * Determines if stream stream refers to a valid terminal type device.
232 * This is a more portable version of posix_isatty, since it works on Windows systems too.
233 *
234 * @param resource $stream
235 * @throws StreamException
236 *
237 */
238 function stream_isatty($stream): void
239 {
240 error_clear_last();
241 $result = \stream_isatty($stream);
242 if ($result === false) {
243 throw StreamException::createFromPhpError();
244 }
245 }
246
247
248 /**
249 * Resolve filename against the include path according to the same rules as fopen/include.
250 *
251 * @param string $filename The filename to resolve.
252 * @return string Returns a string containing the resolved absolute filename.
253 * @throws StreamException
254 *
255 */
256 function stream_resolve_include_path(string $filename): string
257 {
258 error_clear_last();
259 $result = \stream_resolve_include_path($filename);
260 if ($result === false) {
261 throw StreamException::createFromPhpError();
262 }
263 return $result;
264 }
265
266
267 /**
268 * Sets blocking or non-blocking mode on a stream.
269 *
270 * This function works for any stream that supports non-blocking mode
271 * (currently, regular files and socket streams).
272 *
273 * @param resource $stream The stream.
274 * @param bool $mode If mode is FALSE, the given stream
275 * will be switched to non-blocking mode, and if TRUE, it
276 * will be switched to blocking mode. This affects calls like
277 * fgets and fread
278 * that read from the stream. In non-blocking mode an
279 * fgets call will always return right away
280 * while in blocking mode it will wait for data to become available
281 * on the stream.
282 * @throws StreamException
283 *
284 */
285 function stream_set_blocking($stream, bool $mode): void
286 {
287 error_clear_last();
288 $result = \stream_set_blocking($stream, $mode);
289 if ($result === false) {
290 throw StreamException::createFromPhpError();
291 }
292 }
293
294
295 /**
296 * Sets the timeout value on stream,
297 * expressed in the sum of seconds and
298 * microseconds.
299 *
300 * When the stream times out, the 'timed_out' key of the array returned by
301 * stream_get_meta_data is set to TRUE, although no
302 * error/warning is generated.
303 *
304 * @param resource $stream The target stream.
305 * @param int $seconds The seconds part of the timeout to be set.
306 * @param int $microseconds The microseconds part of the timeout to be set.
307 * @throws StreamException
308 *
309 */
310 function stream_set_timeout($stream, int $seconds, int $microseconds = 0): void
311 {
312 error_clear_last();
313 $result = \stream_set_timeout($stream, $seconds, $microseconds);
314 if ($result === false) {
315 throw StreamException::createFromPhpError();
316 }
317 }
318
319
320 /**
321 * Accept a connection on a socket previously created by
322 * stream_socket_server.
323 *
324 * @param resource $server_socket The server socket to accept a connection from.
325 * @param float|null $timeout Override the default socket accept timeout. Time should be given in
326 * seconds.
327 * @param string|null $peername Will be set to the name (address) of the client which connected, if
328 * included and available from the selected transport.
329 *
330 * Can also be determined later using
331 * stream_socket_get_name.
332 *
333 * @return resource Returns a stream to the accepted socket connection.
334 * @throws StreamException
335 *
336 */
337 function stream_socket_accept($server_socket, ?float $timeout = null, ?string &$peername = null)
338 {
339 error_clear_last();
340 if ($peername !== null) {
341 $result = \stream_socket_accept($server_socket, $timeout, $peername);
342 } elseif ($timeout !== null) {
343 $result = \stream_socket_accept($server_socket, $timeout);
344 } else {
345 $result = \stream_socket_accept($server_socket);
346 }
347 if ($result === false) {
348 throw StreamException::createFromPhpError();
349 }
350 return $result;
351 }
352
353
354 /**
355 * Initiates a stream or datagram connection to the destination specified
356 * by remote_socket. The type of socket created
357 * is determined by the transport specified using standard URL formatting:
358 * transport://target. For Internet Domain sockets
359 * (AF_INET) such as TCP and UDP, the target portion
360 * of the remote_socket parameter should consist of
361 * a hostname or IP address followed by a colon and a port number. For Unix
362 * domain sockets, the target portion should point
363 * to the socket file on the filesystem.
364 *
365 * @param string $remote_socket Address to the socket to connect to.
366 * @param int|null $errno Will be set to the system level error number if connection fails.
367 * @param string|null $errstr Will be set to the system level error message if the connection fails.
368 * @param float|null $timeout Number of seconds until the connect() system call
369 * should timeout.
370 *
371 *
372 * This parameter only applies when not making asynchronous
373 * connection attempts.
374 *
375 *
376 *
377 *
378 * To set a timeout for reading/writing data over the socket, use the
379 * stream_set_timeout, as the
380 * timeout only applies while making connecting
381 * the socket.
382 *
383 *
384 *
385 * To set a timeout for reading/writing data over the socket, use the
386 * stream_set_timeout, as the
387 * timeout only applies while making connecting
388 * the socket.
389 * @param int $flags Bitmask field which may be set to any combination of connection flags.
390 * Currently the select of connection flags is limited to
391 * STREAM_CLIENT_CONNECT (default),
392 * STREAM_CLIENT_ASYNC_CONNECT and
393 * STREAM_CLIENT_PERSISTENT.
394 * @param resource $context A valid context resource created with stream_context_create.
395 *
396 * @return resource On success a stream resource is returned which may
397 * be used together with the other file functions (such as
398 * fgets, fgetss,
399 * fwrite, fclose, and
400 * feof), FALSE on failure.
401 * @throws StreamException
402 *
403 */
404 function stream_socket_client(string $remote_socket, ?int &$errno = null, ?string &$errstr = null, ?float $timeout = null, int $flags = STREAM_CLIENT_CONNECT, $context = null)
405 {
406 error_clear_last();
407 if ($context !== null) {
408 $result = \stream_socket_client($remote_socket, $errno, $errstr, $timeout, $flags, $context);
409 } elseif ($flags !== STREAM_CLIENT_CONNECT) {
410 $result = \stream_socket_client($remote_socket, $errno, $errstr, $timeout, $flags);
411 } elseif ($timeout !== null) {
412 $result = \stream_socket_client($remote_socket, $errno, $errstr, $timeout);
413 } else {
414 $result = \stream_socket_client($remote_socket, $errno, $errstr);
415 }
416 if ($result === false) {
417 throw StreamException::createFromPhpError();
418 }
419 return $result;
420 }
421
422
423 /**
424 * stream_socket_pair creates a pair of connected,
425 * indistinguishable socket streams. This function is commonly used in IPC
426 * (Inter-Process Communication).
427 *
428 * @param int $domain The protocol family to be used: STREAM_PF_INET,
429 * STREAM_PF_INET6 or
430 * STREAM_PF_UNIX
431 * @param int $type The type of communication to be used:
432 * STREAM_SOCK_DGRAM,
433 * STREAM_SOCK_RAW,
434 * STREAM_SOCK_RDM,
435 * STREAM_SOCK_SEQPACKET or
436 * STREAM_SOCK_STREAM
437 * @param int $protocol The protocol to be used: STREAM_IPPROTO_ICMP,
438 * STREAM_IPPROTO_IP,
439 * STREAM_IPPROTO_RAW,
440 * STREAM_IPPROTO_TCP or
441 * STREAM_IPPROTO_UDP
442 * @return resource[] Returns an array with the two socket resources on success.
443 * @throws StreamException
444 *
445 */
446 function stream_socket_pair(int $domain, int $type, int $protocol): iterable
447 {
448 error_clear_last();
449 $result = \stream_socket_pair($domain, $type, $protocol);
450 if ($result === false) {
451 throw StreamException::createFromPhpError();
452 }
453 return $result;
454 }
455
456
457 /**
458 * Creates a stream or datagram socket on the specified
459 * local_socket.
460 *
461 * This function only creates a socket, to begin accepting connections
462 * use stream_socket_accept.
463 *
464 * @param string $local_socket The type of socket created is determined by the transport specified
465 * using standard URL formatting: transport://target.
466 *
467 * For Internet Domain sockets (AF_INET) such as TCP and UDP, the
468 * target portion of the
469 * remote_socket parameter should consist of a
470 * hostname or IP address followed by a colon and a port number. For
471 * Unix domain sockets, the target portion should
472 * point to the socket file on the filesystem.
473 *
474 * Depending on the environment, Unix domain sockets may not be available.
475 * A list of available transports can be retrieved using
476 * stream_get_transports. See
477 * for a list of bulitin transports.
478 * @param int|null $errno If the optional errno and errstr
479 * arguments are present they will be set to indicate the actual system
480 * level error that occurred in the system-level socket(),
481 * bind(), and listen() calls. If
482 * the value returned in errno is
483 * 0 and the function returned FALSE, it is an
484 * indication that the error occurred before the bind()
485 * call. This is most likely due to a problem initializing the socket.
486 * Note that the errno and
487 * errstr arguments will always be passed by reference.
488 * @param string|null $errstr See errno description.
489 * @param int $flags A bitmask field which may be set to any combination of socket creation
490 * flags.
491 *
492 * For UDP sockets, you must use STREAM_SERVER_BIND as
493 * the flags parameter.
494 * @param resource $context
495 *
496 * @return resource Returns the created stream.
497 * @throws StreamException
498 *
499 */
500 function stream_socket_server(string $local_socket, ?int &$errno = null, ?string &$errstr = null, int $flags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, $context = null)
501 {
502 error_clear_last();
503 if ($context !== null) {
504 $result = \stream_socket_server($local_socket, $errno, $errstr, $flags, $context);
505 } else {
506 $result = \stream_socket_server($local_socket, $errno, $errstr, $flags);
507 }
508 if ($result === false) {
509 throw StreamException::createFromPhpError();
510 }
511 return $result;
512 }
513
514
515 /**
516 * Shutdowns (partially or not) a full-duplex connection.
517 *
518 * @param resource $stream An open stream (opened with stream_socket_client,
519 * for example)
520 * @param int $how One of the following constants: STREAM_SHUT_RD
521 * (disable further receptions), STREAM_SHUT_WR
522 * (disable further transmissions) or
523 * STREAM_SHUT_RDWR (disable further receptions and
524 * transmissions).
525 * @throws StreamException
526 *
527 */
528 function stream_socket_shutdown($stream, int $how): void
529 {
530 error_clear_last();
531 $result = \stream_socket_shutdown($stream, $how);
532 if ($result === false) {
533 throw StreamException::createFromPhpError();
534 }
535 }
536
537
538 /**
539 * Tells whether the stream supports locking through
540 * flock.
541 *
542 * @param resource $stream The stream to check.
543 * @throws StreamException
544 *
545 */
546 function stream_supports_lock($stream): void
547 {
548 error_clear_last();
549 $result = \stream_supports_lock($stream);
550 if ($result === false) {
551 throw StreamException::createFromPhpError();
552 }
553 }
554
555
556 /**
557 * Allows you to implement your own protocol handlers and streams for use
558 * with all the other filesystem functions (such as fopen,
559 * fread etc.).
560 *
561 * @param string $protocol The wrapper name to be registered.
562 * @param string $classname The classname which implements the protocol.
563 * @param int $flags Should be set to STREAM_IS_URL if
564 * protocol is a URL protocol. Default is 0, local
565 * stream.
566 * @throws StreamException
567 *
568 */
569 function stream_wrapper_register(string $protocol, string $classname, int $flags = 0): void
570 {
571 error_clear_last();
572 $result = \stream_wrapper_register($protocol, $classname, $flags);
573 if ($result === false) {
574 throw StreamException::createFromPhpError();
575 }
576 }
577
578
579 /**
580 * Restores a built-in wrapper previously unregistered with
581 * stream_wrapper_unregister.
582 *
583 * @param string $protocol
584 * @throws StreamException
585 *
586 */
587 function stream_wrapper_restore(string $protocol): void
588 {
589 error_clear_last();
590 $result = \stream_wrapper_restore($protocol);
591 if ($result === false) {
592 throw StreamException::createFromPhpError();
593 }
594 }
595
596
597 /**
598 * Allows you to disable an already defined stream wrapper. Once the wrapper
599 * has been disabled you may override it with a user-defined wrapper using
600 * stream_wrapper_register or reenable it later on with
601 * stream_wrapper_restore.
602 *
603 * @param string $protocol
604 * @throws StreamException
605 *
606 */
607 function stream_wrapper_unregister(string $protocol): void
608 {
609 error_clear_last();
610 $result = \stream_wrapper_unregister($protocol);
611 if ($result === false) {
612 throw StreamException::createFromPhpError();
613 }
614 }
615