Zephir\FileSystem\HardDisk::getHashFile PHP Method

getHashFile() public method

This function does not perform operations in the temporary directory but it caches the results to avoid reprocessing
public getHashFile ( string $algorithm, string $path, boolean $cache = false ) : string
$algorithm string
$path string
$cache boolean
return string
    public function getHashFile($algorithm, $path, $cache = false)
    {
        if ($cache == false) {
            return hash_file($algorithm, $path);
        } else {
            $changed = false;
            $cacheFile = $this->basePath . Compiler::getCurrentVersion() . DIRECTORY_SEPARATOR . str_replace(array(DIRECTORY_SEPARATOR, ':', '/'), '_', $path) . '.md5';
            if (!file_exists($cacheFile)) {
                $hash = hash_file($algorithm, $path);
                file_put_contents($cacheFile, $hash);
                $changed = true;
            } else {
                if (filemtime($path) > filemtime($cacheFile)) {
                    $hash = hash_file($algorithm, $path);
                    file_put_contents($cacheFile, $hash);
                    $changed = true;
                }
            }
            if (!$changed) {
                return file_get_contents($cacheFile);
            }
            return $hash;
        }
    }