◆ __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 | |
39 $this->parts[0] = (int) $part1;
40 $this->parts[1] = (int) $part2;
41 $this->parts[2] = (int) $part3;
42 $this->parts[3] = (int) $part4;
44 $this->version = $version === null ? ($this->parts[1] & 0xf000) >> 12 : (
int) $version;
◆ __toString()
◆ equals()
- Parameters
-
- Returns
- bool
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];
◆ fromBinary()
static fromBinary |
( |
|
$uuid, |
|
|
|
$version = null |
|
) |
| |
|
static |
Creates an UUID from a binary representation
- Parameters
-
- Returns
- UUID
84 if(strlen($uuid) !== 16){
85 throw new \InvalidArgumentException(
"Must have exactly 16 bytes");
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);
◆ fromData()
Creates an UUIDv3 from binary data or list of binary data
- Parameters
-
- Returns
- UUID
99 $hash = hash(
"md5", implode($data),
true);
101 return self::fromBinary($hash, 3);
◆ fromRandom()
◆ fromString()
static fromString |
( |
|
$uuid, |
|
|
|
$version = null |
|
) |
| |
|
static |
Creates an UUID from an hexadecimal representation
- Parameters
-
- Returns
- UUID
72 return self::fromBinary(hex2bin(str_replace(
"-",
"", trim($uuid))), $version);
◆ getPart()
getPart |
( |
int |
$partNumber | ) |
|
- Parameters
-
- Returns
- mixed
144 if($partNumber < 0 or $partNumber > 3){
145 throw new \InvalidArgumentException(
"Invalid UUID part index $partNumber");
147 return $this->parts[$partNumber];
◆ getParts()
◆ getVersion()
- Returns
- int|null
51 return $this->version;
◆ toBinary()
◆ toString()
- Returns
- string
122 $hex = bin2hex(self::toBinary());
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);
128 return substr($hex, 0, 8) .
"-" . substr($hex, 8, 4) .
"-" . substr($hex, 12, 4) .
"-" . substr($hex, 16, 4) .
"-" . substr($hex, 20, 12);
The documentation for this class was generated from the following file:
- src/pocketmine/utils/UUID.php