1 | <?php |
||
8 | class HackedFileGroup |
||
9 | { |
||
10 | /** |
||
11 | * @var string |
||
12 | */ |
||
13 | protected $base_path = ''; |
||
14 | |||
15 | /** |
||
16 | * @var array |
||
17 | */ |
||
18 | protected $files = array(); |
||
19 | |||
20 | /** |
||
21 | * @var array |
||
22 | */ |
||
23 | protected $files_hashes = array(); |
||
24 | |||
25 | /** |
||
26 | * @var array |
||
27 | */ |
||
28 | protected $file_mtimes = array(); |
||
29 | |||
30 | /** |
||
31 | * @var HackedFileHasher |
||
32 | */ |
||
33 | protected $hasher; |
||
34 | |||
35 | /** |
||
36 | * Constructor. |
||
37 | * |
||
38 | * @param string $base_path |
||
39 | * @param HackedFileHasher $hasher |
||
40 | */ |
||
41 | public function __construct($base_path, HackedFileHasher $hasher = null) |
||
50 | |||
51 | /** |
||
52 | * Hash all files listed in the file group. |
||
53 | */ |
||
54 | public function computeHashes() |
||
60 | |||
61 | /** |
||
62 | * Determine if a file exists. |
||
63 | * @param string $file |
||
64 | * @return bool |
||
65 | */ |
||
66 | public function fileExists($file) |
||
70 | |||
71 | /** |
||
72 | * Return a new hackedFileGroup listing all files inside the given $path. |
||
73 | * |
||
74 | * @param string $path |
||
75 | * |
||
76 | * @return HackedFileGroup |
||
77 | */ |
||
78 | public static function createFromDirectory($path) |
||
86 | |||
87 | /** |
||
88 | * Locate all sensible files at the base path of the file group. |
||
89 | */ |
||
90 | public function scanBasePath() |
||
100 | |||
101 | /** |
||
102 | * @param string $dir |
||
103 | * @param int $mask |
||
104 | * @param array $nomask |
||
105 | * @param callable $callback |
||
106 | * @param bool|true $recurse |
||
107 | * @param string $key |
||
108 | * @param int $min_depth |
||
109 | * @param int $depth |
||
110 | * |
||
111 | * @return array |
||
112 | */ |
||
113 | public static function scanDirectory( |
||
165 | |||
166 | /** |
||
167 | * Return a new hackedFileGroup listing all files specified. |
||
168 | * |
||
169 | * @param string $path |
||
170 | * @param array $files |
||
171 | * |
||
172 | * @return HackedFileGroup |
||
173 | */ |
||
174 | public static function createFromList($path, array $files) |
||
182 | |||
183 | /** |
||
184 | * @param string $file |
||
185 | * |
||
186 | * @return string|bool |
||
187 | */ |
||
188 | public function getFileHash($file) |
||
196 | |||
197 | /** |
||
198 | * @param string $file |
||
199 | * @return string |
||
200 | */ |
||
201 | public function getFileLocation($file) |
||
205 | |||
206 | /** |
||
207 | * @return array |
||
208 | */ |
||
209 | public function getFiles() |
||
213 | |||
214 | /** |
||
215 | * Determine if the given file is binary. |
||
216 | * @param string $file |
||
217 | * @return bool |
||
218 | */ |
||
219 | public function isNotBinary($file) |
||
224 | |||
225 | /** |
||
226 | * Determine if a file is a binary file. |
||
227 | * |
||
228 | * Taken from: http://www.ultrashock.com/forums/server-side/checking-if-a-file-is-binary-98391.html |
||
229 | * and then tweaked in: http://drupal.org/node/760362. |
||
230 | * |
||
231 | * @param string $file |
||
232 | * |
||
233 | * @return bool |
||
234 | */ |
||
235 | public static function isBinary($file) |
||
257 | |||
258 | /** |
||
259 | * Determine if the given file is readable. |
||
260 | * @param string $file |
||
261 | * @return bool |
||
262 | */ |
||
263 | public function isReadable($file) |
||
267 | } |
||
268 |