public static function Composer::generateHash in Markdown 8.2
Generates a base-64 encoded, SHA-256 hash from the contents of a directory.
Original code, modified for use with Drupal Markdown.
@internal
Parameters
string $directory: The directory to hash.
Return value
string|false The hash for the provided $directory; FALSE on error.
Deprecated
in markdown:8.x-2.0 and is removed from markdown:4.0.0. No replacement.
See also
https://jonlabelle.com/snippets/view/php/generate-md5-hash-for-directory
https://www.drupal.org/project/markdown/issues/3200476
2 calls to Composer::generateHash()
- Composer::getVersionFromClass in src/
Util/ Composer.php - Retrieves the version based on a provided class name.
- MarkdownCommands::versionHash in src/
Commands/ MarkdownCommands.php - Run the markdown:version-hash hook.
File
- src/
Util/ Composer.php, line 71
Class
- Composer
- Helper class used to deal with composer.
Namespace
Drupal\markdown\UtilCode
public static function generateHash($directory) {
if (!$directory || !($directory = realpath($directory)) || !is_dir($directory)) {
return FALSE;
}
$hashes = [];
$dir = dir($directory);
while (FALSE !== ($file = $dir
->read())) {
if (preg_match(static::VERSION_HASH_IGNORE_REGEX, $file)) {
continue;
}
if (is_dir("{$directory}/{$file}")) {
$hashes[$file] = static::generateHash("{$directory}/{$file}");
}
else {
$hashes[$file] = sha1_file("{$directory}/{$file}");
}
}
$dir
->close();
return Crypt::hashBase64(serialize($hashes));
}