Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / modules / contrib / hacked / src / hackedFileGroup.php
1 <?php
2
3 namespace Drupal\hacked;
4
5 use Drupal\Core\StringTranslation\StringTranslationTrait;
6
7 /**
8  * Represents a group of files on the local filesystem.
9  */
10 class hackedFileGroup {
11   use StringTranslationTrait;
12
13   var $base_path = '';
14   var $files = array();
15   var $files_hashes = array();
16   var $file_mtimes = array();
17
18   var $hasher;
19
20   /**
21    * Constructor.
22    */
23   function __construct($base_path) {
24     $this->base_path = $base_path;
25     $this->hasher = hacked_get_file_hasher();
26   }
27
28   /**
29    * Return a new hackedFileGroup listing all files inside the given $path.
30    */
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();
35     return $filegroup;
36   }
37
38   /**
39    * Return a new hackedFileGroup listing all files specified.
40    */
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;
45     return $filegroup;
46   }
47
48   /**
49    * Locate all sensible files at the base path of the file group.
50    */
51   function scan_base_path() {
52     $files = hacked_file_scan_directory($this->base_path, '/.*/', array(
53       '.',
54       '..',
55       'CVS',
56       '.svn',
57       '.git'
58     ));
59     foreach ($files as $file) {
60       $filename = str_replace($this->base_path . '/', '', $file->filename);
61       $this->files[] = $filename;
62     }
63   }
64
65   /**
66    * Hash all files listed in the file group.
67    */
68   function compute_hashes() {
69     foreach ($this->files as $filename) {
70       $this->files_hashes[$filename] = $this->hasher->hash($this->base_path . '/' . $filename);
71     }
72   }
73
74   /**
75    * Determine if the given file is readable.
76    */
77   function is_readable($file) {
78     return is_readable($this->base_path . '/' . $file);
79   }
80
81   /**
82    * Determine if a file exists.
83    */
84   function file_exists($file) {
85     return file_exists($this->base_path . '/' . $file);
86   }
87
88   /**
89    * Determine if the given file is binary.
90    */
91   function is_not_binary($file) {
92     return is_readable($this->base_path . '/' . $file) && !hacked_file_is_binary($this->base_path . '/' . $file);
93   }
94
95   function file_get_location($file) {
96     return $this->base_path . '/' . $file;
97   }
98
99 }