3 namespace Drupal\hacked;
6 * Base class for the different ways that files can be hashed.
8 abstract class hackedFileHasher {
10 * Returns a hash of the given filename.
12 * Ignores file line endings
14 function hash($filename) {
15 if (file_exists($filename)) {
16 if ($hash = $this->cache_get($filename)) {
20 $hash = $this->perform_hash($filename);
21 $this->cache_set($filename, $hash);
27 function cache_set($filename, $hash) {
28 \Drupal::cache(HACKED_CACHE_TABLE)->set($this->cache_key($filename), $hash, strtotime('+7 days'));
31 function cache_get($filename) {
32 $cache = \Drupal::cache(HACKED_CACHE_TABLE)->get($this->cache_key($filename));
33 if (!empty($cache->data)) {
38 function cache_key($filename) {
40 'filename' => $filename,
41 'mtime' => filemtime($filename),
42 'class_name' => get_class($this),
44 return sha1(serialize($key));
48 * Compute and return the hash of the given file.
51 * A fully-qualified filename to hash.
54 * The computed hash of the given file.
56 abstract function perform_hash($filename);
59 * Compute and return the lines of the given file.
62 * A fully-qualified filename to return.
65 * The lines of the given filename or FALSE on failure.
67 abstract function fetch_lines($filename);