You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.8 KiB
64 lines
1.8 KiB
9 months ago
|
<?php
|
||
|
// +----------------------------------------------------------------------
|
||
|
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
||
|
// +----------------------------------------------------------------------
|
||
|
// | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
|
||
|
// +----------------------------------------------------------------------
|
||
|
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
||
|
// +----------------------------------------------------------------------
|
||
|
// | Author: CRMEB Team <admin@crmeb.com>
|
||
|
// +----------------------------------------------------------------------
|
||
|
|
||
|
namespace crmeb\utils;
|
||
|
|
||
|
/**
|
||
|
* 字符串操作帮助类
|
||
|
* Class Str
|
||
|
* @package crmeb\utils
|
||
|
*/
|
||
|
class Str
|
||
|
{
|
||
|
/**
|
||
|
* @param $action
|
||
|
* @param $controller
|
||
|
* @param $module
|
||
|
* @param $route
|
||
|
* @return string
|
||
|
*/
|
||
|
public static function getAuthName(string $action, string $controller, string $module, $route)
|
||
|
{
|
||
|
return strtolower($module . '/' . $controller . '/' . $action . '/' . self::paramStr($route));
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @param $params
|
||
|
* @return string
|
||
|
*/
|
||
|
public static function paramStr($params)
|
||
|
{
|
||
|
if (!is_array($params)) $params = json_decode($params, true) ?: [];
|
||
|
$p = [];
|
||
|
foreach ($params as $key => $param) {
|
||
|
$p[] = $key;
|
||
|
$p[] = $param;
|
||
|
}
|
||
|
return implode('/', $p);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 截取中文指定字节
|
||
|
* @param string $str
|
||
|
* @param int $utf8len
|
||
|
* @param string $chaet
|
||
|
* @param string $file
|
||
|
* @return string
|
||
|
*/
|
||
|
public static function substrUTf8($str, $utf8len = 100, $chaet = 'UTF-8', $file = '....')
|
||
|
{
|
||
|
if (mb_strlen($str, $chaet) > $utf8len) {
|
||
|
$str = mb_substr($str, 0, $utf8len, $chaet) . $file;
|
||
|
}
|
||
|
return $str;
|
||
|
}
|
||
|
}
|