提交的内容
This commit is contained in:
99
vendor/topthink/think-helper/src/helper/Arr.php
vendored
Executable file → Normal file
99
vendor/topthink/think-helper/src/helper/Arr.php
vendored
Executable file → Normal file
@ -32,9 +32,9 @@ class Arr
|
||||
/**
|
||||
* Add an element to an array using "dot" notation if it doesn't exist.
|
||||
*
|
||||
* @param array $array
|
||||
* @param array $array
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param mixed $value
|
||||
* @return array
|
||||
*/
|
||||
public static function add($array, $key, $value)
|
||||
@ -110,7 +110,7 @@ class Arr
|
||||
/**
|
||||
* Flatten a multi-dimensional associative array with dots.
|
||||
*
|
||||
* @param array $array
|
||||
* @param array $array
|
||||
* @param string $prepend
|
||||
* @return array
|
||||
*/
|
||||
@ -132,7 +132,7 @@ class Arr
|
||||
/**
|
||||
* Get all of the given array except for a specified array of keys.
|
||||
*
|
||||
* @param array $array
|
||||
* @param array $array
|
||||
* @param array|string $keys
|
||||
* @return array
|
||||
*/
|
||||
@ -147,7 +147,7 @@ class Arr
|
||||
* Determine if the given key exists in the provided array.
|
||||
*
|
||||
* @param \ArrayAccess|array $array
|
||||
* @param string|int $key
|
||||
* @param string|int $key
|
||||
* @return bool
|
||||
*/
|
||||
public static function exists($array, $key)
|
||||
@ -162,12 +162,12 @@ class Arr
|
||||
/**
|
||||
* Return the first element in an array passing a given truth test.
|
||||
*
|
||||
* @param array $array
|
||||
* @param array $array
|
||||
* @param callable|null $callback
|
||||
* @param mixed $default
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public static function first($array, callable $callback = null, $default = null)
|
||||
public static function first($array, ?callable $callback = null, $default = null)
|
||||
{
|
||||
if (is_null($callback)) {
|
||||
if (empty($array)) {
|
||||
@ -191,12 +191,12 @@ class Arr
|
||||
/**
|
||||
* Return the last element in an array passing a given truth test.
|
||||
*
|
||||
* @param array $array
|
||||
* @param array $array
|
||||
* @param callable|null $callback
|
||||
* @param mixed $default
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public static function last($array, callable $callback = null, $default = null)
|
||||
public static function last($array, ?callable $callback = null, $default = null)
|
||||
{
|
||||
if (is_null($callback)) {
|
||||
return empty($array) ? value($default) : end($array);
|
||||
@ -209,7 +209,7 @@ class Arr
|
||||
* Flatten a multi-dimensional array into a single level.
|
||||
*
|
||||
* @param array $array
|
||||
* @param int $depth
|
||||
* @param int $depth
|
||||
* @return array
|
||||
*/
|
||||
public static function flatten($array, $depth = INF)
|
||||
@ -234,7 +234,7 @@ class Arr
|
||||
/**
|
||||
* Remove one or many array items from a given array using "dot" notation.
|
||||
*
|
||||
* @param array $array
|
||||
* @param array $array
|
||||
* @param array|string $keys
|
||||
* @return void
|
||||
*/
|
||||
@ -279,8 +279,8 @@ class Arr
|
||||
* Get an item from an array using "dot" notation.
|
||||
*
|
||||
* @param \ArrayAccess|array $array
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get($array, $key, $default = null)
|
||||
@ -316,7 +316,7 @@ class Arr
|
||||
* Check if an item or items exist in an array using "dot" notation.
|
||||
*
|
||||
* @param \ArrayAccess|array $array
|
||||
* @param string|array $keys
|
||||
* @param string|array $keys
|
||||
* @return bool
|
||||
*/
|
||||
public static function has($array, $keys)
|
||||
@ -356,15 +356,13 @@ class Arr
|
||||
*/
|
||||
public static function isAssoc(array $array)
|
||||
{
|
||||
$keys = array_keys($array);
|
||||
|
||||
return array_keys($keys) !== $keys;
|
||||
return !array_is_list($array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a subset of the items from the given array.
|
||||
*
|
||||
* @param array $array
|
||||
* @param array $array
|
||||
* @param array|string $keys
|
||||
* @return array
|
||||
*/
|
||||
@ -376,8 +374,8 @@ class Arr
|
||||
/**
|
||||
* Pluck an array of values from an array.
|
||||
*
|
||||
* @param array $array
|
||||
* @param string|array $value
|
||||
* @param array $array
|
||||
* @param string|array $value
|
||||
* @param string|array|null $key
|
||||
* @return array
|
||||
*/
|
||||
@ -412,7 +410,7 @@ class Arr
|
||||
/**
|
||||
* Explode the "value" and "key" arguments passed to "pluck".
|
||||
*
|
||||
* @param string|array $value
|
||||
* @param string|array $value
|
||||
* @param string|array|null $key
|
||||
* @return array
|
||||
*/
|
||||
@ -447,9 +445,9 @@ class Arr
|
||||
/**
|
||||
* Get a value from the array, and remove it.
|
||||
*
|
||||
* @param array $array
|
||||
* @param array $array
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public static function pull(&$array, $key, $default = null)
|
||||
@ -464,7 +462,7 @@ class Arr
|
||||
/**
|
||||
* Get one or a specified number of random values from an array.
|
||||
*
|
||||
* @param array $array
|
||||
* @param array $array
|
||||
* @param int|null $number
|
||||
* @return mixed
|
||||
*
|
||||
@ -506,9 +504,9 @@ class Arr
|
||||
*
|
||||
* If no key is given to the method, the entire array will be replaced.
|
||||
*
|
||||
* @param array $array
|
||||
* @param array $array
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param mixed $value
|
||||
* @return array
|
||||
*/
|
||||
public static function set(&$array, $key, $value)
|
||||
@ -540,7 +538,7 @@ class Arr
|
||||
/**
|
||||
* Shuffle the given array and return the result.
|
||||
*
|
||||
* @param array $array
|
||||
* @param array $array
|
||||
* @param int|null $seed
|
||||
* @return array
|
||||
*/
|
||||
@ -562,7 +560,7 @@ class Arr
|
||||
/**
|
||||
* Sort the array using the given callback or "dot" notation.
|
||||
*
|
||||
* @param array $array
|
||||
* @param array $array
|
||||
* @param callable|string|null $callback
|
||||
* @return array
|
||||
*/
|
||||
@ -608,7 +606,7 @@ class Arr
|
||||
/**
|
||||
* Filter the array using the given callback.
|
||||
*
|
||||
* @param array $array
|
||||
* @param array $array
|
||||
* @param callable $callback
|
||||
* @return array
|
||||
*/
|
||||
@ -631,4 +629,41 @@ class Arr
|
||||
|
||||
return is_array($value) ? $value : [$value];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively merge arrays.
|
||||
* If the value is an associative array, it will be merged recursively.
|
||||
* If the value is an indexed array, it will be replaced entirely.
|
||||
*
|
||||
* @param array ...$arrays
|
||||
* @return array
|
||||
*/
|
||||
public static function mergeDeep(array ...$arrays): array
|
||||
{
|
||||
$result = [];
|
||||
foreach ($arrays as $array) {
|
||||
foreach ($array as $key => $value) {
|
||||
if (isset($result[$key]) && is_array($result[$key]) && is_array($value)) {
|
||||
// 只有当两个数组都是关联数组时才递归合并
|
||||
if (self::isAssoc($result[$key]) && self::isAssoc($value)) {
|
||||
$result[$key] = self::mergeDeep(
|
||||
$result[$key],
|
||||
$value
|
||||
);
|
||||
} else {
|
||||
// 如果任一数组是索引数组,则直接覆盖
|
||||
$result[$key] = $value;
|
||||
}
|
||||
} else {
|
||||
$result[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function flatMap(callable $fn, array $array): array
|
||||
{
|
||||
return array_merge(...array_map($fn, $array));
|
||||
}
|
||||
}
|
||||
|
||||
66
vendor/topthink/think-helper/src/helper/Macroable.php
vendored
Normal file
66
vendor/topthink/think-helper/src/helper/Macroable.php
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006-2015 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: yunwuxin <448901948@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace think\helper;
|
||||
|
||||
use Closure;
|
||||
use think\exception\FuncNotFoundException;
|
||||
|
||||
trait Macroable
|
||||
{
|
||||
/**
|
||||
* 方法注入.
|
||||
*
|
||||
* @var Closure[]
|
||||
*/
|
||||
protected static $macro = [];
|
||||
|
||||
/**
|
||||
* 设置方法注入.
|
||||
*
|
||||
* @param string $method
|
||||
* @param Closure $closure
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function macro(string $method, Closure $closure)
|
||||
{
|
||||
static::$macro[$method] = $closure;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查方法是否已经有注入
|
||||
*
|
||||
* @param string $name
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasMacro(string $method)
|
||||
{
|
||||
return isset(static::$macro[$method]);
|
||||
}
|
||||
|
||||
public function __call($method, $args)
|
||||
{
|
||||
if (!isset(static::$macro[$method])) {
|
||||
throw new FuncNotFoundException('method not exists: ' . static::class . '::' . $method . '()', "{static::class}::{$method}");
|
||||
}
|
||||
|
||||
return call_user_func_array(static::$macro[$method]->bindTo($this, static::class), $args);
|
||||
}
|
||||
|
||||
public static function __callStatic($method, $args)
|
||||
{
|
||||
if (!isset(static::$macro[$method])) {
|
||||
throw new FuncNotFoundException('method not exists: ' . static::class . '::' . $method . '()', "{static::class}::{$method}");
|
||||
}
|
||||
|
||||
return call_user_func_array(static::$macro[$method]->bindTo(null, static::class), $args);
|
||||
}
|
||||
}
|
||||
4
vendor/topthink/think-helper/src/helper/Str.php
vendored
Executable file → Normal file
4
vendor/topthink/think-helper/src/helper/Str.php
vendored
Executable file → Normal file
@ -80,7 +80,7 @@ class Str
|
||||
* @param string $addChars
|
||||
* @return string
|
||||
*/
|
||||
public static function random(int $length = 6, int $type = null, string $addChars = ''): string
|
||||
public static function random(int $length = 6, ?int $type = null, string $addChars = ''): string
|
||||
{
|
||||
$str = '';
|
||||
switch ($type) {
|
||||
@ -158,7 +158,7 @@ class Str
|
||||
* @param int|null $length
|
||||
* @return string
|
||||
*/
|
||||
public static function substr(string $string, int $start, int $length = null): string
|
||||
public static function substr(string $string, int $start, ?int $length = null): string
|
||||
{
|
||||
return mb_substr($string, $start, $length, 'UTF-8');
|
||||
}
|
||||
|
||||
203
vendor/topthink/think-helper/src/helper/Time.php
vendored
203
vendor/topthink/think-helper/src/helper/Time.php
vendored
@ -1,203 +0,0 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 刘志淳 <chun@engineer.com>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace think\helper;
|
||||
|
||||
class Time
|
||||
{
|
||||
/**
|
||||
* 返回今日开始和结束的时间戳
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function today()
|
||||
{
|
||||
list($y, $m, $d) = explode('-', date('Y-m-d'));
|
||||
return [
|
||||
mktime(0, 0, 0, $m, $d, $y),
|
||||
mktime(23, 59, 59, $m, $d, $y)
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回昨日开始和结束的时间戳
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function yesterday()
|
||||
{
|
||||
$yesterday = date('d') - 1;
|
||||
return [
|
||||
mktime(0, 0, 0, date('m'), $yesterday, date('Y')),
|
||||
mktime(23, 59, 59, date('m'), $yesterday, date('Y'))
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回本周开始和结束的时间戳
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function week()
|
||||
{
|
||||
list($y, $m, $d, $w) = explode('-', date('Y-m-d-w'));
|
||||
if($w == 0) $w = 7; //修正周日的问题
|
||||
return [
|
||||
mktime(0, 0, 0, $m, $d - $w + 1, $y), mktime(23, 59, 59, $m, $d - $w + 7, $y)
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回上周开始和结束的时间戳
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function lastWeek()
|
||||
{
|
||||
$timestamp = time();
|
||||
return [
|
||||
strtotime(date('Y-m-d', strtotime("last week Monday", $timestamp))),
|
||||
strtotime(date('Y-m-d', strtotime("last week Sunday", $timestamp))) + 24 * 3600 - 1
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回本月开始和结束的时间戳
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function month($everyDay = false)
|
||||
{
|
||||
list($y, $m, $t) = explode('-', date('Y-m-t'));
|
||||
return [
|
||||
mktime(0, 0, 0, $m, 1, $y),
|
||||
mktime(23, 59, 59, $m, $t, $y)
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回上个月开始和结束的时间戳
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function lastMonth()
|
||||
{
|
||||
$y = date('Y');
|
||||
$m = date('m');
|
||||
$begin = mktime(0, 0, 0, $m - 1, 1, $y);
|
||||
$end = mktime(23, 59, 59, $m - 1, date('t', $begin), $y);
|
||||
|
||||
return [$begin, $end];
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回今年开始和结束的时间戳
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function year()
|
||||
{
|
||||
$y = date('Y');
|
||||
return [
|
||||
mktime(0, 0, 0, 1, 1, $y),
|
||||
mktime(23, 59, 59, 12, 31, $y)
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回去年开始和结束的时间戳
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function lastYear()
|
||||
{
|
||||
$year = date('Y') - 1;
|
||||
return [
|
||||
mktime(0, 0, 0, 1, 1, $year),
|
||||
mktime(23, 59, 59, 12, 31, $year)
|
||||
];
|
||||
}
|
||||
|
||||
public static function dayOf()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取几天前零点到现在/昨日结束的时间戳
|
||||
*
|
||||
* @param int $day 天数
|
||||
* @param bool $now 返回现在或者昨天结束时间戳
|
||||
* @return array
|
||||
*/
|
||||
public static function dayToNow($day = 1, $now = true)
|
||||
{
|
||||
$end = time();
|
||||
if (!$now) {
|
||||
list($foo, $end) = self::yesterday();
|
||||
}
|
||||
|
||||
return [
|
||||
mktime(0, 0, 0, date('m'), date('d') - $day, date('Y')),
|
||||
$end
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回几天前的时间戳
|
||||
*
|
||||
* @param int $day
|
||||
* @return int
|
||||
*/
|
||||
public static function daysAgo($day = 1)
|
||||
{
|
||||
$nowTime = time();
|
||||
return $nowTime - self::daysToSecond($day);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回几天后的时间戳
|
||||
*
|
||||
* @param int $day
|
||||
* @return int
|
||||
*/
|
||||
public static function daysAfter($day = 1)
|
||||
{
|
||||
$nowTime = time();
|
||||
return $nowTime + self::daysToSecond($day);
|
||||
}
|
||||
|
||||
/**
|
||||
* 天数转换成秒数
|
||||
*
|
||||
* @param int $day
|
||||
* @return int
|
||||
*/
|
||||
public static function daysToSecond($day = 1)
|
||||
{
|
||||
return $day * 86400;
|
||||
}
|
||||
|
||||
/**
|
||||
* 周数转换成秒数
|
||||
*
|
||||
* @param int $week
|
||||
* @return int
|
||||
*/
|
||||
public static function weekToSecond($week = 1)
|
||||
{
|
||||
return self::daysToSecond() * 7 * $week;
|
||||
}
|
||||
|
||||
private static function startTimeToEndTime()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user