|
1
|
|
|
<?php |
|
2
|
|
|
/******************************************************************** |
|
3
|
|
|
* Created by: Marko Kungla @ OkramLabs on Aug 6, 2012 - 9:58:05 |
|
4
|
|
|
* Contact: [email protected] - https://okramlabs.com |
|
5
|
|
|
* @copyright: 2015 OkramLabs - https://okramlabs.com |
|
6
|
|
|
* @license MIT |
|
7
|
|
|
* |
|
8
|
|
|
* Package name:libhowi-filesystem |
|
9
|
|
|
* @category HOWI3 |
|
10
|
|
|
* @package libhowi |
|
11
|
|
|
* @subpackage filesystem |
|
12
|
|
|
* |
|
13
|
|
|
* Lang: PHP |
|
14
|
|
|
* Encoding: UTF-8 |
|
15
|
|
|
******************************************************************** |
|
16
|
|
|
* Contributors: |
|
17
|
|
|
* @author Marko Kungla <[email protected]> |
|
18
|
|
|
* Github: https://github.com/mkungla |
|
19
|
|
|
******************************************************************** |
|
20
|
|
|
* Comments: |
|
21
|
|
|
*/ |
|
22
|
|
|
namespace HOWI3\libhowi\Filesystem\Commons; |
|
23
|
|
|
|
|
24
|
|
|
interface SharedMethodsInterface |
|
25
|
|
|
{ |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Gets the current working directory |
|
29
|
|
|
* |
|
30
|
|
|
* @return string; |
|
|
|
|
|
|
31
|
|
|
*/ |
|
32
|
|
|
public function getCwd(); |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Gets file or directory size |
|
36
|
|
|
* |
|
37
|
|
|
* For directory it will return directory total size |
|
38
|
|
|
* |
|
39
|
|
|
* @param string $filename |
|
|
|
|
|
|
40
|
|
|
* @param string $convert |
|
|
|
|
|
|
41
|
|
|
* @return in file / directory size or formated array |
|
42
|
|
|
*/ |
|
43
|
|
|
public function getSize($convert = false, $filename = false); |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Gets last access time of file |
|
47
|
|
|
* |
|
48
|
|
|
* @param string $timeformat |
|
|
|
|
|
|
49
|
|
|
* @param string $filename |
|
|
|
|
|
|
50
|
|
|
* @return int or formated output |
|
51
|
|
|
*/ |
|
52
|
|
|
public function getATime($timeformat = false, $pathname = false); |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Gets inode change time of file |
|
56
|
|
|
* |
|
57
|
|
|
* @param string $timeformat |
|
|
|
|
|
|
58
|
|
|
* @param string $filename |
|
|
|
|
|
|
59
|
|
|
* @return int or formated output |
|
60
|
|
|
*/ |
|
61
|
|
|
public function getCTime($timeformat = false, $pathname = false); |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Gets file modification time |
|
65
|
|
|
* |
|
66
|
|
|
* @param string $timeformat |
|
|
|
|
|
|
67
|
|
|
* @param string $filename |
|
|
|
|
|
|
68
|
|
|
* @return int or formated output |
|
69
|
|
|
*/ |
|
70
|
|
|
public function getMTime($timeformat = false, $pathname = false); |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Conver to ago |
|
74
|
|
|
* |
|
75
|
|
|
* @param time $timestamp |
|
76
|
|
|
* @param string $date_format |
|
77
|
|
|
* a | y,m,d,h,i,s |
|
78
|
|
|
* @param bool $sfx |
|
79
|
|
|
* short or long representation |
|
80
|
|
|
* @param string $ommit_zero |
|
|
|
|
|
|
81
|
|
|
* ommit emty values? |
|
82
|
|
|
* @param string $ago_single |
|
|
|
|
|
|
83
|
|
|
* @param array $clocale |
|
84
|
|
|
*/ |
|
85
|
|
|
public function ct_ago($timestamp, $date_format = 'y,m,d,h,i,s', $sfx = true, $ommit_zero = true, $ago_single = true, $clocale = []); |
|
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Creates an FileObject object of the file. |
|
89
|
|
|
* |
|
90
|
|
|
* This is useful because FileObject contains additional methods |
|
91
|
|
|
* for manipulating the file whereas FileInfo is only useful |
|
92
|
|
|
* for gaining information, like whether the file is writable. |
|
93
|
|
|
* |
|
94
|
|
|
* @param string $open_mode |
|
95
|
|
|
* @param string $use_include_path |
|
|
|
|
|
|
96
|
|
|
* @param unknown $context |
|
|
|
|
|
|
97
|
|
|
*/ |
|
98
|
|
|
public function openFile($open_mode = "r", $use_include_path = false, $context = null); |
|
|
|
|
|
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Sets the class used with InfoObject::openFile() |
|
102
|
|
|
* |
|
103
|
|
|
* @param string $class_name |
|
104
|
|
|
*/ |
|
105
|
|
|
public function setFileClass($class_name = "\HOWI3\libhowi\Filesystem\php5\Objects\FileObject"); |
|
|
|
|
|
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Sets the class used with InfoObject::getFileInfo() and SplFileInfo::getPathInfo() |
|
109
|
|
|
* |
|
110
|
|
|
* @param string $class_name |
|
111
|
|
|
*/ |
|
112
|
|
|
public function setInfoClass($class_name = "\HOWI3\libhowi\Filesystem\php5\Objects\InfoObject"); |
|
|
|
|
|
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Gets file owner username |
|
116
|
|
|
* |
|
117
|
|
|
* @param string $filename |
|
|
|
|
|
|
118
|
|
|
* @return string owners username |
|
119
|
|
|
*/ |
|
120
|
|
|
public function getOwnerName($filename = false); |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Gets file group name |
|
124
|
|
|
* |
|
125
|
|
|
* @param string $filename |
|
|
|
|
|
|
126
|
|
|
* @return string group name |
|
127
|
|
|
*/ |
|
128
|
|
|
public function getGroupName($filename = false); |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Returns canonicalized absolute pathname |
|
132
|
|
|
* |
|
133
|
|
|
* @param string $filename |
|
|
|
|
|
|
134
|
|
|
* @return string |
|
135
|
|
|
*/ |
|
136
|
|
|
public function getRealpath($filename = false); |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* Returns information about a file path |
|
140
|
|
|
* |
|
141
|
|
|
* If you supply $filename so you are not calling it on FileObject, InfoObject |
|
142
|
|
|
* or DirectoryTreeObject you can specify following flags |
|
143
|
|
|
* PATHINFO_DIRNAME, PATHINFO_BASENAME, PATHINFO_EXTENSION or PATHINFO_FILENAME. |
|
144
|
|
|
* |
|
145
|
|
|
* otherwise it will return FileInfo object fo this items path |
|
146
|
|
|
* |
|
147
|
|
|
* @param string $filename |
|
|
|
|
|
|
148
|
|
|
* @param int $flags |
|
|
|
|
|
|
149
|
|
|
* @return mixed |
|
150
|
|
|
*/ |
|
151
|
|
|
public function getPathInfo($filename = false, $flags = false, |
|
152
|
|
|
$class_name = '\HOWI3\libhowi\Filesystem\php5\Objects\InfoObject'); |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* Get path of current Iterator item without filename or |
|
156
|
|
|
* Gets the path without filename |
|
157
|
|
|
* |
|
158
|
|
|
* @return string $path |
|
159
|
|
|
*/ |
|
160
|
|
|
public function getPath(); |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* Gets the path to the file |
|
164
|
|
|
* |
|
165
|
|
|
* @return string $path |
|
166
|
|
|
*/ |
|
167
|
|
|
public function getPathname(); |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* Gets file group |
|
171
|
|
|
* |
|
172
|
|
|
* @param string $filename |
|
|
|
|
|
|
173
|
|
|
* @return int group id |
|
174
|
|
|
*/ |
|
175
|
|
|
public function getGroup($filename = false); |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* Gets file owner ID |
|
179
|
|
|
* |
|
180
|
|
|
* @param string $filename |
|
|
|
|
|
|
181
|
|
|
* @return int owners user id |
|
182
|
|
|
*/ |
|
183
|
|
|
public function getOwner($filename = false); |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* Gets item inode |
|
187
|
|
|
* |
|
188
|
|
|
* @param string $filename |
|
|
|
|
|
|
189
|
|
|
* @return int inode |
|
190
|
|
|
*/ |
|
191
|
|
|
public function getInode($filename = false); |
|
192
|
|
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* Returns trailing name component of path |
|
195
|
|
|
* |
|
196
|
|
|
* Getting the path to a file or directory from current iterator (non dot) position, |
|
197
|
|
|
* this function will return the trailing name component. When getBasename is called |
|
198
|
|
|
* on Dot the current directory basename is returned instead! |
|
199
|
|
|
* |
|
200
|
|
|
* @param string $suffix |
|
|
|
|
|
|
201
|
|
|
* @param string $pathname |
|
|
|
|
|
|
202
|
|
|
* @return string Name of given path |
|
203
|
|
|
*/ |
|
204
|
|
|
public function getBasename($suffix = false, $pathname = false); |
|
205
|
|
|
|
|
206
|
|
|
/** |
|
207
|
|
|
* Gets file permissions (non octal) |
|
208
|
|
|
* |
|
209
|
|
|
* @param string $filename |
|
|
|
|
|
|
210
|
|
|
* @return int like 755 |
|
211
|
|
|
*/ |
|
212
|
|
|
public function getPerms($filename = false); |
|
213
|
|
|
|
|
214
|
|
|
/** |
|
215
|
|
|
* Gets file type |
|
216
|
|
|
* |
|
217
|
|
|
* @param string $filename |
|
|
|
|
|
|
218
|
|
|
* @return string filetype |
|
219
|
|
|
*/ |
|
220
|
|
|
public function getType($filename = false); |
|
221
|
|
|
|
|
222
|
|
|
/** |
|
223
|
|
|
* Determine if current DirectoryIterator item is '.' or '..' |
|
224
|
|
|
* |
|
225
|
|
|
* @return bool |
|
226
|
|
|
*/ |
|
227
|
|
|
public function isDot(); |
|
228
|
|
|
|
|
229
|
|
|
/** |
|
230
|
|
|
* whether the file path is an absolute path. |
|
231
|
|
|
* |
|
232
|
|
|
* @param string $path |
|
|
|
|
|
|
233
|
|
|
* @return bool |
|
234
|
|
|
*/ |
|
235
|
|
|
public function isAbsolute($path = false); |
|
236
|
|
|
|
|
237
|
|
|
/** |
|
238
|
|
|
* whether the file path is an relative path. |
|
239
|
|
|
* |
|
240
|
|
|
* @param string $path |
|
|
|
|
|
|
241
|
|
|
* @return bool |
|
242
|
|
|
*/ |
|
243
|
|
|
public function isRelative($path = false); |
|
244
|
|
|
|
|
245
|
|
|
/** |
|
246
|
|
|
* Is path or directory writable |
|
247
|
|
|
* |
|
248
|
|
|
* @param string $path |
|
|
|
|
|
|
249
|
|
|
* @return bool |
|
250
|
|
|
*/ |
|
251
|
|
|
public function isWritable($path = false); |
|
252
|
|
|
|
|
253
|
|
|
/** |
|
254
|
|
|
* Tells whether a file exists and is readable |
|
255
|
|
|
* |
|
256
|
|
|
* @param string $filename |
|
|
|
|
|
|
257
|
|
|
* @return bool |
|
258
|
|
|
*/ |
|
259
|
|
|
public function isReadable($filename = false); |
|
260
|
|
|
|
|
261
|
|
|
/** |
|
262
|
|
|
* Tells whether the filename is a directory |
|
263
|
|
|
* |
|
264
|
|
|
* @param string $filename |
|
|
|
|
|
|
265
|
|
|
* @return bool |
|
266
|
|
|
*/ |
|
267
|
|
|
public function isDir($filename = false); |
|
268
|
|
|
|
|
269
|
|
|
/** |
|
270
|
|
|
* Tells whether the filename is executable |
|
271
|
|
|
* |
|
272
|
|
|
* @param string $filename |
|
|
|
|
|
|
273
|
|
|
* @return bool |
|
274
|
|
|
*/ |
|
275
|
|
|
public function isExecutable($filename = false); |
|
276
|
|
|
|
|
277
|
|
|
/** |
|
278
|
|
|
* Tells whether the filename is a regular file |
|
279
|
|
|
* |
|
280
|
|
|
* @param string $filename |
|
|
|
|
|
|
281
|
|
|
* @return bool |
|
282
|
|
|
*/ |
|
283
|
|
|
public function isFile($filename = false); |
|
284
|
|
|
|
|
285
|
|
|
/** |
|
286
|
|
|
* Tells whether the filename is a symbolic link |
|
287
|
|
|
* |
|
288
|
|
|
* @param string $filename |
|
|
|
|
|
|
289
|
|
|
* @return bool |
|
290
|
|
|
*/ |
|
291
|
|
|
public function isLink($filename = false); |
|
292
|
|
|
|
|
293
|
|
|
/** |
|
294
|
|
|
* Convert any path to absolute |
|
295
|
|
|
* |
|
296
|
|
|
* @param string $path |
|
|
|
|
|
|
297
|
|
|
* @return string absolute path |
|
298
|
|
|
*/ |
|
299
|
|
|
public function makeAbsolute($path = false); |
|
300
|
|
|
|
|
301
|
|
|
/** |
|
302
|
|
|
* Does file or directory exist |
|
303
|
|
|
* |
|
304
|
|
|
* @param string $pathname |
|
|
|
|
|
|
305
|
|
|
* @return bool |
|
306
|
|
|
*/ |
|
307
|
|
|
public function exists($pathname = false); |
|
308
|
|
|
|
|
309
|
|
|
/** |
|
310
|
|
|
* Return file name from path or Gets the file name from object |
|
311
|
|
|
* |
|
312
|
|
|
* @return array |
|
313
|
|
|
*/ |
|
314
|
|
|
public function getFilename($filename = false); |
|
315
|
|
|
|
|
316
|
|
|
/** |
|
317
|
|
|
* Gets the file extension |
|
318
|
|
|
* |
|
319
|
|
|
* @return string |
|
320
|
|
|
*/ |
|
321
|
|
|
public function getExtension($filename = false); |
|
322
|
|
|
} |
|
323
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.