5 * Contains \Drupal\hacked\hackedFileGroup.
8 namespace Drupal\hacked;
10 use Drupal\Core\StringTranslation\StringTranslationTrait;
13 * Represents a group of files on the local filesystem.
15 class hackedFileGroup {
16 use StringTranslationTrait;
20 var $files_hashes = array();
21 var $file_mtimes = array();
28 function __construct($base_path) {
29 $this->base_path = $base_path;
30 $this->hasher = hacked_get_file_hasher();
34 * Return a new hackedFileGroup listing all files inside the given $path.
36 static function fromDirectory($path) {
37 $filegroup = new hackedFileGroup($path);
38 // Find all the files in the path, and add them to the file group.
39 $filegroup->scan_base_path();
44 * Return a new hackedFileGroup listing all files specified.
46 static function fromList($path, $files) {
47 $filegroup = new hackedFileGroup($path);
48 // Find all the files in the path, and add them to the file group.
49 $filegroup->files = $files;
54 * Locate all sensible files at the base path of the file group.
56 function scan_base_path() {
57 $files = hacked_file_scan_directory($this->base_path, '/.*/', array(
64 foreach ($files as $file) {
65 $filename = str_replace($this->base_path . '/', '', $file->filename);
66 $this->files[] = $filename;
71 * Hash all files listed in the file group.
73 function compute_hashes() {
74 foreach ($this->files as $filename) {
75 $this->files_hashes[$filename] = $this->hasher->hash($this->base_path . '/' . $filename);
80 * Determine if the given file is readable.
82 function is_readable($file) {
83 return is_readable($this->base_path . '/' . $file);
87 * Determine if a file exists.
89 function file_exists($file) {
90 return file_exists($this->base_path . '/' . $file);
94 * Determine if the given file is binary.
96 function is_not_binary($file) {
97 return is_readable($this->base_path . '/' . $file) && !hacked_file_is_binary($this->base_path . '/' . $file);
100 function file_get_location($file) {
101 return $this->base_path . '/' . $file;