2025-03-12 10:47:34 +08:00

64 lines
1.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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;
}
}