mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-28 17:08:58 +03:00
19 lines
445 B
PHP
19 lines
445 B
PHP
|
<?php
|
||
|
|
||
|
declare(strict_types=1);
|
||
|
|
||
|
namespace Shlinkio\Shlink\Core;
|
||
|
|
||
|
use PUGX\Shortid\Factory as ShortIdFactory;
|
||
|
|
||
|
function generateRandomShortCode(int $length = 5): string
|
||
|
{
|
||
|
static $shortIdFactory;
|
||
|
if ($shortIdFactory === null) {
|
||
|
$shortIdFactory = new ShortIdFactory();
|
||
|
}
|
||
|
|
||
|
$alphabet = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||
|
return $shortIdFactory->generate($length, $alphabet)->serialize();
|
||
|
}
|