Core\Uuid
A UUID, which is a 128-bit identifier. v4 and v7 create a new one. parse reads one from its text, such as f9168c5e-ceb2-4faa-b6bf-329bf39fa1e4, and fromBytes reads one from its sixteen bytes. toString and toBytes give the text and the bytes back.
A Uuid is an opaque 128-bit value, not a string: v4 draws a random one, v7 a time-ordered one whose leading bits are a millisecond timestamp — the right database key and the wrong public identifier, since it tells the reader when the row was made. parse reads only the canonical hyphenated 8-4-4-4-12 form, in either letter case, and refuses the unhyphenated, braced and urn:uuid: spellings; asking whether text is a UUID is tryParse($s) != null. toString and echo give the text back, always in lower case. format returns the same text. It is the method of the Parses interface that Core\Router::url and Core\Uri::buildQuery call to write a UUID into a link. Two Uuid objects compare by identity under ==, so two values are compared through their text.
<?nvsvar $id = Core\Uuid::v4();echo Core\Str::length($id->toString()), "\n";echo Core\Str::slice($id->toString(), 14, 1), "\n";echo Core\Str::slice(Core\Uuid::v7()->toString(), 14, 1), "\n";
var $known = Core\Uuid::parse('123E4567-E89B-12D3-A456-426614174000');echo $known, "\n";echo Core\Uuid::tryParse('not-a-uuid') == null ? 'invalid' : 'valid', "\n";echo Core\Uuid::tryParse('123e4567-e89b-12d3-a456-426614174000') != null ? 'valid' : 'invalid', "\n";
var $again = Core\Uuid::parse('123e4567-e89b-12d3-a456-426614174000');echo $known == $again ? 'same object' : 'different objects', "\n";echo $known->toString() == $again->toString() ? 'same value' : 'different values', "\n";
try { Core\Uuid::parse('{123e4567-e89b-12d3-a456-426614174000}');} catch (RuntimeError $bad) { echo "braces refused\n";}3647123e4567-e89b-12d3-a456-426614174000invalidvaliddifferent objectssame valuebraces refusedReturned by
You get a Core\Uuid from these methods:
Members
8 members.
