first commit
This commit is contained in:
45
app/Helpers/AppHelper.php
Executable file
45
app/Helpers/AppHelper.php
Executable file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
use function Hyperf\Config\config;
|
||||
|
||||
class AppHelper
|
||||
{
|
||||
public static function getImageBaseUrl(): string
|
||||
{
|
||||
return config('upload.qiniu.base_url');
|
||||
}
|
||||
|
||||
public static function setImageUrl(string $imageUrl)
|
||||
{
|
||||
$imageUrl = self::extractImagePath($imageUrl);
|
||||
return self::getImageBaseUrl() . $imageUrl;
|
||||
}
|
||||
|
||||
public static function extractImagePath(string $url): string
|
||||
{
|
||||
// 解析URL
|
||||
$parsedUrl = parse_url($url);
|
||||
|
||||
// 获取路径部分
|
||||
$path = $parsedUrl['path'];
|
||||
|
||||
// 去除路径前的 "/"
|
||||
return ltrim($path, '/');
|
||||
}
|
||||
|
||||
public static function generateAid(): string
|
||||
{
|
||||
return strtr(uniqid(more_entropy: true), [
|
||||
'.' => ''
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getYear(string $title)
|
||||
{
|
||||
preg_match('/([0-9]+)/', $title, $y);
|
||||
|
||||
return $y[1] ?? date('Y');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user