5 * Contains \Drupal\hacked\hackedFileHasher.
8 namespace Drupal\hacked;
11 * Base class for the different ways that files can be hashed.
13 abstract class hackedFileHasher {
15 * Returns a hash of the given filename.
17 * Ignores file line endings
19 function hash($filename) {
20 if (file_exists($filename)) {
21 if ($hash = $this->cache_get($filename)) {
25 $hash = $this->perform_hash($filename);
26 $this->cache_set($filename, $hash);
32 function cache_set($filename, $hash) {
33 \Drupal::cache(HACKED_CACHE_TABLE)->set($this->cache_key($filename), $hash, strtotime('+7 days'));
36 function cache_get($filename) {
37 $cache = \Drupal::cache(HACKED_CACHE_TABLE)->get($this->cache_key($filename));
38 if (!empty($cache->data)) {
43 function cache_key($filename) {
45 'filename' => $filename,
46 'mtime' => filemtime($filename),
47 'class_name' => get_class($this),
49 return sha1(serialize($key));
53 * Compute and return the hash of the given file.
56 * A fully-qualified filename to hash.
59 * The computed hash of the given file.
61 abstract function perform_hash($filename);
64 * Compute and return the lines of the given file.
67 * A fully-qualified filename to return.
70 * The lines of the given filename or FALSE on failure.
72 abstract function fetch_lines($filename);