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() |
||
109 | |||
110 | /** |
||
111 | * @param string $dir |
||
112 | * @param int $mask |
||
113 | * @param array $nomask |
||
114 | * @param callable $callback |
||
115 | * @param bool|true $recurse |
||
116 | * @param string $key |
||
117 | * @param int $min_depth |
||
118 | * @param int $depth |
||
119 | * |
||
120 | * @return array |
||
121 | */ |
||
122 | public static function scanDirectory( |
||
174 | |||
175 | /** |
||
176 | * Return a new hackedFileGroup listing all files specified. |
||
177 | * |
||
178 | * @param string $path |
||
179 | * @param array $files |
||
180 | * |
||
181 | * @return HackedFileGroup |
||
182 | */ |
||
183 | public static function createFromList($path, array $files) |
||
191 | |||
192 | /** |
||
193 | * @param string $file |
||
194 | * |
||
195 | * @return string|bool |
||
196 | */ |
||
197 | public function getFileHash($file) |
||
205 | |||
206 | /** |
||
207 | * @param string $file |
||
208 | * @return string |
||
209 | */ |
||
210 | public function getFileLocation($file) |
||
214 | |||
215 | /** |
||
216 | * @return array |
||
217 | */ |
||
218 | public function getFiles() |
||
222 | |||
223 | /** |
||
224 | * Determine if the given file is binary. |
||
225 | * @param string $file |
||
226 | * @return bool |
||
227 | */ |
||
228 | public function isNotBinary($file) |
||
233 | |||
234 | /** |
||
235 | * Determine if a file is a binary file. |
||
236 | * |
||
237 | * Taken from: http://www.ultrashock.com/forums/server-side/checking-if-a-file-is-binary-98391.html |
||
238 | * and then tweaked in: http://drupal.org/node/760362. |
||
239 | * |
||
240 | * @param string $file |
||
241 | * |
||
242 | * @return bool |
||
243 | */ |
||
244 | public static function isBinary($file) |
||
266 | |||
267 | /** |
||
268 | * Determine if the given file is readable. |
||
269 | * @param string $file |
||
270 | * @return bool |
||
271 | */ |
||
272 | public function isReadable($file) |
||
276 | } |
||
277 |