public function write(Table $table, UuidInterface $uuid) { $table->addRows(array(array('encode:', 'STR:', (string) $uuid), array('', 'INT:', (string) $uuid->getInteger()))); if ($uuid->getVariant() == Uuid::RFC_4122) { $table->addRows(array(array('decode:', 'variant:', $this->getFormattedVariant($uuid)), array('', 'version:', $this->getFormattedVersion($uuid)))); $table->addRows($this->getContent($uuid)); } else { $table->addRows(array(array('decode:', 'variant:', 'Not an RFC 4122 UUID'))); } }
/** * Encodes a UUID into a string (LSB first) according to the alphabet * If leftmost (MSB) bits 0, string might be shorter * * @param UuidInterface $uuid * @return string */ public function encode($uuid) { $padLength = $this->encodedLength(strlen($uuid->getBytes())); return $this->numToString($uuid->getInteger(), $padLength); }
/** * Encodes the given UUID to a shorter version. * For example: * - 4e52c919-513e-4562-9248-7dd612c6c1ca becomes fpfyRTmt6XeE9ehEKZ5LwF * - 59a3e9ab-6b99-4936-928a-d8b465dd41e0 becomes BnxtX5wGumMUWXmnbey6xH * * @param UuidInterface $uuid * * @return string * * @throws ArithmeticException */ public function encode(UuidInterface $uuid) { /** @var BigNumber $uuidInteger */ $uuidInteger = $uuid->getInteger(); return $this->numToString($uuidInteger); }