GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
UUID Class Reference

Public Member Functions

 __construct ($part1=0, $part2=0, $part3=0, $part4=0, $version=null)
 
 getVersion ()
 
 equals (UUID $uuid)
 
 toBinary ()
 
 toString ()
 
 __toString ()
 
 getPart (int $partNumber)
 
 getParts ()
 

Static Public Member Functions

static fromString ($uuid, $version=null)
 
static fromBinary ($uuid, $version=null)
 
static fromData (... $data)
 
static fromRandom ()
 

Constructor & Destructor Documentation

◆ __construct()

__construct (   $part1 = 0,
  $part2 = 0,
  $part3 = 0,
  $part4 = 0,
  $version = null 
)

UUID constructor.

Parameters
int$part1
int$part2
int$part3
int$part4
null$version
38  {
39  $this->parts[0] = (int) $part1;
40  $this->parts[1] = (int) $part2;
41  $this->parts[2] = (int) $part3;
42  $this->parts[3] = (int) $part4;
43 
44  $this->version = $version === null ? ($this->parts[1] & 0xf000) >> 12 : (int) $version;
45  }

Member Function Documentation

◆ __toString()

__toString ( )
Returns
string
134  {
135  return $this->toString();
136  }

◆ equals()

equals ( UUID  $uuid)
Parameters
UUID$uuid
Returns
bool
59  {
60  return $uuid->parts[0] === $this->parts[0] and $uuid->parts[1] === $this->parts[1] and $uuid->parts[2] === $this->parts[2] and $uuid->parts[3] === $this->parts[3];
61  }

◆ fromBinary()

static fromBinary (   $uuid,
  $version = null 
)
static

Creates an UUID from a binary representation

Parameters
string$uuid
int$version
Returns
UUID
83  {
84  if(strlen($uuid) !== 16){
85  throw new \InvalidArgumentException("Must have exactly 16 bytes");
86  }
87 
88  return new UUID(Binary::readInt(substr($uuid, 0, 4)), Binary::readInt(substr($uuid, 4, 4)), Binary::readInt(substr($uuid, 8, 4)), Binary::readInt(substr($uuid, 12, 4)), $version);
89  }

◆ fromData()

static fromData (   $data)
static

Creates an UUIDv3 from binary data or list of binary data

Parameters
array|string...$data
Returns
UUID
98  {
99  $hash = hash("md5", implode($data), true);
100 
101  return self::fromBinary($hash, 3);
102  }

◆ fromRandom()

static fromRandom ( )
static
Returns
UUID
107  {
108  return self::fromData(Binary::writeInt(time()), Binary::writeShort(getmypid()), Binary::writeShort(getmyuid()), Binary::writeInt(mt_rand(-0x7fffffff, 0x7fffffff)), Binary::writeInt(mt_rand(-0x7fffffff, 0x7fffffff)));
109  }

◆ fromString()

static fromString (   $uuid,
  $version = null 
)
static

Creates an UUID from an hexadecimal representation

Parameters
string$uuid
int$version
Returns
UUID
71  {
72  return self::fromBinary(hex2bin(str_replace("-", "", trim($uuid))), $version);
73  }

◆ getPart()

getPart ( int  $partNumber)
Parameters
int$partNumber
Returns
mixed
143  {
144  if($partNumber < 0 or $partNumber > 3){
145  throw new \InvalidArgumentException("Invalid UUID part index $partNumber");
146  }
147  return $this->parts[$partNumber];
148  }

◆ getParts()

getParts ( )
Returns
array
153  : array{
154  return $this->parts;
155  }

◆ getVersion()

getVersion ( )
Returns
int|null
50  {
51  return $this->version;
52  }

◆ toBinary()

toBinary ( )
Returns
string
114  {
115  return Binary::writeInt($this->parts[0]) . Binary::writeInt($this->parts[1]) . Binary::writeInt($this->parts[2]) . Binary::writeInt($this->parts[3]);
116  }

◆ toString()

toString ( )
Returns
string
121  {
122  $hex = bin2hex(self::toBinary());
123 
124  //xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx 8-4-4-12
125  if($this->version !== null){
126  return substr($hex, 0, 8) . "-" . substr($hex, 8, 4) . "-" . hexdec($this->version) . substr($hex, 13, 3) . "-8" . substr($hex, 17, 3) . "-" . substr($hex, 20, 12);
127  }
128  return substr($hex, 0, 8) . "-" . substr($hex, 8, 4) . "-" . substr($hex, 12, 4) . "-" . substr($hex, 16, 4) . "-" . substr($hex, 20, 12);
129  }

The documentation for this class was generated from the following file: