/** * Generates a string of binary data of the specified length * * @param integer $length The number of bytes of random binary data to generate * @return string A binary string */ public function generate($length) { if ($length < self::TIMESTAMP_BYTES || $length < 0) { throw new \InvalidArgumentException('Length must be a positive integer.'); } $hash = ''; if (self::TIMESTAMP_BYTES > 0 && $length > self::TIMESTAMP_BYTES) { $hash = $this->randomGenerator->generate($length - self::TIMESTAMP_BYTES); } $lsbTime = str_pad($this->converter->toHex($this->timestamp()), self::TIMESTAMP_BYTES * 2, '0', STR_PAD_LEFT); return hex2bin(str_pad(bin2hex($hash), $length - self::TIMESTAMP_BYTES, '0') . $lsbTime); }
/** * Generates a string of binary data of the specified length * * @param integer $length The number of bytes of random binary data to generate * @return string A binary string */ public function generate($length) { if ($length < $this->timestampBytes || $length < 0) { throw new \InvalidArgumentException('Length must be a positive integer.'); } $hash = ''; if ($this->timestampBytes > 0 && $length > $this->timestampBytes) { $hash = $this->randomGenerator->generate($length - $this->timestampBytes); } $lsbTime = str_pad($this->converter->toHex($this->timestamp()), $this->timestampBytes * 2, '0', STR_PAD_LEFT); if ($this->timestampBytes > 0 && strlen($lsbTime) > $this->timestampBytes * 2) { $lsbTime = substr($lsbTime, 0 - $this->timestampBytes * 2); } return hex2bin(str_pad(bin2hex($hash), $length - $this->timestampBytes, '0')) . hex2bin($lsbTime); }
public function fromInteger($integer) { $hex = $this->numberConverter->toHex($integer); $hex = str_pad($hex, 32, '0', STR_PAD_LEFT); return $this->fromString($hex); }
/** * Returns the most significant 64 bits of this UUID's 128 bit value. * * @return mixed Converted representation of the unsigned 64-bit integer value */ public function getMostSignificantBits() { return $this->converter->fromHex($this->getMostSignificantBitsHex()); }