Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
16 / 16 |
|
100.00% |
16 / 16 |
CRAP | |
100.00% |
1 / 1 |
StorageAbstract | |
100.00% |
16 / 16 |
|
100.00% |
16 / 16 |
16 | |
100.00% |
1 / 1 |
getClassType | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
created | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
changed | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
owner | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
permission | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
parent | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
delete | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
copy | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
move | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
size | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
exists | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
name | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
basename | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
dirname | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
dirpath | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
count | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
sanitize | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | /** |
3 | * Jingga |
4 | * |
5 | * PHP Version 8.1 |
6 | * |
7 | * @package phpOMS\System\File |
8 | * @copyright Dennis Eichhorn |
9 | * @license OMS License 2.0 |
10 | * @version 1.0.0 |
11 | * @link https://jingga.app |
12 | */ |
13 | declare(strict_types=1); |
14 | |
15 | namespace phpOMS\System\File; |
16 | |
17 | /** |
18 | * Filesystem class. |
19 | * |
20 | * Performing operations on the file system |
21 | * |
22 | * @package phpOMS\System\File |
23 | * @license OMS License 2.0 |
24 | * @link https://jingga.app |
25 | * @since 1.0.0 |
26 | */ |
27 | abstract class StorageAbstract |
28 | { |
29 | /** |
30 | * Get the internal class type (directory or file) based on path. |
31 | * |
32 | * @param string $path Path to the directory or file |
33 | * |
34 | * @return string Class namespace |
35 | * |
36 | * @since 1.0.0 |
37 | */ |
38 | abstract protected static function getClassType(string $path) : string; |
39 | |
40 | /** |
41 | * Get the datetime when the resource got created. |
42 | * |
43 | * @param string $path Path of the resource |
44 | * |
45 | * @return \DateTime |
46 | * |
47 | * @since 1.0.0 |
48 | */ |
49 | public static function created(string $path) : \DateTime |
50 | { |
51 | return static::getClassType($path)::created($path); |
52 | } |
53 | |
54 | /** |
55 | * Get the datetime when the resource got last modified. |
56 | * |
57 | * @param string $path Path of the resource |
58 | * |
59 | * @return \DateTime |
60 | * |
61 | * @since 1.0.0 |
62 | */ |
63 | public static function changed(string $path) : \DateTime |
64 | { |
65 | return static::getClassType($path)::changed($path); |
66 | } |
67 | |
68 | /** |
69 | * Get the owner id of the resource. |
70 | * |
71 | * @param string $path Path of the resource |
72 | * |
73 | * @return int |
74 | * |
75 | * @since 1.0.0 |
76 | */ |
77 | public static function owner(string $path) : int |
78 | { |
79 | return static::getClassType($path)::owner($path); |
80 | } |
81 | |
82 | /** |
83 | * Get the permissions id of the resource. |
84 | * |
85 | * @param string $path Path of the resource |
86 | * |
87 | * @return int Permissions (e.g. 0755); |
88 | * |
89 | * @since 1.0.0 |
90 | */ |
91 | public static function permission(string $path) : int |
92 | { |
93 | return static::getClassType($path)::permission($path); |
94 | } |
95 | |
96 | /** |
97 | * Get the parent path of the resource. |
98 | * |
99 | * The parent resource path is always a directory. |
100 | * |
101 | * @param string $path Path of the resource |
102 | * |
103 | * @return string |
104 | * |
105 | * @since 1.0.0 |
106 | */ |
107 | public static function parent(string $path) : string |
108 | { |
109 | return static::getClassType($path)::parent($path); |
110 | } |
111 | |
112 | /** |
113 | * Delete resource at destination path. |
114 | * |
115 | * @param string $path Path of the resource |
116 | * |
117 | * @return bool True on success and false on failure |
118 | * |
119 | * @since 1.0.0 |
120 | */ |
121 | public static function delete(string $path) : bool |
122 | { |
123 | return static::getClassType($path)::delete($path); |
124 | } |
125 | |
126 | /** |
127 | * Copy resource to different location. |
128 | * |
129 | * @param string $from Path of the resource to copy |
130 | * @param string $to Path of the resource to copy to |
131 | * @param bool $overwrite Overwrite/replace existing file |
132 | * |
133 | * @return bool True on success and false on failure |
134 | * |
135 | * @since 1.0.0 |
136 | */ |
137 | public static function copy(string $from, string $to, bool $overwrite = false) : bool |
138 | { |
139 | return static::getClassType($from)::copy($from, $to, $overwrite); |
140 | } |
141 | |
142 | /** |
143 | * Move resource to different location. |
144 | * |
145 | * @param string $from Path of the resource to move |
146 | * @param string $to Path of the resource to move to |
147 | * @param bool $overwrite Overwrite/replace existing file |
148 | * |
149 | * @return bool True on success and false on failure |
150 | * |
151 | * @since 1.0.0 |
152 | */ |
153 | public static function move(string $from, string $to, bool $overwrite = false) : bool |
154 | { |
155 | return static::getClassType($from)::move($from, $to, $overwrite); |
156 | } |
157 | |
158 | /** |
159 | * Get size of resource. |
160 | * |
161 | * @param string $path Path of the resource |
162 | * @param bool $recursive Should include sub-sub-resources |
163 | * |
164 | * @return int |
165 | * |
166 | * @since 1.0.0 |
167 | */ |
168 | public static function size(string $path, bool $recursive = true) : int |
169 | { |
170 | return static::getClassType($path)::size($path, $recursive); |
171 | } |
172 | |
173 | /** |
174 | * Check existence of resource. |
175 | * |
176 | * @param string $path Path of the resource |
177 | * |
178 | * @return bool |
179 | * |
180 | * @since 1.0.0 |
181 | */ |
182 | public static function exists(string $path) : bool |
183 | { |
184 | return static::getClassType($path)::exists($path); |
185 | } |
186 | |
187 | /** |
188 | * Get name of resource. |
189 | * |
190 | * @param string $path Path of the resource |
191 | * |
192 | * @return string |
193 | * |
194 | * @since 1.0.0 |
195 | */ |
196 | public static function name(string $path) : string |
197 | { |
198 | return static::getClassType($path)::name($path); |
199 | } |
200 | |
201 | /** |
202 | * Get basename of resource. |
203 | * |
204 | * @param string $path Path of the resource |
205 | * |
206 | * @return string |
207 | * |
208 | * @since 1.0.0 |
209 | */ |
210 | public static function basename(string $path) : string |
211 | { |
212 | return static::getClassType($path)::basename($path); |
213 | } |
214 | |
215 | /** |
216 | * Get the directoryname of the resource. |
217 | * |
218 | * @param string $path Path of the resource |
219 | * |
220 | * @return string |
221 | * |
222 | * @since 1.0.0 |
223 | */ |
224 | public static function dirname(string $path) : string |
225 | { |
226 | return static::getClassType($path)::dirname($path); |
227 | } |
228 | |
229 | /** |
230 | * Get the directory path of the resource. |
231 | * |
232 | * @param string $path Path of the resource |
233 | * |
234 | * @return string |
235 | * |
236 | * @since 1.0.0 |
237 | */ |
238 | public static function dirpath(string $path) : string |
239 | { |
240 | return static::getClassType($path)::dirpath($path); |
241 | } |
242 | |
243 | /** |
244 | * Count subresources. |
245 | * |
246 | * @param string $path Path of the resource |
247 | * @param bool $recursive Consider subdirectories |
248 | * @param string[] $ignore Files/paths to ignore (no regex) |
249 | * |
250 | * @return int |
251 | * |
252 | * @since 1.0.0 |
253 | */ |
254 | public static function count(string $path, bool $recursive = true, array $ignore = []) : int |
255 | { |
256 | return static::getClassType($path)::count($path, $recursive, $ignore); |
257 | } |
258 | |
259 | /** |
260 | * Make name/path operating system safe. |
261 | * |
262 | * @param string $path Path of the resource |
263 | * @param string $replace Replace invalid chars with |
264 | * @param string $invalid Invalid chars to sanitize |
265 | * |
266 | * @return string |
267 | * |
268 | * @since 1.0.0 |
269 | */ |
270 | public static function sanitize(string $path, string $replace = '', string $invalid = '/[^\w\s\d\.\-_~,;\/\[\]\(\]]/') : string |
271 | { |
272 | return static::getClassType($path)::sanitize($path, $replace); |
273 | } |
274 | } |