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

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

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