Compare commits
7 Commits
c0586c93cd
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 6d3eeeca34 | |||
| e82f3275cf | |||
| e744b1a898 | |||
| d6a9b93f29 | |||
| 38a6f81b39 | |||
| 9e3c82086c | |||
| b1f99153b2 |
@@ -96,12 +96,15 @@ class Logger
|
||||
|
||||
if ($this->throwable !== null) {
|
||||
$throwable = $this->throwable;
|
||||
$previous = $throwable->getPrevious();
|
||||
$content['throwable'] = [
|
||||
'message' => $throwable->getMessage(),
|
||||
'code' => $throwable->getCode(),
|
||||
'file' => $throwable->getFile(),
|
||||
'line' => $throwable->getLine(),
|
||||
'trace' => $this->isError ? $throwable->getTrace() : null,
|
||||
'previous_trace' => $previous ? $previous->getTrace() : null,
|
||||
'previous_message' => $previous ? $previous->getMessage() : null,
|
||||
'data' => method_exists($throwable, 'getData') ? $throwable->getData() : null,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ use Hyperf\Context\ApplicationContext;
|
||||
use Hyperf\Collection\Arr;
|
||||
use Hyperf\Carbon\Carbon;
|
||||
use Dhd\Micro\Core\Library\Logger;
|
||||
use Hyperf\Contract\LengthAwarePaginatorInterface;
|
||||
use Hyperf\Paginator\AbstractPaginator;
|
||||
|
||||
final class Util
|
||||
{
|
||||
@@ -410,4 +412,53 @@ final class Util
|
||||
$step = 1024;
|
||||
return round($bytes / $step, 2) . 'KB';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分页参数中的页码
|
||||
* @param array $params
|
||||
* @return int
|
||||
*/
|
||||
public static function getPageFromParams(array $params): int
|
||||
{
|
||||
$page = (int)Arr::get($params, 'page', 1) ?: 1;
|
||||
return max($page, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分页参数中的每页数量
|
||||
* @param array $params
|
||||
* @return int
|
||||
*/
|
||||
public static function getPageSizeFromParams(array $params, int $maxSize = 100): int
|
||||
{
|
||||
$pageSize = (int)Arr::get(
|
||||
$params,
|
||||
'size',
|
||||
Arr::get(
|
||||
$params,
|
||||
'page_size',
|
||||
Arr::get($params, 'pageSize', 15)
|
||||
)
|
||||
) ?: 15;
|
||||
|
||||
return min(max($pageSize, 1), $maxSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页打包
|
||||
* @param LengthAwarePaginatorInterface $paginator 分页对象
|
||||
* @return array
|
||||
*/
|
||||
public static function handlePage(LengthAwarePaginatorInterface $paginator): array
|
||||
{
|
||||
if ($paginator instanceof AbstractPaginator) {
|
||||
$items = $paginator->getCollection();
|
||||
} else {
|
||||
$items = Collection::make($paginator->items());
|
||||
}
|
||||
return [
|
||||
'list' => $items->toArray(),
|
||||
'total' => $paginator->total(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ abstract class Model extends HyperfModel implements CacheableInterface
|
||||
$size = max(1, min(100, $size));
|
||||
|
||||
$result = $query->paginate($size, ['*'], 'page', $page);
|
||||
if (is_callable($eachCallback) && method_exists($result, 'each')) {
|
||||
if (is_callable($eachCallback)) {
|
||||
$result->each($eachCallback);
|
||||
}
|
||||
return [
|
||||
|
||||
@@ -384,4 +384,12 @@ abstract class Service
|
||||
{
|
||||
Util::setObjectValueExcept($obj, $params, $except);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|T
|
||||
*/
|
||||
public function findByFilter(array $params): mixed
|
||||
{
|
||||
return $this->repository->findByFilter($params);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ use Hyperf\Di\Annotation\Inject;
|
||||
use Hyperf\Validation\Contract\ValidatorFactoryInterface;
|
||||
use Hyperf\Validation\Validator as HyperfValidator;
|
||||
use RuntimeException;
|
||||
use Hyperf\Collection\Arr;
|
||||
|
||||
abstract class Validator
|
||||
{
|
||||
@@ -128,6 +129,17 @@ abstract class Validator
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取待验证数据中指定键的值.
|
||||
* 如果不存在该键,则返回null.
|
||||
* @param string $key 待获取的键名
|
||||
* @return mixed 键对应的值
|
||||
*/
|
||||
protected function getDataByKey(string $key): mixed
|
||||
{
|
||||
return Arr::get($this->data, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 定义场景验证规则(子类实现).
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user