From 9b16d7acc06394061d94d3edd63e9623def83dfd Mon Sep 17 00:00:00 2001 From: Marijn Vandevoorde Date: Thu, 16 May 2024 14:00:39 +0200 Subject: [PATCH] Replaces short-id by nano-id --- composer.json | 2 +- module/Core/functions/functions.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 6b075d2b..6cd3e92d 100644 --- a/composer.json +++ b/composer.json @@ -26,6 +26,7 @@ "friendsofphp/proxy-manager-lts": "^1.0", "geoip2/geoip2": "^3.0", "guzzlehttp/guzzle": "^7.5", + "hidehalo/nanoid-php": "^1.1", "jaybizzle/crawler-detect": "^1.2.116", "laminas/laminas-config": "^3.8", "laminas/laminas-config-aggregator": "^1.15", @@ -40,7 +41,6 @@ "mlocati/ip-lib": "^1.18", "mobiledetect/mobiledetectlib": "^4.8", "pagerfanta/core": "^3.8", - "pugx/shortid-php": "^1.1", "ramsey/uuid": "^4.7", "shlinkio/doctrine-specification": "^2.1.1", "shlinkio/shlink-common": "^6.1", diff --git a/module/Core/functions/functions.php b/module/Core/functions/functions.php index 2e238e99..8a11209d 100644 --- a/module/Core/functions/functions.php +++ b/module/Core/functions/functions.php @@ -9,11 +9,11 @@ use Cake\Chronos\Chronos; use DateTimeInterface; use Doctrine\ORM\Mapping\Builder\FieldBuilder; use GuzzleHttp\Psr7\Query; +use Hidehalo\Nanoid\Client; use Jaybizzle\CrawlerDetect\CrawlerDetect; use Laminas\Filter\Word\CamelCaseToSeparator; use Laminas\Filter\Word\CamelCaseToUnderscore; use Laminas\InputFilter\InputFilter; -use PUGX\Shortid\Factory as ShortIdFactory; use Shlinkio\Shlink\Common\Util\DateRange; use Shlinkio\Shlink\Core\ShortUrl\Model\ShortUrlMode; @@ -39,13 +39,13 @@ function generateRandomShortCode(int $length, ShortUrlMode $mode = ShortUrlMode: { static $shortIdFactory; if ($shortIdFactory === null) { - $shortIdFactory = new ShortIdFactory(); + $shortIdFactory = new Client(); } $alphabet = $mode === ShortUrlMode::STRICT ? '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' : '0123456789abcdefghijklmnopqrstuvwxyz'; - return $shortIdFactory->generate($length, $alphabet)->serialize(); + return $shortIdFactory->formattedId($alphabet, $length); } function parseDateFromQuery(array $query, string $dateName): ?Chronos