Last active
May 20, 2022 07:01
-
-
Save kaystrobach/7aa08be92373be66efb6a1d36705d1b1 to your computer and use it in GitHub Desktop.
Convert UUIDs into BigInt with ramsey/uuid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// needs picqer/php-barcode-generator | |
$generator = new \Picqer\Barcode\BarcodeGeneratorPNG(); | |
$barcode = $generator->getBarcode($data, $generator::TYPE_CODE_128, 3, 100, [0,0,0]); | |
// ensure the char count is even for CODE_128_C | |
$barcodeData = (strlen($data) % 2) === 0 ? $data : '0' . $data; | |
$generator = new \Picqer\Barcode\BarcodeGeneratorPNG(); | |
$barcode = $generator->getBarcode($barcodeData, $generator::TYPE_CODE_128_C, 3, 100, [0,0,0]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// needs ramsey/uuid | |
class UuidConverterService | |
{ | |
public static function fromUuidToNumberString(string $uuid): string | |
{ | |
$uuidObject = Uuid::fromString($uuid); | |
return $uuidObject->getInteger()->toString(); | |
} | |
public static function fromNumberStringToUuid(string $integer): string | |
{ | |
$uuidObject = Uuid::fromInteger($integer); | |
return $uuidObject->toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment