50 lines
1.1 KiB
PHP
50 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace common\services;
|
|
|
|
class UtilsService
|
|
{
|
|
|
|
public $urlList = [
|
|
'avatar',
|
|
'logo',
|
|
'url',
|
|
'image_url',
|
|
];
|
|
|
|
/**
|
|
* @var mixed 单例实例,确保该类只有一个全局实例
|
|
*/
|
|
private static mixed $_instance;
|
|
|
|
/**
|
|
* 获取实例
|
|
* @return null|static
|
|
*/
|
|
public static function getInstance()
|
|
{
|
|
$name = get_called_class();
|
|
if (!isset(self::$_instance[$name])) {
|
|
self::$_instance[$name] = new static();
|
|
}
|
|
|
|
return self::$_instance[$name];
|
|
}
|
|
|
|
/**
|
|
* 截取oss链接
|
|
* @param $data
|
|
* @return mixed
|
|
*/
|
|
public function truncatedOss($data)
|
|
{
|
|
foreach ($data as $key => &$value) {
|
|
if (in_array($key, $this->urlList)) {
|
|
$value = str_replace('http://xiaokang88.oss-cn-hangzhou.aliyuncs.com/', '', $value);
|
|
$value = str_replace('https://xiaokang88.oss-cn-hangzhou.aliyuncs.com/', '', $value);
|
|
$value = explode('?', $value)[0];
|
|
}
|
|
}
|
|
return $data;
|
|
}
|
|
} |