Skip to content

Instantly share code, notes, and snippets.

@niladam
Forked from kaystrobach/CreateBarCode.php
Created May 20, 2022 07:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niladam/1c235038465106e9cd8cb796d430bcca to your computer and use it in GitHub Desktop.
Save niladam/1c235038465106e9cd8cb796d430bcca to your computer and use it in GitHub Desktop.
Convert UUIDs into BigInt with ramsey/uuid
<?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]);
<?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