function DatabaseLockBackend::normalizeName

Same name in other branches
  1. 9 core/lib/Drupal/Core/Lock/DatabaseLockBackend.php \Drupal\Core\Lock\DatabaseLockBackend::normalizeName()
  2. 8.9.x core/lib/Drupal/Core/Lock/DatabaseLockBackend.php \Drupal\Core\Lock\DatabaseLockBackend::normalizeName()
  3. 11.x 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.

3 calls to DatabaseLockBackend::normalizeName()
DatabaseLockBackend::acquire in core/lib/Drupal/Core/Lock/DatabaseLockBackend.php
Acquires a lock.
DatabaseLockBackend::lockMayBeAvailable in core/lib/Drupal/Core/Lock/DatabaseLockBackend.php
Checks if a lock is available for acquiring.
DatabaseLockBackend::release in core/lib/Drupal/Core/Lock/DatabaseLockBackend.php
Releases the given lock.

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.