Recursively md5 hash all files in a path

@param string $path
@return string
196342
public static function hashAllFiles($path)
    {
        $flags = \RecursiveDirectoryIterator::SKIP_DOTS;
        $files = [];

        /** @var UniformResourceLocator $locator */
        $locator = Grav::instance()['locator'];
        if ($locator->isStream($path)) {
            $directory = $locator->getRecursiveIterator($path, $flags);
        } else {
            $directory = new \RecursiveDirectoryIterator($path, $flags);
        }

        $iterator = new \RecursiveIteratorIterator($directory, \RecursiveIteratorIterator::SELF_FIRST);

        foreach ($iterator as $file) {
            $files[] = $file->getPathname() . '?'. $file->getMTime();
        }

        return md5(serialize($files));
    }
598257
public static function isOwner($path)
	{
		$tmp = md5(mt_rand());
		$ssp = ini_get('session.save_path');
		$jtp = JPATH_ROOT . '/tmp';

		// Try to find a writable directory
		$dir = is_writable('/tmp') ? '/tmp' : false;
		$dir = (!$dir && is_writable($ssp)) ? $ssp : false;
		$dir = (!$dir && is_writable($jtp)) ? $jtp : false;

		if ($dir)
		{
			$test = $dir . '/' . $tmp;

			// Create the test file
			$blank = '';
			File::write($test, $blank, false);

			// Test ownership
			$return = (fileowner($test) == fileowner($path));

			// Delete the test file
			File::delete($test);

			return $return;
		}

		return false;
	}
642781
private function fileRelativePath($path)
    {
        $path = $this->fileWebpath($path);
        // @todo This wont work for files not located on the current server...
        $path = str_replace_first(env('APP_URL'), '', $path);
        $path = str_replace(' ', '%20', $path);

        return $path;
    }
1302272
public function realpath($path)
    {
        $path = str_replace('\\', '/', rtrim($path, '/'));
        if ($path[0] != '/' && (strlen($path) < 2 || $path[1] != ':')) {
            $path = getcwd() . '/' . $path;
        }
        $parts = explode('/', $path);
        $path = [];
        foreach ($parts as $part) {
            if ($part == '..') {
                array_pop($path);
            } else if ($part != '.') {
                array_push($path, $part);
            }
        }
        return implode('/', $path);
    }
1372336
public static function getKeyFromPem($path)
    {
        $content = file_get_contents($path);

        $decSerializer = new DerPublicKeySerializer();
        $pemSerializer = new PemPublicKeySerializer($decSerializer);
        $key = $pemSerializer->parse($content);
        $key = $decSerializer->getUncompressedKey($key);

        return hex2bin($key);
    }
601517
private function normalizePath($path)
    {
        $path = str_replace(\DIRECTORY_SEPARATOR, '/', $path);
        if ('/' !== $path[0]) {
            $path = getcwd() . '/' . $path;
        }

        return $path;
    }
822867
public function url($path = '')
    {
        $path = trim($path, '/');
        if ($this->enabled) {
            $hash = ($this->hash) ? trim($this->hash, '/') . '/' : '';
            return $this->cdn . $this->prefix . $hash . $path;
        } else {
            return $this->cdn . $path;
        }

    }
900937
def _get_hashed_path(self, path):
        """"""
        return self._get_path('%s.pkl' % hashlib.md5(path.encode("utf-8")).hexdigest())
421556
private static function setHash($filePath)
    {
        if (stristr(php_uname('s'), 'WIN')) {
            $filePath = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $filePath);
        }

        return md5($filePath);
    }
649695
public function buildRelativePath($path)
    {
        if (is_null($path)) return $path;

        $relativePath = str_replace(array(realpath($this->publicPath), '\\'), array('', '/'), $path);

        // If the asset is not a remote asset then we'll trim the relative path even further to remove
        // any unnecessary leading or trailing slashes. This will leave us with a nice relative path.
        if ( ! starts_with($path, '//') and ! (bool) filter_var($path, FILTER_VALIDATE_URL))
        {
            $relativePath = trim($relativePath, '/');

            // If the given path is the same as the built relative path then the asset appears to be
            // outside of the public directory. If this is the case then we'll use an MD5 hash of
            // the assets path as the relative path to the asset.
            if (trim(str_replace('\\', '/', $path), '/') == trim($relativePath, '/'))
            {
                $path = pathinfo($path);

                $relativePath = md5($path['dirname']).'/'.$path['basename'];
            }
        }

        return $relativePath;
    }
1333361
private function relativizePaths($path)
    {
        if (!$this->basePath) {
            return $path;
        }

        return str_replace($this->basePath . DIRECTORY_SEPARATOR, '', $path);
    }
87953
public function file(string $path, string $md5)
    {
        //==============================================================================
        //      Create Event Object
        $event = new ObjectFileEvent($this->getWebserviceId(), $path, $md5);
        //==============================================================================
        //      Dispatch Event
        /** @var ObjectFileEvent $response */
        $response = $this->getEventDispatcher()->dispatch(ObjectFileEvent::NAME, $event);

        return $response->getContents();
    }
1142063
private function loadDirectory($path)
    {
        $directory = new RecursiveDirectoryIterator($path);
        $iterator = new RecursiveIteratorIterator($directory);
        $files = new RegexIterator($iterator, '/^[^\.](?:(?!\/\.).)+?\.php$/i');

        $fm = $this;

        foreach ($files as $file) {
            require $file->getPathName();
        }
    }
326287
public function sharedGet(string $path) : string
    {
        $contents = '';
        $handle   = @fopen($path, File::READ_BINARY);

        if (false === $handle) {
            return $contents;
        }

        try {
            if (flock($handle, LOCK_SH)) {
                clearstatcache(true, $path);

                $contents = fread($handle, filesize($path) ?: 1);

                flock($handle, LOCK_UN);
            }
        } finally {
            fclose($handle);
        }

        return $contents;
    }
244366
public function makeFolder($path)
    {
        $path = self::validatePath($path);
        $fullPath = $this->getMediaPath($path);

        return $this->getStorageDisk()->makeDirectory($fullPath);
    }
868773
public static function slashTerm($path)
    {
        if (Folder::isSlashTerm($path)) {
            return $path;
        }

        return $path . Folder::correctSlashFor($path);
    }
1055367
protected function cleanPath($path)
    {
        $lastchunk = strrchr($path, DS);
        if (strpos($lastchunk, ':') !== false) {
            $path = str_replace($lastchunk, '', $path);
        }

        return $path;
    }