1
1
<?php
2
+
2
3
namespace Trihydera \File ;
3
4
4
5
/**
5
6
* Class FileInfo
6
- *
7
+ *
7
8
* Retrieves information about files in a directory, including file details like size, hash, and modification time.
8
9
*/
9
- class FileInfo {
10
+ class FileInfo
11
+ {
10
12
private $ dir ;
11
13
12
14
/**
13
15
* FileInfo constructor.
14
- *
16
+ *
15
17
* @param string $dir The directory path to retrieve file information from.
16
18
*/
17
- public function __construct ($ dir ) {
19
+ public function __construct ($ dir )
20
+ {
18
21
$ this ->dir = $ dir ;
19
22
}
20
23
21
24
/**
22
25
* Get information about files in the directory.
23
- *
26
+ *
24
27
* @return array An array containing details of files in the directory.
25
28
*/
26
- public function getInfo () {
29
+ public function getInfo ()
30
+ {
27
31
$ details = [];
28
32
$ this ->listFilesRecursively ($ this ->dir , $ details );
29
33
return $ details ;
30
34
}
31
35
32
36
/**
33
37
* Recursively list files in a directory and gather details.
34
- *
38
+ *
35
39
* @param string $dir The directory path to list files from.
36
40
* @param array $details Reference to an array to store file details.
37
41
*/
38
- private function listFilesRecursively ($ dir , &$ details ) {
42
+ private function listFilesRecursively ($ dir , &$ details )
43
+ {
39
44
$ files = scandir ($ dir );
40
45
41
46
foreach ($ files as $ file ) {
@@ -69,14 +74,14 @@ private function listFilesRecursively($dir, &$details) {
69
74
70
75
/**
71
76
* Format file size in human-readable format.
72
- *
77
+ *
73
78
* @param int $bytes The size of the file in bytes.
74
79
* @return string The formatted file size with appropriate units.
75
80
*/
76
- private function formatSize ($ bytes ) {
81
+ private function formatSize ($ bytes )
82
+ {
77
83
$ units = array ('B ' , 'KB ' , 'MB ' , 'GB ' , 'TB ' );
78
84
$ i = floor (log ($ bytes , 1024 ));
79
85
return @round ($ bytes / pow (1024 , $ i ), 2 ) . ' ' . $ units [$ i ];
80
86
}
81
87
}
82
- ?>
0 commit comments