Pathologic was missing because of a .git folder inside.
[yaffs-website] / web / modules / contrib / hacked / src / hackedFileHasher.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\hacked\hackedFileHasher.
6  */
7
8 namespace Drupal\hacked;
9
10 /**
11  * Base class for the different ways that files can be hashed.
12  */
13 abstract class hackedFileHasher {
14   /**
15    * Returns a hash of the given filename.
16    *
17    * Ignores file line endings
18    */
19   function hash($filename) {
20     if (file_exists($filename)) {
21       if ($hash = $this->cache_get($filename)) {
22         return $hash;
23       }
24       else {
25         $hash = $this->perform_hash($filename);
26         $this->cache_set($filename, $hash);
27         return $hash;
28       }
29     }
30   }
31
32   function cache_set($filename, $hash) {
33     \Drupal::cache(HACKED_CACHE_TABLE)->set($this->cache_key($filename), $hash, strtotime('+7 days'));
34   }
35
36   function cache_get($filename) {
37     $cache = \Drupal::cache(HACKED_CACHE_TABLE)->get($this->cache_key($filename));
38     if (!empty($cache->data)) {
39       return $cache->data;
40     }
41   }
42
43   function cache_key($filename) {
44     $key = array(
45       'filename' => $filename,
46       'mtime' => filemtime($filename),
47       'class_name' => get_class($this),
48     );
49     return sha1(serialize($key));
50   }
51
52   /**
53    * Compute and return the hash of the given file.
54    *
55    * @param $filename
56    *   A fully-qualified filename to hash.
57    *
58    * @return string
59    *   The computed hash of the given file.
60    */
61   abstract function perform_hash($filename);
62
63   /**
64    * Compute and return the lines of the given file.
65    *
66    * @param $filename
67    *   A fully-qualified filename to return.
68    *
69    * @return array|bool
70    *   The lines of the given filename or FALSE on failure.
71    */
72   abstract function fetch_lines($filename);
73 }