public function generate($node = null, $clockSeq = null) { $node = $this->getValidNode($node); if ($clockSeq === null) { // Not using "stable storage"; see RFC 4122, Section 4.2.1.1 $clockSeq = mt_rand(0, 1 << 14); } // Create a 60-bit time value as a count of 100-nanosecond intervals // since 00:00:00.00, 15 October 1582 $timeOfDay = $this->timeProvider->currentTime(); $uuidTime = $this->timeConverter->calculateTime($timeOfDay['sec'], $timeOfDay['usec']); $timeHi = BinaryUtils::applyVersion($uuidTime['hi'], 1); $clockSeqHi = BinaryUtils::applyVariant($clockSeq >> 8); $hex = vsprintf('%08s%04s%04s%02s%02s%012s', array($uuidTime['low'], $uuidTime['mid'], sprintf('%04x', $timeHi), sprintf('%02x', $clockSeqHi), sprintf('%02x', $clockSeq & 0xff), $node)); return hex2bin($hex); }
/** * Returns a `Uuid` created from `$hash` with the version field set to `$version` * and the variant field set for RFC 4122 * * @param string $hash The hash to use when creating the UUID * @param int $version The UUID version to set for this hash (1, 3, 4, or 5) * @return UuidInterface */ protected function uuidFromHashedName($hash, $version) { $timeHi = BinaryUtils::applyVersion(substr($hash, 12, 4), $version); $clockSeqHi = BinaryUtils::applyVariant(hexdec(substr($hash, 16, 2))); $fields = array('time_low' => substr($hash, 0, 8), 'time_mid' => substr($hash, 8, 4), 'time_hi_and_version' => sprintf('%04x', $timeHi), 'clock_seq_hi_and_reserved' => sprintf('%02x', $clockSeqHi), 'clock_seq_low' => substr($hash, 18, 2), 'node' => substr($hash, 20, 12)); return $this->uuid($fields); }