Beispiel #1
0
 /**
  * Return a type 5 (SHA-1 hash) uuid
  *
  * @param String $namespace The namespace to use
  * @param String $name The name to use
  * @return String The newly generated UUID
  */
 public static function v5($namespace, $name)
 {
     if (!self::isValidUuid($namespace)) {
         return false;
     }
     Uuid::initialize();
     if (self::$method == self::USE_PECL_MAKE) {
         uuid_make(Uuid::$uobject, UUID_MAKE_V4);
         @uuid_export(Uuid::$uobject, UUID_FMT_STR, &$uuidstring);
         return trim($uuidstring);
     }
     // 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 . $name);
     return sprintf('%08s-%04s-%04x-%04x-%12s', substr($hash, 0, 8), substr($hash, 8, 4), hexdec(substr($hash, 12, 4)) & 0xfff | 0x5000, hexdec(substr($hash, 16, 4)) & 0x3fff | 0x8000, substr($hash, 20, 12));
 }