value = $value; } /** * Generate a random UUID v4. * * @since 0.1.0 */ public static function generate(): self { $bytes = random_bytes( 16 ); $bytes[6] = chr( ( ord( $bytes[6] ) & 0x0f ) | 0x40 ); $bytes[8] = chr( ( ord( $bytes[8] ) & 0x3f ) | 0x80 ); $hex = bin2hex( $bytes ); return new self( sprintf( '%s-%s-%s-%s-%s', substr( $hex, 0, 8 ), substr( $hex, 8, 4 ), substr( $hex, 12, 4 ), substr( $hex, 16, 4 ), substr( $hex, 20, 12 ) ) ); } /** * Canonical string form. * * @since 0.1.0 */ public function to_string(): string { return $this->value; } /** * Equals. * * @param self $other Parameter. * @since 0.1.0 */ public function equals( self $other ): bool { return $this->value === $other->value; } /** * String cast. * * @since 0.1.0 */ public function __toString(): string { return $this->value; } }