Doctrine\OXM\Id\UuidGenerator::generateV5 PHP 메소드

generateV5() 공개 메소드

Generates a v5 GUID
public generateV5 ( string $namespace, string $salt ) : string
$namespace string The GUID to seed with
$salt string The string to salt this new UUID with
리턴 string
    public function generateV5($namespace, $salt)
    {
        if (!$this->isValid($namespace)) {
            throw new \Exception('Provided $namespace is invalid: ' . $namespace);
        }
        // Get hexadecimal components of namespace
        $nhex = str_replace(array('-', '{', '}'), '', $namespace);
        // Binary Value
        $nstr = '';
        // Convert Namespace UUID to bits
        for ($i = 0; $i < strlen($nhex); $i += 2) {
            $nstr .= chr(hexdec($nhex[$i] . $nhex[$i + 1]));
        }
        // Calculate hash value
        $hash = sha1($nstr . $salt);
        $guid = sprintf('%08s%04s%04x%04x%12s', substr($hash, 0, 8), substr($hash, 8, 4), hexdec(substr($hash, 12, 4)) & 0xfff | 0x3000, hexdec(substr($hash, 16, 4)) & 0x3fff | 0x8000, substr($hash, 20, 12));
        return $guid;
    }