/** * Generate ID * @return String */ public function generateId($version = 4, $includeDash = false) { try { switch ($version) { case 1: $uuid = Uuid::uuid1(); break; case 3: $uuid = Uuid::uuid3(Uuid::NAMESPACE_DNS, php_uname('n')); break; case 5: $uuid = Uuid::uuid5(Uuid::NAMESPACE_DNS, php_uname('n')); break; default: $uuid = Uuid::uuid4(); break; } return $includeDash ? $uuid->toString() : str_replace('-', '', $uuid->toString()); } catch (UnsatisfiedDependencyException $e) { // Some dependency was not met. Either the method cannot be called on a // 32-bit system, or it can, but it relies on Moontoast\Math to be present. echo 'Caught exception: ' . $e->getMessage() . "\n"; exit; } }
/** * @param $string * * @return string * * @throws UUIDGeneratorException */ public function generateFromString($string) { try { return Uuid::uuid3(Uuid::NAMESPACE_OID, $string)->toString(); } catch (UnsatisfiedDependencyException $e) { throw new UUIDGeneratorException($e->getMessage()); } }
protected static function boot() { parent::boot(); self::creating(function ($registro) { $uuid = Uuid::uuid3(Uuid::NAMESPACE_DNS, $registro->title_oaca); // name-based uuid $registro->id = $uuid->toString(); return true; }); }
/** * @see \Ramsey\Uuid\Uuid::uuid3() * * @param string $ns * @param string $name * @return \Ramsey\Uuid\UuidInterface */ public function uuid3($ns, $name) { return \Ramsey\Uuid\Uuid::uuid3($ns, $name); }
/** * UUID v3 generator. * * @since 150424 Initial release. * * @param string $namespace Namespace. * @param string $identifier Identifier. * @param bool $optimize Optimize? * * @return string Version 3 UUID (32 bytes optimized). * Or 36 bytes unoptimized; i.e., w/ dashes. * * @internal {@link v5()} is a suggested alternative, as this version uses MD5. */ public function v3(string $namespace, string $identifier, bool $optimize = true) : string { switch ($namespace) { case 'dns': $namespace = UuidGen::NAMESPACE_DNS; break; // Stop here. // Stop here. case 'url': $namespace = UuidGen::NAMESPACE_URL; break; // Stop here. // Stop here. case 'oid': $namespace = UuidGen::NAMESPACE_OID; break; // Stop here. // Stop here. case 'x500': $namespace = UuidGen::NAMESPACE_X500; break; // Stop here. // Stop here. default: $this->c::issue('Invalid namespace.'); } $uuid = UuidGen::uuid3($namespace, $identifier)->toString(); return $optimize ? str_replace('-', '', $uuid) : $uuid; }
function uuid3($ns, $name) { $uuid = Uuid::uuid3($ns, $name); return $uuid->toString(); }
/** * @param string $namespace * @param string $name * * @return $this */ public function generateUuid3($namespace, $name) { $this->uuid = Uuid::uuid3($namespace, $name); return $this; }
/** * Generate a uuid for the site based on it's port. * * @param $site * * @return string */ protected function generateUuid($site) { $uuid3 = Uuid::uuid3(Uuid::NAMESPACE_DNS, $site['port']); $uuid = $uuid3->toString(); return $uuid; }
public static function uuid3($ns, $name) { return self::fromRamseyUuid(parent::uuid3($ns, $name)); }
public static function p2uuid3($subDomain = self::SUBDOMAIN_UUID) { return Uuid::uuid3(Uuid::uuid1(), self::fullReverseDomain($subDomain)); }
public function uuidProvider() { return array(array(Uuid::uuid1()), array(Uuid::uuid3(Uuid::NAMESPACE_DNS, 'php.net')), array(Uuid::uuid4()), array(Uuid::uuid5(Uuid::NAMESPACE_DNS, 'php.net')), array(Uuid::fromString(self::UUID_SAMPLE))); }
/** * 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; }
/** * Generate a uuid for the site based on it's port. * * @param $unique * * @return string */ public function generateUuid($unique) { $uuid3 = Uuid::uuid3(Uuid::NAMESPACE_DNS, $unique); $uuid = $uuid3->toString(); return $uuid; }
public function testShouldAcceptUuid3() { $uuid = new Uuid(BaseUuid::uuid3(BaseUuid::NAMESPACE_DNS, 'user')); $this->assertInstanceOf('App\\Domain\\Identity\\Uuid', $uuid); }