PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.0.1
Defender Security – Malware Scanner, Login Security & Firewall v6.0.1
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 / filesystem.php

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

1,492 lines 39.7 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\FilesystemException;
6
7 /**
8 * Attempts to change the group of the file filename
9 * to group.
10 *
11 * Only the superuser may change the group of a file arbitrarily; other users
12 * may change the group of a file to any group of which that user is a member.
13 *
14 * @param string $filename Path to the file.
15 * @param string|int $group A group name or number.
16 * @throws FilesystemException
17 *
18 */
19 function chgrp(string $filename, $group): void
20 {
21 error_clear_last();
22 $result = \chgrp($filename, $group);
23 if ($result === false) {
24 throw FilesystemException::createFromPhpError();
25 }
26 }
27
28
29 /**
30 * Attempts to change the mode of the specified file to that given in
31 * mode.
32 *
33 * @param string $filename Path to the file.
34 * @param int $mode Note that mode is not automatically
35 * assumed to be an octal value, so to ensure the expected operation,
36 * you need to prefix mode with a zero (0).
37 * Strings such as "g+w" will not work properly.
38 *
39 *
40 *
41 *
42 * ]]>
43 *
44 *
45 *
46 * The mode parameter consists of three octal
47 * number components specifying access restrictions for the owner,
48 * the user group in which the owner is in, and to everybody else in
49 * this order. One component can be computed by adding up the needed
50 * permissions for that target user base. Number 1 means that you
51 * grant execute rights, number 2 means that you make the file
52 * writeable, number 4 means that you make the file readable. Add
53 * up these numbers to specify needed rights. You can also read more
54 * about modes on Unix systems with 'man 1 chmod'
55 * and 'man 2 chmod'.
56 *
57 *
58 *
59 *
60 */
61 function chmod(string $filename, int $mode): void
62 {
63 error_clear_last();
64 $result = \chmod($filename, $mode);
65 if ($result === false) {
66 throw FilesystemException::createFromPhpError();
67 }
68 }
69
70
71 /**
72 * Attempts to change the owner of the file filename
73 * to user user. Only the superuser may change the
74 * owner of a file.
75 *
76 * @param string $filename Path to the file.
77 * @param string|int $user A user name or number.
78 * @throws FilesystemException
79 *
80 */
81 function chown(string $filename, $user): void
82 {
83 error_clear_last();
84 $result = \chown($filename, $user);
85 if ($result === false) {
86 throw FilesystemException::createFromPhpError();
87 }
88 }
89
90
91 /**
92 * Makes a copy of the file source to
93 * dest.
94 *
95 * If you wish to move a file, use the rename function.
96 *
97 * @param string $source Path to the source file.
98 * @param string $dest The destination path. If dest is a URL, the
99 * copy operation may fail if the wrapper does not support overwriting of
100 * existing files.
101 *
102 * If the destination file already exists, it will be overwritten.
103 * @param resource $context A valid context resource created with
104 * stream_context_create.
105 * @throws FilesystemException
106 *
107 */
108 function copy(string $source, string $dest, $context = null): void
109 {
110 error_clear_last();
111 if ($context !== null) {
112 $result = \copy($source, $dest, $context);
113 } else {
114 $result = \copy($source, $dest);
115 }
116 if ($result === false) {
117 throw FilesystemException::createFromPhpError();
118 }
119 }
120
121
122 /**
123 * Given a string containing a directory, this function will return the
124 * number of bytes available on the corresponding filesystem or disk
125 * partition.
126 *
127 * @param string $directory A directory of the filesystem or disk partition.
128 *
129 * Given a file name instead of a directory, the behaviour of the
130 * function is unspecified and may differ between operating systems and
131 * PHP versions.
132 * @return float Returns the number of available bytes as a float.
133 * @throws FilesystemException
134 *
135 */
136 function disk_free_space(string $directory): float
137 {
138 error_clear_last();
139 $result = \disk_free_space($directory);
140 if ($result === false) {
141 throw FilesystemException::createFromPhpError();
142 }
143 return $result;
144 }
145
146
147 /**
148 * Given a string containing a directory, this function will return the total
149 * number of bytes on the corresponding filesystem or disk partition.
150 *
151 * @param string $directory A directory of the filesystem or disk partition.
152 * @return float Returns the total number of bytes as a float.
153 * @throws FilesystemException
154 *
155 */
156 function disk_total_space(string $directory): float
157 {
158 error_clear_last();
159 $result = \disk_total_space($directory);
160 if ($result === false) {
161 throw FilesystemException::createFromPhpError();
162 }
163 return $result;
164 }
165
166
167 /**
168 * The file pointed to by handle is closed.
169 *
170 * @param resource $handle The file pointer must be valid, and must point to a file successfully
171 * opened by fopen or fsockopen.
172 * @throws FilesystemException
173 *
174 */
175 function fclose($handle): void
176 {
177 error_clear_last();
178 $result = \fclose($handle);
179 if ($result === false) {
180 throw FilesystemException::createFromPhpError();
181 }
182 }
183
184
185 /**
186 * This function forces a write of all buffered output to the resource
187 * pointed to by the file handle.
188 *
189 * @param resource $handle The file pointer must be valid, and must point to
190 * a file successfully opened by fopen or
191 * fsockopen (and not yet closed by
192 * fclose).
193 * @throws FilesystemException
194 *
195 */
196 function fflush($handle): void
197 {
198 error_clear_last();
199 $result = \fflush($handle);
200 if ($result === false) {
201 throw FilesystemException::createFromPhpError();
202 }
203 }
204
205
206 /**
207 * This function is similar to file, except that
208 * file_get_contents returns the file in a
209 * string, starting at the specified offset
210 * up to maxlen bytes. On failure,
211 * file_get_contents will return FALSE.
212 *
213 * file_get_contents is the preferred way to read the
214 * contents of a file into a string. It will use memory mapping techniques if
215 * supported by your OS to enhance performance.
216 *
217 * @param string $filename Name of the file to read.
218 * @param bool $use_include_path The FILE_USE_INCLUDE_PATH constant can be used
219 * to trigger include path
220 * search.
221 * This is not possible if strict typing
222 * is enabled, since FILE_USE_INCLUDE_PATH is an
223 * int. Use TRUE instead.
224 * @param resource|null $context A valid context resource created with
225 * stream_context_create. If you don't need to use a
226 * custom context, you can skip this parameter by NULL.
227 * @param int $offset The offset where the reading starts on the original stream.
228 * Negative offsets count from the end of the stream.
229 *
230 * Seeking (offset) is not supported with remote files.
231 * Attempting to seek on non-local files may work with small offsets, but this
232 * is unpredictable because it works on the buffered stream.
233 * @param int|null $maxlen Maximum length of data read. The default is to read until end
234 * of file is reached. Note that this parameter is applied to the
235 * stream processed by the filters.
236 *
237 * @return string The function returns the read data.
238 * @throws FilesystemException
239 *
240 */
241 function file_get_contents(string $filename, bool $use_include_path = false, $context = null, int $offset = 0, ?int $maxlen = null): string
242 {
243 error_clear_last();
244 if ($maxlen !== null) {
245 $result = \file_get_contents($filename, $use_include_path, $context, $offset, $maxlen);
246 } elseif ($offset !== 0) {
247 $result = \file_get_contents($filename, $use_include_path, $context, $offset);
248 } elseif ($context !== null) {
249 $result = \file_get_contents($filename, $use_include_path, $context);
250 } else {
251 $result = \file_get_contents($filename, $use_include_path);
252 }
253 if ($result === false) {
254 throw FilesystemException::createFromPhpError();
255 }
256 return $result;
257 }
258
259
260 /**
261 * This function is identical to calling fopen,
262 * fwrite and fclose successively
263 * to write data to a file.
264 *
265 * If filename does not exist, the file is created.
266 * Otherwise, the existing file is overwritten, unless the
267 * FILE_APPEND flag is set.
268 *
269 * @param string $filename Path to the file where to write the data.
270 * @param mixed $data The data to write. Can be either a string, an
271 * array or a stream resource.
272 *
273 * If data is a stream resource, the
274 * remaining buffer of that stream will be copied to the specified file.
275 * This is similar with using stream_copy_to_stream.
276 *
277 * You can also specify the data parameter as a single
278 * dimension array. This is equivalent to
279 * file_put_contents($filename, implode('', $array)).
280 * @param int $flags The value of flags can be any combination of
281 * the following flags, joined with the binary OR (|)
282 * operator.
283 *
284 *
285 * Available flags
286 *
287 *
288 *
289 * Flag
290 * Description
291 *
292 *
293 *
294 *
295 *
296 * FILE_USE_INCLUDE_PATH
297 *
298 *
299 * Search for filename in the include directory.
300 * See include_path for more
301 * information.
302 *
303 *
304 *
305 *
306 * FILE_APPEND
307 *
308 *
309 * If file filename already exists, append
310 * the data to the file instead of overwriting it.
311 *
312 *
313 *
314 *
315 * LOCK_EX
316 *
317 *
318 * Acquire an exclusive lock on the file while proceeding to the
319 * writing. In other words, a flock call happens
320 * between the fopen call and the
321 * fwrite call. This is not identical to an
322 * fopen call with mode "x".
323 *
324 *
325 *
326 *
327 *
328 * @param resource $context A valid context resource created with
329 * stream_context_create.
330 * @return int This function returns the number of bytes that were written to the file.
331 * @throws FilesystemException
332 *
333 */
334 function file_put_contents(string $filename, $data, int $flags = 0, $context = null): int
335 {
336 error_clear_last();
337 if ($context !== null) {
338 $result = \file_put_contents($filename, $data, $flags, $context);
339 } else {
340 $result = \file_put_contents($filename, $data, $flags);
341 }
342 if ($result === false) {
343 throw FilesystemException::createFromPhpError();
344 }
345 return $result;
346 }
347
348
349 /**
350 * Reads an entire file into an array.
351 *
352 * @param string $filename Path to the file.
353 * @param int $flags The optional parameter flags can be one, or
354 * more, of the following constants:
355 *
356 *
357 *
358 * FILE_USE_INCLUDE_PATH
359 *
360 *
361 *
362 * Search for the file in the include_path.
363 *
364 *
365 *
366 *
367 *
368 * FILE_IGNORE_NEW_LINES
369 *
370 *
371 *
372 * Omit newline at the end of each array element
373 *
374 *
375 *
376 *
377 *
378 * FILE_SKIP_EMPTY_LINES
379 *
380 *
381 *
382 * Skip empty lines
383 *
384 *
385 *
386 *
387 * @param resource $context
388 * @return array Returns the file in an array. Each element of the array corresponds to a
389 * line in the file, with the newline still attached. Upon failure,
390 * file returns FALSE.
391 * @throws FilesystemException
392 *
393 */
394 function file(string $filename, int $flags = 0, $context = null): array
395 {
396 error_clear_last();
397 if ($context !== null) {
398 $result = \file($filename, $flags, $context);
399 } else {
400 $result = \file($filename, $flags);
401 }
402 if ($result === false) {
403 throw FilesystemException::createFromPhpError();
404 }
405 return $result;
406 }
407
408
409 /**
410 *
411 *
412 * @param string $filename Path to the file.
413 * @return int Returns the time the file was last accessed.
414 * The time is returned as a Unix timestamp.
415 * @throws FilesystemException
416 *
417 */
418 function fileatime(string $filename): int
419 {
420 error_clear_last();
421 $result = \fileatime($filename);
422 if ($result === false) {
423 throw FilesystemException::createFromPhpError();
424 }
425 return $result;
426 }
427
428
429 /**
430 * Gets the inode change time of a file.
431 *
432 * @param string $filename Path to the file.
433 * @return int Returns the time the file was last changed.
434 * The time is returned as a Unix timestamp.
435 * @throws FilesystemException
436 *
437 */
438 function filectime(string $filename): int
439 {
440 error_clear_last();
441 $result = \filectime($filename);
442 if ($result === false) {
443 throw FilesystemException::createFromPhpError();
444 }
445 return $result;
446 }
447
448
449 /**
450 * Gets the file inode.
451 *
452 * @param string $filename Path to the file.
453 * @return int Returns the inode number of the file.
454 * @throws FilesystemException
455 *
456 */
457 function fileinode(string $filename): int
458 {
459 error_clear_last();
460 $result = \fileinode($filename);
461 if ($result === false) {
462 throw FilesystemException::createFromPhpError();
463 }
464 return $result;
465 }
466
467
468 /**
469 * This function returns the time when the data blocks of a file were being
470 * written to, that is, the time when the content of the file was changed.
471 *
472 * @param string $filename Path to the file.
473 * @return int Returns the time the file was last modified.
474 * The time is returned as a Unix timestamp, which is
475 * suitable for the date function.
476 * @throws FilesystemException
477 *
478 */
479 function filemtime(string $filename): int
480 {
481 error_clear_last();
482 $result = \filemtime($filename);
483 if ($result === false) {
484 throw FilesystemException::createFromPhpError();
485 }
486 return $result;
487 }
488
489
490 /**
491 * Gets the file owner.
492 *
493 * @param string $filename Path to the file.
494 * @return int Returns the user ID of the owner of the file.
495 * The user ID is returned in numerical format, use
496 * posix_getpwuid to resolve it to a username.
497 * @throws FilesystemException
498 *
499 */
500 function fileowner(string $filename): int
501 {
502 error_clear_last();
503 $result = \fileowner($filename);
504 if ($result === false) {
505 throw FilesystemException::createFromPhpError();
506 }
507 return $result;
508 }
509
510
511 /**
512 * Gets the size for the given file.
513 *
514 * @param string $filename Path to the file.
515 * @return int Returns the size of the file in bytes, or FALSE (and generates an error
516 * of level E_WARNING) in case of an error.
517 * @throws FilesystemException
518 *
519 */
520 function filesize(string $filename): int
521 {
522 error_clear_last();
523 $result = \filesize($filename);
524 if ($result === false) {
525 throw FilesystemException::createFromPhpError();
526 }
527 return $result;
528 }
529
530
531 /**
532 * flock allows you to perform a simple reader/writer
533 * model which can be used on virtually every platform (including most Unix
534 * derivatives and even Windows).
535 *
536 * On versions of PHP before 5.3.2, the lock is released also by
537 * fclose (which is also called automatically when script
538 * finished).
539 *
540 * PHP supports a portable way of locking complete files in an advisory way
541 * (which means all accessing programs have to use the same way of locking
542 * or it will not work). By default, this function will block until the
543 * requested lock is acquired; this may be controlled with the LOCK_NB option documented below.
544 *
545 * @param resource $handle A file system pointer resource
546 * that is typically created using fopen.
547 * @param int $operation operation is one of the following:
548 *
549 *
550 *
551 * LOCK_SH to acquire a shared lock (reader).
552 *
553 *
554 *
555 *
556 * LOCK_EX to acquire an exclusive lock (writer).
557 *
558 *
559 *
560 *
561 * LOCK_UN to release a lock (shared or exclusive).
562 *
563 *
564 *
565 *
566 * It is also possible to add LOCK_NB as a bitmask to one
567 * of the above operations, if flock should not
568 * block during the locking attempt.
569 * @param int|null $wouldblock The optional third argument is set to 1 if the lock would block
570 * (EWOULDBLOCK errno condition).
571 * @throws FilesystemException
572 *
573 */
574 function flock($handle, int $operation, ?int &$wouldblock = null): void
575 {
576 error_clear_last();
577 $result = \flock($handle, $operation, $wouldblock);
578 if ($result === false) {
579 throw FilesystemException::createFromPhpError();
580 }
581 }
582
583
584 /**
585 * fopen binds a named resource, specified by
586 * filename, to a stream.
587 *
588 * @param string $filename If filename is of the form "scheme://...", it
589 * is assumed to be a URL and PHP will search for a protocol handler
590 * (also known as a wrapper) for that scheme. If no wrappers for that
591 * protocol are registered, PHP will emit a notice to help you track
592 * potential problems in your script and then continue as though
593 * filename specifies a regular file.
594 *
595 * If PHP has decided that filename specifies
596 * a local file, then it will try to open a stream on that file.
597 * The file must be accessible to PHP, so you need to ensure that
598 * the file access permissions allow this access.
599 * If you have enabled
600 * open_basedir further
601 * restrictions may apply.
602 *
603 * If PHP has decided that filename specifies
604 * a registered protocol, and that protocol is registered as a
605 * network URL, PHP will check to make sure that
606 * allow_url_fopen is
607 * enabled. If it is switched off, PHP will emit a warning and
608 * the fopen call will fail.
609 *
610 * The list of supported protocols can be found in . Some protocols (also referred to as
611 * wrappers) support context
612 * and/or php.ini options. Refer to the specific page for the
613 * protocol in use for a list of options which can be set. (e.g.
614 * php.ini value user_agent used by the
615 * http wrapper).
616 *
617 * On the Windows platform, be careful to escape any backslashes
618 * used in the path to the file, or use forward slashes.
619 *
620 *
621 *
622 * ]]>
623 *
624 *
625 * @param string $mode The mode parameter specifies the type of access
626 * you require to the stream. It may be any of the following:
627 *
628 *
629 * A list of possible modes for fopen
630 * using mode
631 *
632 *
633 *
634 *
635 * mode
636 * Description
637 *
638 *
639 *
640 *
641 * 'r'
642 *
643 * Open for reading only; place the file pointer at the
644 * beginning of the file.
645 *
646 *
647 *
648 * 'r+'
649 *
650 * Open for reading and writing; place the file pointer at
651 * the beginning of the file.
652 *
653 *
654 *
655 * 'w'
656 *
657 * Open for writing only; place the file pointer at the
658 * beginning of the file and truncate the file to zero length.
659 * If the file does not exist, attempt to create it.
660 *
661 *
662 *
663 * 'w+'
664 *
665 * Open for reading and writing; place the file pointer at
666 * the beginning of the file and truncate the file to zero
667 * length. If the file does not exist, attempt to create it.
668 *
669 *
670 *
671 * 'a'
672 *
673 * Open for writing only; place the file pointer at the end of
674 * the file. If the file does not exist, attempt to create it.
675 * In this mode, fseek has no effect, writes are always appended.
676 *
677 *
678 *
679 * 'a+'
680 *
681 * Open for reading and writing; place the file pointer at
682 * the end of the file. If the file does not exist, attempt to
683 * create it. In this mode, fseek only affects
684 * the reading position, writes are always appended.
685 *
686 *
687 *
688 * 'x'
689 *
690 * Create and open for writing only; place the file pointer at the
691 * beginning of the file. If the file already exists, the
692 * fopen call will fail by returning FALSE and
693 * generating an error of level E_WARNING. If
694 * the file does not exist, attempt to create it. This is equivalent
695 * to specifying O_EXCL|O_CREAT flags for the
696 * underlying open(2) system call.
697 *
698 *
699 *
700 * 'x+'
701 *
702 * Create and open for reading and writing; otherwise it has the
703 * same behavior as 'x'.
704 *
705 *
706 *
707 * 'c'
708 *
709 * Open the file for writing only. If the file does not exist, it is
710 * created. If it exists, it is neither truncated (as opposed to
711 * 'w'), nor the call to this function fails (as is
712 * the case with 'x'). The file pointer is
713 * positioned on the beginning of the file. This may be useful if it's
714 * desired to get an advisory lock (see flock)
715 * before attempting to modify the file, as using
716 * 'w' could truncate the file before the lock
717 * was obtained (if truncation is desired,
718 * ftruncate can be used after the lock is
719 * requested).
720 *
721 *
722 *
723 * 'c+'
724 *
725 * Open the file for reading and writing; otherwise it has the same
726 * behavior as 'c'.
727 *
728 *
729 *
730 * 'e'
731 *
732 * Set close-on-exec flag on the opened file descriptor. Only
733 * available in PHP compiled on POSIX.1-2008 conform systems.
734 *
735 *
736 *
737 *
738 *
739 *
740 * Different operating system families have different line-ending
741 * conventions. When you write a text file and want to insert a line
742 * break, you need to use the correct line-ending character(s) for your
743 * operating system. Unix based systems use \n as the
744 * line ending character, Windows based systems use \r\n
745 * as the line ending characters and Macintosh based systems (Mac OS Classic) used
746 * \r as the line ending character.
747 *
748 * If you use the wrong line ending characters when writing your files, you
749 * might find that other applications that open those files will "look
750 * funny".
751 *
752 * Windows offers a text-mode translation flag ('t')
753 * which will transparently translate \n to
754 * \r\n when working with the file. In contrast, you
755 * can also use 'b' to force binary mode, which will not
756 * translate your data. To use these flags, specify either
757 * 'b' or 't' as the last character
758 * of the mode parameter.
759 *
760 * The default translation mode is 'b'.
761 * You can use the 't'
762 * mode if you are working with plain-text files and you use
763 * \n to delimit your line endings in your script, but
764 * expect your files to be readable with applications such as old versions of notepad. You
765 * should use the 'b' in all other cases.
766 *
767 * If you specify the 't' flag when working with binary files, you
768 * may experience strange problems with your data, including broken image
769 * files and strange problems with \r\n characters.
770 *
771 * For portability, it is also strongly recommended that
772 * you re-write code that uses or relies upon the 't'
773 * mode so that it uses the correct line endings and
774 * 'b' mode instead.
775 * @param bool $use_include_path The optional third use_include_path parameter
776 * can be set to '1' or TRUE if you want to search for the file in the
777 * include_path, too.
778 * @param resource $context
779 * @return resource Returns a file pointer resource on success
780 * @throws FilesystemException
781 *
782 */
783 function fopen(string $filename, string $mode, bool $use_include_path = false, $context = null)
784 {
785 error_clear_last();
786 if ($context !== null) {
787 $result = \fopen($filename, $mode, $use_include_path, $context);
788 } else {
789 $result = \fopen($filename, $mode, $use_include_path);
790 }
791 if ($result === false) {
792 throw FilesystemException::createFromPhpError();
793 }
794 return $result;
795 }
796
797
798 /**
799 * fputcsv formats a line (passed as a
800 * fields array) as CSV and writes it (terminated by a
801 * newline) to the specified file handle.
802 *
803 * @param resource $handle The file pointer must be valid, and must point to
804 * a file successfully opened by fopen or
805 * fsockopen (and not yet closed by
806 * fclose).
807 * @param array $fields An array of strings.
808 * @param string $delimiter The optional delimiter parameter sets the field
809 * delimiter (one character only).
810 * @param string $enclosure The optional enclosure parameter sets the field
811 * enclosure (one character only).
812 * @param string $escape_char The optional escape_char parameter sets the
813 * escape character (at most one character).
814 * An empty string ("") disables the proprietary escape mechanism.
815 * @return int Returns the length of the written string.
816 * @throws FilesystemException
817 *
818 */
819 function fputcsv($handle, array $fields, string $delimiter = ",", string $enclosure = '"', string $escape_char = "\\"): int
820 {
821 error_clear_last();
822 $result = \fputcsv($handle, $fields, $delimiter, $enclosure, $escape_char);
823 if ($result === false) {
824 throw FilesystemException::createFromPhpError();
825 }
826 return $result;
827 }
828
829
830 /**
831 * fread reads up to
832 * length bytes from the file pointer
833 * referenced by handle. Reading stops as soon as one
834 * of the following conditions is met:
835 *
836 *
837 *
838 * length bytes have been read
839 *
840 *
841 *
842 *
843 * EOF (end of file) is reached
844 *
845 *
846 *
847 *
848 * a packet becomes available or the
849 * socket timeout occurs (for network streams)
850 *
851 *
852 *
853 *
854 * if the stream is read buffered and it does not represent a plain file, at
855 * most one read of up to a number of bytes equal to the chunk size (usually
856 * 8192) is made; depending on the previously buffered data, the size of the
857 * returned data may be larger than the chunk size.
858 *
859 *
860 *
861 *
862 * @param resource $handle A file system pointer resource
863 * that is typically created using fopen.
864 * @param int $length Up to length number of bytes read.
865 * @return string Returns the read string.
866 * @throws FilesystemException
867 *
868 */
869 function fread($handle, int $length): string
870 {
871 error_clear_last();
872 $result = \fread($handle, $length);
873 if ($result === false) {
874 throw FilesystemException::createFromPhpError();
875 }
876 return $result;
877 }
878
879
880 /**
881 * Takes the filepointer, handle, and truncates the file to
882 * length, size.
883 *
884 * @param resource $handle The file pointer.
885 *
886 * The handle must be open for writing.
887 * @param int $size The size to truncate to.
888 *
889 * If size is larger than the file then the file
890 * is extended with null bytes.
891 *
892 * If size is smaller than the file then the file
893 * is truncated to that size.
894 * @throws FilesystemException
895 *
896 */
897 function ftruncate($handle, int $size): void
898 {
899 error_clear_last();
900 $result = \ftruncate($handle, $size);
901 if ($result === false) {
902 throw FilesystemException::createFromPhpError();
903 }
904 }
905
906
907 /**
908 *
909 *
910 * @param resource $handle A file system pointer resource
911 * that is typically created using fopen.
912 * @param string $string The string that is to be written.
913 * @param int|null $length If the length argument is given, writing will
914 * stop after length bytes have been written or
915 * the end of string is reached, whichever comes
916 * first.
917 *
918 * Note that if the length argument is given,
919 * then the magic_quotes_runtime
920 * configuration option will be ignored and no slashes will be
921 * stripped from string.
922 *
923 * @return int
924 * @throws FilesystemException
925 *
926 */
927 function fwrite($handle, string $string, ?int $length = null): int
928 {
929 error_clear_last();
930 if ($length !== null) {
931 $result = \fwrite($handle, $string, $length);
932 } else {
933 $result = \fwrite($handle, $string);
934 }
935 if ($result === false) {
936 throw FilesystemException::createFromPhpError();
937 }
938 return $result;
939 }
940
941
942 /**
943 * The glob function searches for all the pathnames
944 * matching pattern according to the rules used by
945 * the libc glob() function, which is similar to the rules used by common
946 * shells.
947 *
948 * @param string $pattern The pattern. No tilde expansion or parameter substitution is done.
949 *
950 * Special characters:
951 *
952 *
953 *
954 * * - Matches zero or more characters.
955 *
956 *
957 *
958 *
959 * ? - Matches exactly one character (any character).
960 *
961 *
962 *
963 *
964 * [...] - Matches one character from a group of
965 * characters. If the first character is !,
966 * matches any character not in the group.
967 *
968 *
969 *
970 *
971 * \ - Escapes the following character,
972 * except when the GLOB_NOESCAPE flag is used.
973 *
974 *
975 *
976 * @param int $flags Valid flags:
977 *
978 *
979 *
980 * GLOB_MARK - Adds a slash (a backslash on Windows) to each directory returned
981 *
982 *
983 *
984 *
985 * GLOB_NOSORT - Return files as they appear in the
986 * directory (no sorting). When this flag is not used, the pathnames are
987 * sorted alphabetically
988 *
989 *
990 *
991 *
992 * GLOB_NOCHECK - Return the search pattern if no
993 * files matching it were found
994 *
995 *
996 *
997 *
998 * GLOB_NOESCAPE - Backslashes do not quote
999 * metacharacters
1000 *
1001 *
1002 *
1003 *
1004 * GLOB_BRACE - Expands {a,b,c} to match 'a', 'b',
1005 * or 'c'
1006 *
1007 *
1008 *
1009 *
1010 * GLOB_ONLYDIR - Return only directory entries
1011 * which match the pattern
1012 *
1013 *
1014 *
1015 *
1016 * GLOB_ERR - Stop on read errors (like unreadable
1017 * directories), by default errors are ignored.
1018 *
1019 *
1020 *
1021 * @return array Returns an array containing the matched files/directories, an empty array
1022 * if no file matched.
1023 * @throws FilesystemException
1024 *
1025 */
1026 function glob(string $pattern, int $flags = 0): array
1027 {
1028 error_clear_last();
1029 $result = \glob($pattern, $flags);
1030 if ($result === false) {
1031 throw FilesystemException::createFromPhpError();
1032 }
1033 return $result;
1034 }
1035
1036
1037 /**
1038 * Attempts to change the group of the symlink filename
1039 * to group.
1040 *
1041 * Only the superuser may change the group of a symlink arbitrarily; other
1042 * users may change the group of a symlink to any group of which that user is
1043 * a member.
1044 *
1045 * @param string $filename Path to the symlink.
1046 * @param string|int $group The group specified by name or number.
1047 * @throws FilesystemException
1048 *
1049 */
1050 function lchgrp(string $filename, $group): void
1051 {
1052 error_clear_last();
1053 $result = \lchgrp($filename, $group);
1054 if ($result === false) {
1055 throw FilesystemException::createFromPhpError();
1056 }
1057 }
1058
1059
1060 /**
1061 * Attempts to change the owner of the symlink filename
1062 * to user user.
1063 *
1064 * Only the superuser may change the owner of a symlink.
1065 *
1066 * @param string $filename Path to the file.
1067 * @param string|int $user User name or number.
1068 * @throws FilesystemException
1069 *
1070 */
1071 function lchown(string $filename, $user): void
1072 {
1073 error_clear_last();
1074 $result = \lchown($filename, $user);
1075 if ($result === false) {
1076 throw FilesystemException::createFromPhpError();
1077 }
1078 }
1079
1080
1081 /**
1082 * link creates a hard link.
1083 *
1084 * @param string $target Target of the link.
1085 * @param string $link The link name.
1086 * @throws FilesystemException
1087 *
1088 */
1089 function link(string $target, string $link): void
1090 {
1091 error_clear_last();
1092 $result = \link($target, $link);
1093 if ($result === false) {
1094 throw FilesystemException::createFromPhpError();
1095 }
1096 }
1097
1098
1099 /**
1100 * Attempts to create the directory specified by pathname.
1101 *
1102 * @param string $pathname The directory path.
1103 * @param int $mode The mode is 0777 by default, which means the widest possible
1104 * access. For more information on modes, read the details
1105 * on the chmod page.
1106 *
1107 * mode is ignored on Windows.
1108 *
1109 * Note that you probably want to specify the mode as an octal number,
1110 * which means it should have a leading zero. The mode is also modified
1111 * by the current umask, which you can change using
1112 * umask.
1113 * @param bool $recursive Allows the creation of nested directories specified in the
1114 * pathname.
1115 * @param resource $context
1116 * @throws FilesystemException
1117 *
1118 */
1119 function mkdir(string $pathname, int $mode = 0777, bool $recursive = false, $context = null): void
1120 {
1121 error_clear_last();
1122 if ($context !== null) {
1123 $result = \mkdir($pathname, $mode, $recursive, $context);
1124 } else {
1125 $result = \mkdir($pathname, $mode, $recursive);
1126 }
1127 if ($result === false) {
1128 throw FilesystemException::createFromPhpError();
1129 }
1130 }
1131
1132
1133 /**
1134 * parse_ini_file loads in the
1135 * ini file specified in filename,
1136 * and returns the settings in it in an associative array.
1137 *
1138 * The structure of the ini file is the same as the php.ini's.
1139 *
1140 * @param string $filename The filename of the ini file being parsed. If a relative path is used,
1141 * it is evaluated relative to the current working directory, then the
1142 * include_path.
1143 * @param bool $process_sections By setting the process_sections
1144 * parameter to TRUE, you get a multidimensional array, with
1145 * the section names and settings included. The default
1146 * for process_sections is FALSE
1147 * @param int $scanner_mode Can either be INI_SCANNER_NORMAL (default) or
1148 * INI_SCANNER_RAW. If INI_SCANNER_RAW
1149 * is supplied, then option values will not be parsed.
1150 *
1151 *
1152 * As of PHP 5.6.1 can also be specified as INI_SCANNER_TYPED.
1153 * In this mode boolean, null and integer types are preserved when possible.
1154 * String values "true", "on" and "yes"
1155 * are converted to TRUE. "false", "off", "no"
1156 * and "none" are considered FALSE. "null" is converted to NULL
1157 * in typed mode. Also, all numeric strings are converted to integer type if it is possible.
1158 * @return array The settings are returned as an associative array on success.
1159 * @throws FilesystemException
1160 *
1161 */
1162 function parse_ini_file(string $filename, bool $process_sections = false, int $scanner_mode = INI_SCANNER_NORMAL): array
1163 {
1164 error_clear_last();
1165 $result = \parse_ini_file($filename, $process_sections, $scanner_mode);
1166 if ($result === false) {
1167 throw FilesystemException::createFromPhpError();
1168 }
1169 return $result;
1170 }
1171
1172
1173 /**
1174 * parse_ini_string returns the settings in string
1175 * ini in an associative array.
1176 *
1177 * The structure of the ini string is the same as the php.ini's.
1178 *
1179 * @param string $ini The contents of the ini file being parsed.
1180 * @param bool $process_sections By setting the process_sections
1181 * parameter to TRUE, you get a multidimensional array, with
1182 * the section names and settings included. The default
1183 * for process_sections is FALSE
1184 * @param int $scanner_mode Can either be INI_SCANNER_NORMAL (default) or
1185 * INI_SCANNER_RAW. If INI_SCANNER_RAW
1186 * is supplied, then option values will not be parsed.
1187 *
1188 *
1189 * As of PHP 5.6.1 can also be specified as INI_SCANNER_TYPED.
1190 * In this mode boolean, null and integer types are preserved when possible.
1191 * String values "true", "on" and "yes"
1192 * are converted to TRUE. "false", "off", "no"
1193 * and "none" are considered FALSE. "null" is converted to NULL
1194 * in typed mode. Also, all numeric strings are converted to integer type if it is possible.
1195 * @return array The settings are returned as an associative array on success.
1196 * @throws FilesystemException
1197 *
1198 */
1199 function parse_ini_string(string $ini, bool $process_sections = false, int $scanner_mode = INI_SCANNER_NORMAL): array
1200 {
1201 error_clear_last();
1202 $result = \parse_ini_string($ini, $process_sections, $scanner_mode);
1203 if ($result === false) {
1204 throw FilesystemException::createFromPhpError();
1205 }
1206 return $result;
1207 }
1208
1209
1210 /**
1211 * Reads a file and writes it to the output buffer.
1212 *
1213 * @param string $filename The filename being read.
1214 * @param bool $use_include_path You can use the optional second parameter and set it to TRUE, if
1215 * you want to search for the file in the include_path, too.
1216 * @param resource $context A context stream resource.
1217 * @return int Returns the number of bytes read from the file on success
1218 * @throws FilesystemException
1219 *
1220 */
1221 function readfile(string $filename, bool $use_include_path = false, $context = null): int
1222 {
1223 error_clear_last();
1224 if ($context !== null) {
1225 $result = \readfile($filename, $use_include_path, $context);
1226 } else {
1227 $result = \readfile($filename, $use_include_path);
1228 }
1229 if ($result === false) {
1230 throw FilesystemException::createFromPhpError();
1231 }
1232 return $result;
1233 }
1234
1235
1236 /**
1237 * readlink does the same as the readlink C function.
1238 *
1239 * @param string $path The symbolic link path.
1240 * @return string Returns the contents of the symbolic link path.
1241 * @throws FilesystemException
1242 *
1243 */
1244 function readlink(string $path): string
1245 {
1246 error_clear_last();
1247 $result = \readlink($path);
1248 if ($result === false) {
1249 throw FilesystemException::createFromPhpError();
1250 }
1251 return $result;
1252 }
1253
1254
1255 /**
1256 * realpath expands all symbolic links and
1257 * resolves references to /./, /../ and extra / characters in
1258 * the input path and returns the canonicalized
1259 * absolute pathname.
1260 *
1261 * @param string $path The path being checked.
1262 *
1263 *
1264 * Whilst a path must be supplied, the value can be an empty string.
1265 * In this case, the value is interpreted as the current directory.
1266 *
1267 *
1268 *
1269 * Whilst a path must be supplied, the value can be an empty string.
1270 * In this case, the value is interpreted as the current directory.
1271 * @return string Returns the canonicalized absolute pathname on success. The resulting path
1272 * will have no symbolic link, /./ or /../ components. Trailing delimiters,
1273 * such as \ and /, are also removed.
1274 *
1275 * realpath returns FALSE on failure, e.g. if
1276 * the file does not exist.
1277 * @throws FilesystemException
1278 *
1279 */
1280 function realpath(string $path): string
1281 {
1282 error_clear_last();
1283 $result = \realpath($path);
1284 if ($result === false) {
1285 throw FilesystemException::createFromPhpError();
1286 }
1287 return $result;
1288 }
1289
1290
1291 /**
1292 * Attempts to rename oldname to
1293 * newname, moving it between directories if necessary.
1294 * If renaming a file and newname exists,
1295 * it will be overwritten. If renaming a directory and
1296 * newname exists,
1297 * this function will emit a warning.
1298 *
1299 * @param string $oldname The old name.
1300 *
1301 * The wrapper used in oldname
1302 * must match the wrapper used in
1303 * newname.
1304 * @param string $newname The new name.
1305 * @param resource $context
1306 * @throws FilesystemException
1307 *
1308 */
1309 function rename(string $oldname, string $newname, $context = null): void
1310 {
1311 error_clear_last();
1312 if ($context !== null) {
1313 $result = \rename($oldname, $newname, $context);
1314 } else {
1315 $result = \rename($oldname, $newname);
1316 }
1317 if ($result === false) {
1318 throw FilesystemException::createFromPhpError();
1319 }
1320 }
1321
1322
1323 /**
1324 * Sets the file position indicator for handle
1325 * to the beginning of the file stream.
1326 *
1327 * @param resource $handle The file pointer must be valid, and must point to a file
1328 * successfully opened by fopen.
1329 * @throws FilesystemException
1330 *
1331 */
1332 function rewind($handle): void
1333 {
1334 error_clear_last();
1335 $result = \rewind($handle);
1336 if ($result === false) {
1337 throw FilesystemException::createFromPhpError();
1338 }
1339 }
1340
1341
1342 /**
1343 * Attempts to remove the directory named by dirname.
1344 * The directory must be empty, and the relevant permissions must permit this.
1345 * A E_WARNING level error will be generated on failure.
1346 *
1347 * @param string $dirname Path to the directory.
1348 * @param resource $context
1349 * @throws FilesystemException
1350 *
1351 */
1352 function rmdir(string $dirname, $context = null): void
1353 {
1354 error_clear_last();
1355 if ($context !== null) {
1356 $result = \rmdir($dirname, $context);
1357 } else {
1358 $result = \rmdir($dirname);
1359 }
1360 if ($result === false) {
1361 throw FilesystemException::createFromPhpError();
1362 }
1363 }
1364
1365
1366 /**
1367 * symlink creates a symbolic link to the existing
1368 * target with the specified name
1369 * link.
1370 *
1371 * @param string $target Target of the link.
1372 * @param string $link The link name.
1373 * @throws FilesystemException
1374 *
1375 */
1376 function symlink(string $target, string $link): void
1377 {
1378 error_clear_last();
1379 $result = \symlink($target, $link);
1380 if ($result === false) {
1381 throw FilesystemException::createFromPhpError();
1382 }
1383 }
1384
1385
1386 /**
1387 * Creates a file with a unique filename, with access permission set to 0600, in the specified directory.
1388 * If the directory does not exist or is not writable, tempnam may
1389 * generate a file in the system's temporary directory, and return
1390 * the full path to that file, including its name.
1391 *
1392 * @param string $dir The directory where the temporary filename will be created.
1393 * @param string $prefix The prefix of the generated temporary filename.
1394 * @return string Returns the new temporary filename (with path).
1395 * @throws FilesystemException
1396 *
1397 */
1398 function tempnam(string $dir, string $prefix): string
1399 {
1400 error_clear_last();
1401 $result = \tempnam($dir, $prefix);
1402 if ($result === false) {
1403 throw FilesystemException::createFromPhpError();
1404 }
1405 return $result;
1406 }
1407
1408
1409 /**
1410 * Creates a temporary file with a unique name in read-write (w+) mode and
1411 * returns a file handle.
1412 *
1413 * The file is automatically removed when closed (for example, by calling
1414 * fclose, or when there are no remaining references to
1415 * the file handle returned by tmpfile), or when the
1416 * script ends.
1417 *
1418 * @return resource Returns a file handle, similar to the one returned by
1419 * fopen, for the new file.
1420 * @throws FilesystemException
1421 *
1422 */
1423 function tmpfile()
1424 {
1425 error_clear_last();
1426 $result = \tmpfile();
1427 if ($result === false) {
1428 throw FilesystemException::createFromPhpError();
1429 }
1430 return $result;
1431 }
1432
1433
1434 /**
1435 * Attempts to set the access and modification times of the file named in the
1436 * filename parameter to the value given in
1437 * time.
1438 * Note that the access time is always modified, regardless of the number
1439 * of parameters.
1440 *
1441 * If the file does not exist, it will be created.
1442 *
1443 * @param string $filename The name of the file being touched.
1444 * @param int|null $time The touch time. If time is not supplied,
1445 * the current system time is used.
1446 * @param int|null $atime If present, the access time of the given filename is set to
1447 * the value of atime. Otherwise, it is set to
1448 * the value passed to the time parameter.
1449 * If neither are present, the current system time is used.
1450 *
1451 * @throws FilesystemException
1452 *
1453 */
1454 function touch(string $filename, ?int $time = null, ?int $atime = null): void
1455 {
1456 error_clear_last();
1457 if ($atime !== null) {
1458 $result = \touch($filename, $time, $atime);
1459 } elseif ($time !== null) {
1460 $result = \touch($filename, $time);
1461 } else {
1462 $result = \touch($filename);
1463 }
1464 if ($result === false) {
1465 throw FilesystemException::createFromPhpError();
1466 }
1467 }
1468
1469
1470 /**
1471 * Deletes filename. Similar to the Unix C unlink()
1472 * function. An E_WARNING level error will be generated on
1473 * failure.
1474 *
1475 * @param string $filename Path to the file.
1476 * @param resource $context
1477 * @throws FilesystemException
1478 *
1479 */
1480 function unlink(string $filename, $context = null): void
1481 {
1482 error_clear_last();
1483 if ($context !== null) {
1484 $result = \unlink($filename, $context);
1485 } else {
1486 $result = \unlink($filename);
1487 }
1488 if ($result === false) {
1489 throw FilesystemException::createFromPhpError();
1490 }
1491 }
1492