mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-12 01:54:41 +08:00
Extracted some private functions ase helper global functions
This commit is contained in:
@@ -4,6 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Core;
|
||||
|
||||
use Cake\Chronos\Chronos;
|
||||
use DateTimeInterface;
|
||||
use PUGX\Shortid\Factory as ShortIdFactory;
|
||||
|
||||
function generateRandomShortCode(int $length = 5): string
|
||||
@@ -16,3 +18,24 @@ function generateRandomShortCode(int $length = 5): string
|
||||
$alphabet = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
return $shortIdFactory->generate($length, $alphabet)->serialize();
|
||||
}
|
||||
|
||||
function parseDateFromQuery(array $query, string $dateName): ?Chronos
|
||||
{
|
||||
return ! isset($query[$dateName]) || empty($query[$dateName]) ? null : Chronos::parse($query[$dateName]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|DateTimeInterface|Chronos|null $date
|
||||
*/
|
||||
function parseDateField($date): ?Chronos
|
||||
{
|
||||
if ($date === null || $date instanceof Chronos) {
|
||||
return $date;
|
||||
}
|
||||
|
||||
if ($date instanceof DateTimeInterface) {
|
||||
return Chronos::instance($date);
|
||||
}
|
||||
|
||||
return Chronos::parse($date);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user