You are here

protected function DatabaseLockBackend::normalizeName in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Lock/DatabaseLockBackend.php \Drupal\Core\Lock\DatabaseLockBackend::normalizeName()
  2. 9 core/lib/Drupal/Core/Lock/DatabaseLockBackend.php \Drupal\Core\Lock\DatabaseLockBackend::normalizeName()

Normalizes a lock name in order to comply with database limitations.

Parameters

string $name: The passed in lock name.

Return value

string An ASCII-encoded lock name that is at most 255 characters long.

File

core/lib/Drupal/Core/Lock/DatabaseLockBackend.php, line 221

Class

DatabaseLockBackend
Defines the database lock backend. This is the default backend in Drupal.

Namespace

Drupal\Core\Lock

Code

protected function normalizeName($name) {

  // Nothing to do if the name is a US ASCII string of 255 characters or less.
  $name_is_ascii = mb_check_encoding($name, 'ASCII');
  if (strlen($name) <= 255 && $name_is_ascii) {
    return $name;
  }

  // Return a string that uses as much as possible of the original name with
  // the hash appended.
  $hash = Crypt::hashBase64($name);
  if (!$name_is_ascii) {
    return $hash;
  }
  return substr($name, 0, 255 - strlen($hash)) . $hash;
}