function Schema::hashBase64

Same name in other branches
  1. 9 core/modules/pgsql/src/Driver/Database/pgsql/Schema.php \Drupal\pgsql\Driver\Database\pgsql\Schema::hashBase64()
  2. 8.9.x core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php \Drupal\Core\Database\Driver\pgsql\Schema::hashBase64()
  3. 11.x core/modules/pgsql/src/Driver/Database/pgsql/Schema.php \Drupal\pgsql\Driver\Database\pgsql\Schema::hashBase64()

Calculates a base-64 encoded PostgreSQL-safe sha-256 hash.

The hash is modified to according to @link https://www.postgresql.org/docs/current/sql-syntax-lexical.html PostgreSQL Lexical Structure@endlink.

Parameters

$data: String to be hashed.

Return value

string A base-64 encoded sha-256 hash, with + and / replaced with _ and any = padding characters removed.

1 call to Schema::hashBase64()
Schema::ensureIdentifiersLength in core/modules/pgsql/src/Driver/Database/pgsql/Schema.php
Make sure to limit identifiers according to PostgreSQL compiled in length.

File

core/modules/pgsql/src/Driver/Database/pgsql/Schema.php, line 1073

Class

Schema
PostgreSQL implementation of \Drupal\Core\Database\Schema.

Namespace

Drupal\pgsql\Driver\Database\pgsql

Code

protected function hashBase64($data) {
    $hash = base64_encode(hash('sha256', $data, TRUE));
    // Modify the hash so it's safe to use in PostgreSQL identifiers.
    return strtr($hash, [
        '+' => '_',
        '/' => '_',
        '=' => '',
    ]);
}

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