改名
This commit is contained in:
@@ -24,7 +24,7 @@ class ArrayAccess
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function toArray($data)
|
||||
public static function toArray($data): array
|
||||
{
|
||||
if (!is_object($data) && !is_array($data)) {
|
||||
return $data;
|
||||
@@ -49,10 +49,10 @@ class ArrayAccess
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return array|mixed
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function objToArray($data)
|
||||
public static function objToArray($data): array
|
||||
{
|
||||
if (!is_object($data)) {
|
||||
return $data;
|
||||
@@ -77,7 +77,7 @@ class ArrayAccess
|
||||
* @param array $newArray
|
||||
* @return array
|
||||
*/
|
||||
public static function merge(array $oldArray, array $newArray)
|
||||
public static function merge(array $oldArray, array $newArray): array
|
||||
{
|
||||
if (empty($oldArray)) {
|
||||
return $newArray;
|
||||
|
||||
@@ -9,6 +9,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace Snowflake\Core;
|
||||
|
||||
use JetBrains\PhpStorm\Pure;
|
||||
|
||||
/**
|
||||
* Class DateFormat
|
||||
* @package Snowflake\Snowflake\Core
|
||||
@@ -20,7 +22,7 @@ class DateFormat
|
||||
* @param $time
|
||||
* @return bool|false|int|string
|
||||
*/
|
||||
private static function check($time)
|
||||
private static function check($time): bool|int|string
|
||||
{
|
||||
if ($time === null) {
|
||||
$time = time();
|
||||
@@ -46,7 +48,7 @@ class DateFormat
|
||||
*
|
||||
* 获取指定日期当周第一天的时间
|
||||
*/
|
||||
public static function getWeekCurrentDay($time = null)
|
||||
public static function getWeekCurrentDay($time = null): bool|int
|
||||
{
|
||||
if (!($time = static::check($time))) {
|
||||
return false;
|
||||
@@ -64,7 +66,7 @@ class DateFormat
|
||||
*
|
||||
* 获取指定日期当月第一天的时间
|
||||
*/
|
||||
public static function getMonthCurrentDay($time = null)
|
||||
public static function getMonthCurrentDay($time = null): bool|int
|
||||
{
|
||||
if (!($time = static::check($time))) {
|
||||
return false;
|
||||
@@ -75,10 +77,10 @@ class DateFormat
|
||||
|
||||
/**
|
||||
* @param $time
|
||||
* @return bool|false|int|string
|
||||
* @return bool|int|string 指定的月份有几天
|
||||
* 指定的月份有几天
|
||||
*/
|
||||
public static function getMonthTotalDay($time)
|
||||
public static function getMonthTotalDay($time): bool|int|string
|
||||
{
|
||||
if (!($time = static::check($time))) {
|
||||
return false;
|
||||
@@ -94,7 +96,7 @@ class DateFormat
|
||||
* @param null $endTime
|
||||
* @return string
|
||||
*/
|
||||
public static function mtime($startTime, $endTime = null)
|
||||
#[Pure] public static function mtime($startTime, $endTime = null)
|
||||
{
|
||||
if ($endTime === null) {
|
||||
$endTime = microtime(true);
|
||||
|
||||
+4
-4
@@ -30,10 +30,10 @@ class Dtl extends Component
|
||||
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function toArray()
|
||||
public function toArray(): array
|
||||
{
|
||||
if (!is_array($this->params)) {
|
||||
return ArrayAccess::toArray($this->params);
|
||||
@@ -44,10 +44,10 @@ class Dtl extends Component
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @return mixed|null
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
public function get($name)
|
||||
public function get($name): mixed
|
||||
{
|
||||
$array = $this->toArray();
|
||||
if (!isset($array[$name])) {
|
||||
|
||||
+18
-11
@@ -5,6 +5,9 @@ declare(strict_types=1);
|
||||
namespace Snowflake\Core;
|
||||
|
||||
|
||||
use Exception;
|
||||
use JetBrains\PhpStorm\Pure;
|
||||
|
||||
/**
|
||||
* Class Help
|
||||
* @package Snowflake\Snowflake\Core
|
||||
@@ -16,7 +19,7 @@ class Help
|
||||
* @param array $data
|
||||
* @return string
|
||||
*/
|
||||
public static function toXml(array $data)
|
||||
#[Pure] public static function toXml(array $data)
|
||||
{
|
||||
$xml = "<xml>";
|
||||
foreach ($data as $key => $val) {
|
||||
@@ -33,9 +36,9 @@ class Help
|
||||
|
||||
/**
|
||||
* @param $xml
|
||||
* @return array|mixed
|
||||
* @return mixed
|
||||
*/
|
||||
public static function toArray($xml)
|
||||
public static function toArray($xml): mixed
|
||||
{
|
||||
if (empty($xml)) {
|
||||
return null;
|
||||
@@ -49,7 +52,11 @@ class Help
|
||||
}
|
||||
|
||||
|
||||
public static function jsonToArray($xml)
|
||||
/**
|
||||
* @param $xml
|
||||
* @return mixed
|
||||
*/
|
||||
public static function jsonToArray($xml): mixed
|
||||
{
|
||||
$_xml = json_decode($xml, true);
|
||||
if (is_null($_xml)) {
|
||||
@@ -62,7 +69,7 @@ class Help
|
||||
* @param $xml
|
||||
* @return mixed
|
||||
*/
|
||||
public static function xmlToArray($xml)
|
||||
public static function xmlToArray($xml): mixed
|
||||
{
|
||||
if (is_array($xml)) {
|
||||
return $xml;
|
||||
@@ -79,9 +86,9 @@ class Help
|
||||
/**
|
||||
* @param $parameter
|
||||
* @return array|false|string
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function toString($parameter)
|
||||
public static function toString($parameter): bool|array|string
|
||||
{
|
||||
if (!is_string($parameter)) {
|
||||
$parameter = ArrayAccess::toArray($parameter);
|
||||
@@ -94,9 +101,9 @@ class Help
|
||||
|
||||
/**
|
||||
* @param mixed $json
|
||||
* @return false|mixed|string
|
||||
* @return bool|string
|
||||
*/
|
||||
public static function toJson($json)
|
||||
public static function toJson(mixed $json): bool|string
|
||||
{
|
||||
if (is_object($json)) {
|
||||
$json = get_object_vars($json);
|
||||
@@ -122,7 +129,7 @@ class Help
|
||||
*
|
||||
* 随机字符串
|
||||
*/
|
||||
public static function random($length = 20)
|
||||
public static function random($length = 20): string
|
||||
{
|
||||
$res = [];
|
||||
$str = 'abcdefghijklmnopqrstuvwxyz';
|
||||
@@ -144,7 +151,7 @@ class Help
|
||||
* @param $type
|
||||
* @return string
|
||||
*/
|
||||
public static function sign(array $array, $key, $type)
|
||||
public static function sign(array $array, $key, $type): string
|
||||
{
|
||||
ksort($array, SORT_ASC);
|
||||
$string = [];
|
||||
|
||||
@@ -24,7 +24,7 @@ class JSON
|
||||
* @return false|string
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function encode($data)
|
||||
public static function encode($data): bool|string
|
||||
{
|
||||
if (empty($data)) {
|
||||
return $data;
|
||||
@@ -41,7 +41,7 @@ class JSON
|
||||
* @param bool $asArray
|
||||
* @return mixed
|
||||
*/
|
||||
public static function decode($data, $asArray = true)
|
||||
public static function decode($data, $asArray = true): mixed
|
||||
{
|
||||
if (is_array($data)) {
|
||||
return $data;
|
||||
@@ -58,7 +58,7 @@ class JSON
|
||||
* @return mixed
|
||||
* @throws
|
||||
*/
|
||||
public static function to($code, $message = '', $data = [], $count = 0, $exPageInfo = [])
|
||||
public static function to($code, $message = '', $data = [], $count = 0, $exPageInfo = []): mixed
|
||||
{
|
||||
$params['code'] = $code;
|
||||
if (!is_string($message)) {
|
||||
@@ -91,7 +91,7 @@ class JSON
|
||||
* @return false|int|string
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function output($state, $body)
|
||||
public static function output($state, $body): bool|int|string
|
||||
{
|
||||
$params['state'] = $state;
|
||||
$params['body'] = ArrayAccess::toArray($body);
|
||||
|
||||
@@ -18,7 +18,7 @@ class Reader
|
||||
* @param int $size
|
||||
* @return array and int
|
||||
*/
|
||||
public static function readerServerLogPagination($filepath, $page = 1, $size = 20)
|
||||
public static function readerServerLogPagination($filepath, $page = 1, $size = 20): array
|
||||
{
|
||||
$count = 0;
|
||||
$strings = [];
|
||||
@@ -56,7 +56,7 @@ class Reader
|
||||
* @param $lines
|
||||
* @return mixed
|
||||
*/
|
||||
public static function read_backward_line($filename, $start, $lines)
|
||||
public static function read_backward_line($filename, $start, $lines): mixed
|
||||
{
|
||||
$lines++;
|
||||
$offset = -1;
|
||||
@@ -100,7 +100,7 @@ class Reader
|
||||
* @param $filepath
|
||||
* @return int
|
||||
*/
|
||||
private static function read_count_by_file($filepath)
|
||||
private static function read_count_by_file($filepath): int
|
||||
{
|
||||
$count = 0;
|
||||
//只读方式打开文件
|
||||
@@ -123,7 +123,7 @@ class Reader
|
||||
* @param int $size
|
||||
* @return array
|
||||
*/
|
||||
public static function folderPagination($filepath, $page = 1, $size = 20)
|
||||
public static function folderPagination($filepath, $page = 1, $size = 20): array
|
||||
{
|
||||
$count = 0;
|
||||
$strings = [];
|
||||
|
||||
+18
-17
@@ -5,6 +5,7 @@ namespace Snowflake\Core;
|
||||
|
||||
|
||||
use Exception;
|
||||
use JetBrains\PhpStorm\Pure;
|
||||
|
||||
/**
|
||||
* Class Str
|
||||
@@ -23,7 +24,7 @@ class Str
|
||||
* @return string
|
||||
* 获取随机字符串
|
||||
*/
|
||||
public static function rand(int $length = 20)
|
||||
#[Pure] public static function rand(int $length = 20): string
|
||||
{
|
||||
$string = '';
|
||||
if ($length < 1) $length = 20;
|
||||
@@ -38,10 +39,10 @@ class Str
|
||||
/**
|
||||
* @param int $length
|
||||
*
|
||||
* @return int
|
||||
* @return int|string 获取随机数字
|
||||
* 获取随机数字
|
||||
*/
|
||||
public static function random(int $length = 20)
|
||||
#[Pure] public static function random(int $length = 20): int|string
|
||||
{
|
||||
$number = '';
|
||||
$default = str_split(self::NUMBER);
|
||||
@@ -54,13 +55,13 @@ class Str
|
||||
|
||||
/**
|
||||
* @param $string
|
||||
* @param $sublen
|
||||
* @param $sullen
|
||||
* @param bool $strip_tags
|
||||
* @param string $append
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function cut_str_utf8($string, $sublen, $strip_tags = true, $append = '...')
|
||||
public static function cut_str_utf8($string, $sullen, $strip_tags = true, $append = '...'): string
|
||||
{
|
||||
if ($strip_tags) {
|
||||
$string = strip_tags($string);
|
||||
@@ -71,7 +72,7 @@ class Str
|
||||
for ($i = 0; $i < count($t_string[0]); $i++) {
|
||||
$str .= $t_string[0][$i];
|
||||
//转为gbk,一个汉字长度为2
|
||||
if (strlen(@iconv('utf-8', 'gbk', $str)) >= $sublen) {
|
||||
if (strlen(@iconv('utf-8', 'gbk', $str)) >= $sullen) {
|
||||
if ($i != count($t_string[0]) - 1) $str .= $append;
|
||||
break;
|
||||
}
|
||||
@@ -86,7 +87,7 @@ class Str
|
||||
* @return bool
|
||||
* 判断是否为json字符串
|
||||
*/
|
||||
public static function isJson($data, $callback = null)
|
||||
public static function isJson($data, $callback = null): bool
|
||||
{
|
||||
$json = !is_null(json_decode($data)) && !is_numeric($data);
|
||||
if ($json && is_callable($callback, true)) {
|
||||
@@ -102,7 +103,7 @@ class Str
|
||||
* @return bool
|
||||
* 判断是否序列化字符串
|
||||
*/
|
||||
public static function isSerialize($data, $callBack = null)
|
||||
public static function isSerialize($data, $callBack = null): bool
|
||||
{
|
||||
$false = !empty($data) && unserialize($data) !== false;
|
||||
if ($false && is_callable($callBack, true)) {
|
||||
@@ -118,7 +119,7 @@ class Str
|
||||
* @param string $append
|
||||
* @return string
|
||||
*/
|
||||
public static function cut($string, int $length = 20, $append = '...')
|
||||
#[Pure] public static function cut($string, int $length = 20, $append = '...'): string
|
||||
{
|
||||
if (empty($string)) {
|
||||
return '';
|
||||
@@ -144,7 +145,7 @@ class Str
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function encrypt($str, $number = 10, $key = 'xshucai.com')
|
||||
public static function encrypt($str, $number = 10, $key = 'xshucai.com'): string
|
||||
{
|
||||
$res = [];
|
||||
$add = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
||||
@@ -166,7 +167,7 @@ class Str
|
||||
* @param $type
|
||||
* @return string
|
||||
*/
|
||||
public static function filename($file, $type)
|
||||
#[Pure] public static function filename($file, $type): string
|
||||
{
|
||||
switch ($type) {
|
||||
case 'image/png':
|
||||
@@ -187,7 +188,7 @@ class Str
|
||||
* @return array
|
||||
* 剩余天,带分秒
|
||||
*/
|
||||
public static function timeout($endTime, int $startTime = null)
|
||||
public static function timeout($endTime, int $startTime = null): array
|
||||
{
|
||||
$endTime = $endTime - (!empty($startTime) ? $startTime : time());
|
||||
|
||||
@@ -206,7 +207,7 @@ class Str
|
||||
/**
|
||||
* @return false|int
|
||||
*/
|
||||
public static function get_sy_time()
|
||||
public static function get_sy_time(): bool|int
|
||||
{
|
||||
$time = strtotime('+1days', strtotime(date('Y-m-d')));
|
||||
|
||||
@@ -217,7 +218,7 @@ class Str
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
public static function encode(string $string)
|
||||
#[Pure] public static function encode(string $string): string
|
||||
{
|
||||
return addslashes($string);
|
||||
}
|
||||
@@ -227,7 +228,7 @@ class Str
|
||||
* @return string|string[]|null
|
||||
* 清除标点符号
|
||||
*/
|
||||
public static function clear(string $string)
|
||||
public static function clear(string $string): array|string|null
|
||||
{
|
||||
$char = '。、!?:;﹑•"…‘’“”〝〞∕¦‖— 〈〉﹞﹝「」‹›〖〗】【»«』『〕〔》《﹐¸﹕︰﹔!¡?¿﹖﹌﹏﹋'´ˊˋ―﹫︳︴¯_ ̄﹢﹦﹤‐˜﹟﹩﹠﹪﹡﹨﹍﹉﹎﹊ˇ︵︶︷︸︹︿﹀︺︽︾ˉ﹁﹂﹃﹄︻︼()';
|
||||
return preg_replace(array("/[[:punct:]]/i", '/[' . $char . ']/u', '/[ ]{2,}/'), '', $string);
|
||||
@@ -237,12 +238,12 @@ class Str
|
||||
/**
|
||||
* @param int $user
|
||||
* @param array $param
|
||||
* @param int $requestTime
|
||||
* @param null $requestTime
|
||||
*
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function token($user, $param = [], $requestTime = NULL)
|
||||
public static function token(int $user, $param = [], $requestTime = NULL): string
|
||||
{
|
||||
$str = '';
|
||||
if (!$requestTime) {
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ class Xml
|
||||
* @param bool $asArray
|
||||
* @return array|object
|
||||
*/
|
||||
public static function toArray($data, $asArray = true)
|
||||
public static function toArray($data, $asArray = true): object|array
|
||||
{
|
||||
$data = simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA);
|
||||
if ($asArray) {
|
||||
@@ -35,7 +35,7 @@ class Xml
|
||||
* @param $str
|
||||
* @return array|bool|object
|
||||
*/
|
||||
public static function isXml($str)
|
||||
public static function isXml($str): object|bool|array
|
||||
{
|
||||
$xml_parser = xml_parser_create();
|
||||
if (!xml_parse($xml_parser, $str, true)) {
|
||||
|
||||
Reference in New Issue
Block a user