protected function FileMetadataManager::calculateHash in File metadata manager 8
Same name and namespace in other branches
- 8.2 src/FileMetadataManager.php \Drupal\file_mdm\FileMetadataManager::calculateHash()
Returns an hash for the URI, used internally by the manager.
Parameters
string $uri: The URI to a file.
Return value
string An hash string.
4 calls to FileMetadataManager::calculateHash()
- FileMetadataManager::deleteCachedMetadata in src/
FileMetadataManager.php - Deletes the all the cached metadata for the URI.
- FileMetadataManager::has in src/
FileMetadataManager.php - Determines if the URI is currently in use by the manager.
- FileMetadataManager::release in src/
FileMetadataManager.php - Releases the FileMetadata object for the URI.
- FileMetadataManager::uri in src/
FileMetadataManager.php - Returns a FileMetadata object for the URI, creating it if necessary.
File
- src/
FileMetadataManager.php, line 92
Class
- FileMetadataManager
- A service class to provide file metadata.
Namespace
Drupal\file_mdmCode
protected function calculateHash($uri) {
// Sanitize URI removing duplicate slashes, if any.
// @see http://stackoverflow.com/questions/12494515/remove-unnecessary-slashes-from-path
$uri = preg_replace('/([^:])(\\/{2,})/', '$1/', $uri);
// If URI is invalid and no local file path exists, return NULL.
if (!file_valid_uri($uri) && !$this->fileSystem
->realpath($uri)) {
return NULL;
}
// Return a hash of the URI.
return hash('sha256', $uri);
}