private function SpiController::hashPath in Acquia Connector 8
Same name and namespace in other branches
- 8.2 src/Controller/SpiController.php \Drupal\acquia_connector\Controller\SpiController::hashPath()
- 3.x src/Controller/SpiController.php \Drupal\acquia_connector\Controller\SpiController::hashPath()
Calculate the sha1 hash for a path.
Parameters
string $path: The name of the file or a directory.
Return value
string base64 encoded sha1 hash. 'hash' is an empty string for directories.
File
- src/
Controller/ SpiController.php, line 761
Class
- SpiController
- SPI Controller class.
Namespace
Drupal\acquia_connector\ControllerCode
private function hashPath($path = '') {
$hash = '';
if (file_exists($path)) {
if (!is_dir($path)) {
$string = file_get_contents($path);
// Remove trailing whitespace.
$string = rtrim($string);
// Replace all line endings and CVS/svn Id tags.
$string = preg_replace('/\\$Id[^;<>{}\\(\\)\\$]*\\$/', 'x$' . 'Id$', $string);
$string = preg_replace('/\\r\\n|\\n|\\r/', ' ', $string);
$hash = base64_encode(pack("H*", sha1($string)));
}
}
return $hash;
}