PHP code example of gpslab / base64uid
1. Go to this page and download the library: Download gpslab/base64uid library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once ('vendor/autoload.php' );
gpslab / base64uid example snippets
use GpsLab \Component \Base64UID \Base64UID ;
$uid = Base64UID::generate();
$uid = Base64UID::generate(6 );
$uid = Base64UID::generate(random_int(8 , 10 ));
$charset = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/' ;
$uid = Base64UID::generate(11 , $charset);
$charset = '0123456789abcdef' ;
$uid = Base64UID::generate(11 , $charset);
$generator = new RandomCharGenerator();
$uid = $generator->generate();
$charset = '0123456789abcdef' ;
$generator = new RandomCharGenerator(6 , $charset);
$uid = $generator->generate();
$generator = new RandomBytesGenerator();
$uid = $generator->generate();
$generator = new RandomBytesGenerator(5 );
$uid = $generator->generate();
$binary_generator = new RandomBinaryGenerator(32 );
$encoder = new HexToBase64BitmapEncoder();
$generator = new EncodeBitmapGenerator($binary_generator, $encoder);
$uid = $generator->generate();
$binary_generator = new TimeBinaryGenerator();
$encoder = new HexToBase64BitmapEncoder();
$generator = new EncodeBitmapGenerator($binary_generator, $encoder);
$uid = $generator->generate();
$uid = $generator->generate();
$uid = $generator->generate();
$binary_generator = new FloatingTimeGenerator();
$encoder = new HexToBase64BitmapEncoder();
$generator = new EncodeBitmapGenerator($binary_generator, $encoder);
$uid = $generator->generate();
$uid = $generator->generate();
$uid = $generator->generate();
$generator_id = 0 ;
$binary_generator = new SnowflakeGenerator($generator_id);
$encoder = new HexToBase64BitmapEncoder();
$generator = new EncodeBitmapGenerator($binary_generator, $encoder);
$uid = $generator->generate();
$uid = $generator->generate();
$uid = $generator->generate();
class ArticleId
{
private $id;
public function __construct (string $id)
{
$this ->id = $id;
}
public function id ()
{
return $this ->id;
}
}
interface ArticleRepository
{
public function nextId () ;
}
use GpsLab \Component \Base64UID \Base64UID ;
class ConcreteArticleRepository implements ArticleRepository
{
public function nextId ()
{
return new ArticleId(Base64UID::generate());
}
}
$article = new Article(
$repository->nextId(),
);