3 namespace Drupal\hacked;
5 use Drupal\Core\StringTranslation\StringTranslationTrait;
8 * Represents a group of files on the local filesystem.
10 class hackedFileGroup {
11 use StringTranslationTrait;
15 var $files_hashes = array();
16 var $file_mtimes = array();
23 function __construct($base_path) {
24 $this->base_path = $base_path;
25 $this->hasher = hacked_get_file_hasher();
29 * Return a new hackedFileGroup listing all files inside the given $path.
31 static function fromDirectory($path) {
32 $filegroup = new hackedFileGroup($path);
33 // Find all the files in the path, and add them to the file group.
34 $filegroup->scan_base_path();
39 * Return a new hackedFileGroup listing all files specified.
41 static function fromList($path, $files) {
42 $filegroup = new hackedFileGroup($path);
43 // Find all the files in the path, and add them to the file group.
44 $filegroup->files = $files;
49 * Locate all sensible files at the base path of the file group.
51 function scan_base_path() {
52 $files = hacked_file_scan_directory($this->base_path, '/.*/', array(
59 foreach ($files as $file) {
60 $filename = str_replace($this->base_path . '/', '', $file->filename);
61 $this->files[] = $filename;
66 * Hash all files listed in the file group.
68 function compute_hashes() {
69 foreach ($this->files as $filename) {
70 $this->files_hashes[$filename] = $this->hasher->hash($this->base_path . '/' . $filename);
75 * Determine if the given file is readable.
77 function is_readable($file) {
78 return is_readable($this->base_path . '/' . $file);
82 * Determine if a file exists.
84 function file_exists($file) {
85 return file_exists($this->base_path . '/' . $file);
89 * Determine if the given file is binary.
91 function is_not_binary($file) {
92 return is_readable($this->base_path . '/' . $file) && !hacked_file_is_binary($this->base_path . '/' . $file);
95 function file_get_location($file) {
96 return $this->base_path . '/' . $file;