hackedFileHasher.php in Hacked! 8.2
File
src/hackedFileHasher.php
View source
<?php
namespace Drupal\hacked;
abstract class hackedFileHasher {
function hash($filename) {
if (file_exists($filename)) {
if ($hash = $this
->cache_get($filename)) {
return $hash;
}
else {
$hash = $this
->perform_hash($filename);
$this
->cache_set($filename, $hash);
return $hash;
}
}
}
function cache_set($filename, $hash) {
\Drupal::cache(HACKED_CACHE_TABLE)
->set($this
->cache_key($filename), $hash, strtotime('+7 days'));
}
function cache_get($filename) {
$cache = \Drupal::cache(HACKED_CACHE_TABLE)
->get($this
->cache_key($filename));
if (!empty($cache->data)) {
return $cache->data;
}
}
function cache_key($filename) {
$key = array(
'filename' => $filename,
'mtime' => filemtime($filename),
'class_name' => get_class($this),
);
return sha1(serialize($key));
}
abstract function perform_hash($filename);
abstract function fetch_lines($filename);
}