예제 #1
0
 /**
  * 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);
 }
예제 #2
0
 /**
  * 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);
 }
예제 #3
0
 public function fromInteger($integer)
 {
     $hex = $this->numberConverter->toHex($integer);
     $hex = str_pad($hex, 32, '0', STR_PAD_LEFT);
     return $this->fromString($hex);
 }
예제 #4
0
파일: Uuid.php 프로젝트: rodion-k/uuid
 /**
  * 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());
 }