public static function generate($ver = 4, $node = null, $clockSeq = null, $ns = null, $name = null)
 {
     $uuid = null;
     /* Create a new UUID based on provided data. */
     switch ((int) $ver) {
         case 1:
             $uuid = Uuid::uuid1($node, $clockSeq);
             break;
         case 2:
             // Version 2 is not supported
             throw new \RuntimeException('UUID version 2 is unsupported.');
         case 3:
             $uuid = Uuid::uuid3($ns, $name);
             break;
         case 4:
             $uuid = Uuid::uuid4();
             break;
         case 5:
             $uuid = Uuid::uuid5($ns, $name);
             break;
         default:
             throw new \RuntimeException('Selected UUID version is invalid or unsupported.');
     }
     if (function_exists('gmp_strval')) {
         return gmp_strval(gmp_init($uuid->getHex(), 16), 62);
     }
     return Base62::encode((string) $uuid->getInteger());
 }
Пример #2
0
 /**
  * Creates the requested UUID
  *
  * @param int $version
  * @param string $namespace
  * @param string $name
  * @return Uuid
  */
 protected function createUuid($version, $namespace = null, $name = null)
 {
     switch ((int) $version) {
         case 1:
             $uuid = Uuid::uuid1();
             break;
         case 4:
             $uuid = Uuid::uuid4();
             break;
         case 3:
         case 5:
             $ns = $this->validateNamespace($namespace);
             if (empty($name)) {
                 throw new Exception('The name argument is required for version 3 or 5 UUIDs');
             }
             if ($version == 3) {
                 $uuid = Uuid::uuid3($ns, $name);
             } else {
                 $uuid = Uuid::uuid5($ns, $name);
             }
             break;
         default:
             throw new Exception('Invalid UUID version. Supported are version "1", "3", "4", and "5".');
     }
     return $uuid;
 }
Пример #3
0
 /**
  * 基于名字的MD5散列值
  * [!!] 同一命名空间的同一名字会生成相同的uuid
  *
  * @param  VendorUUID|string $namespace
  * @param  string            $name
  * @return string
  */
 public static function v3($namespace = VendorUUID::NAMESPACE_DNS, $name = 'php.net')
 {
     try {
         $uuid3 = VendorUUID::uuid3($namespace, $name);
         return $uuid3->toString();
     } catch (UnsatisfiedDependencyException $e) {
         return false;
     }
 }
Пример #4
0
 public static function uuid3($ns, $name)
 {
     return BaseUuid::uuid3($ns, $name);
 }
Пример #5
0
 /**
  * generate name base and hashed md5 uuid
  *
  * @param string $namespace base name
  * @return string
  */
 protected function createIdVersion3($namespace)
 {
     return Uuid::uuid3(Uuid::NAMESPACE_DNS, $namespace)->toString();
 }
Пример #6
0
/**
 * Generates a unique UUID string.
 *
 * @return string
 */
function uuid()
{
    return Uuid::uuid3(Uuid::NAMESPACE_DNS, str_random())->toString();
}
Пример #7
0
 public static function uuid3($ns, $name)
 {
     return self::bin(BaseUuid::uuid3($ns, $name));
 }
Пример #8
0
 /**
  * Generate a version 3 (name-based and hashed with MD5) UUID object.
  *
  * @param string $ns
  * @param string $name
  *
  * @return string
  */
 function uuid3($ns, $name)
 {
     $uuid = Uuid::uuid3($ns, $name);
     return $uuid->toString();
 }