PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 3.3.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v3.3.1
3.3.1 V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 All 138 releases
bit-form / vendor / typisttech / imposter / src / Filesystem.php

Filesystem.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 3.3.1, at vendor/typisttech/imposter/src/Filesystem.php

95 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace TypistTech\Imposter;
6
7 use FilesystemIterator;
8 use RecursiveDirectoryIterator;
9 use RecursiveIteratorIterator;
10 use RuntimeException;
11
12 class Filesystem implements FilesystemInterface
13 {
14 /**
15 * @param string $path
16 *
17 * @return \SplFileInfo[]
18 * @throws \UnexpectedValueException
19 */
20 public function allFiles(string $path): array
21 {
22 $iterator = new RecursiveIteratorIterator(
23 new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS)
24 );
25
26 return iterator_to_array($iterator);
27 }
28
29 /**
30 * Extract the parent directory from a file path.
31 *
32 * @param string $path
33 *
34 * @return string
35 */
36 public function dirname(string $path): string
37 {
38 return pathinfo($path, PATHINFO_DIRNAME);
39 }
40
41 /**
42 * Get the contents of a file.
43 *
44 * @param string $path
45 *
46 * @return string
47 * @throws \RuntimeException
48 */
49 public function get(string $path): string
50 {
51 if (! $this->isFile($path)) {
52 throw new RuntimeException('File does not exist at path ' . $path);
53 }
54
55 return file_get_contents($path);
56 }
57
58 /**
59 * Determine if the given path is a file.
60 *
61 * @param string $path
62 *
63 * @return bool
64 */
65 public function isFile(string $path): bool
66 {
67 return is_file($path);
68 }
69
70 /**
71 * Determine if the given path is a directory.
72 *
73 * @param string $path
74 *
75 * @return bool
76 */
77 public function isDir(string $path): bool
78 {
79 return is_dir($path);
80 }
81
82 /**
83 * Write the contents of a file.
84 *
85 * @param string $path
86 * @param string $contents
87 *
88 * @return int|false
89 */
90 public function put(string $path, string $contents)
91 {
92 return file_put_contents($path, $contents);
93 }
94 }
95