2FAuth/app/Helpers/Helpers.php

32 lines
882 B
PHP
Raw Normal View History

<?php
namespace App\Helpers;
use Illuminate\Support\Str;
class Helpers
{
/**
* Generate a unique filename
2022-11-22 15:15:52 +01:00
*
* @param string $extension
* @return string The filename
*/
2022-12-09 10:55:11 +01:00
public static function getUniqueFilename(string $extension): string
{
2022-11-22 15:15:52 +01:00
return Str::random(40) . '.' . $extension;
}
2022-11-22 15:15:52 +01:00
/**
* Clean a version number string
*
* @param string|null $release
* @return string|false
*/
2022-12-09 10:55:11 +01:00
public static function cleanVersionNumber(?string $release): string|false
{
2022-12-09 10:52:17 +01:00
// We use the regex for semver detection (see https://semver.org/)
return preg_match('/(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?/', $release, $version) ? $version[0] : false;
}
}