mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2025-04-05 19:41:44 +08:00
启用强类型Libarary,调整代码
This commit is contained in:
parent
6bad3ded9c
commit
693502ec5e
@ -131,7 +131,7 @@ class Auth extends Controller
|
||||
* @param boolean $result
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
protected function _remove_delete_result($result)
|
||||
protected function _remove_delete_result(bool $result)
|
||||
{
|
||||
if ($result) {
|
||||
$map = $this->_vali(['auth.require#id' => '权限ID不能为空!']);
|
||||
|
@ -84,6 +84,7 @@ class Login extends Controller
|
||||
'login_num' => $this->app->db->raw('login_num+1'),
|
||||
]);
|
||||
sysoplog('用户登录', '登录系统后台成功');
|
||||
$GLOBALS['oplogs'] = [];
|
||||
$this->success('登录成功', sysuri('admin/index/index'));
|
||||
}
|
||||
}
|
||||
|
@ -53,11 +53,11 @@ class Menu extends Controller
|
||||
* 列表数据处理
|
||||
* @param array $data
|
||||
*/
|
||||
protected function _index_page_filter(&$data)
|
||||
protected function _index_page_filter(array &$data)
|
||||
{
|
||||
foreach ($data as &$vo) {
|
||||
if ($vo['url'] !== '#') {
|
||||
$vo['url'] = trim(url($vo['url']) . (empty($vo['params']) ? '' : "?{$vo['params']}"), '/\\');
|
||||
$vo['url'] = trim(sysuri($vo['url']) . (empty($vo['params']) ? '' : "?{$vo['params']}"), '/\\');
|
||||
}
|
||||
$vo['ids'] = join(',', DataExtend::getArrSubIds($data, $vo['id']));
|
||||
}
|
||||
@ -95,7 +95,7 @@ class Menu extends Controller
|
||||
* @param array $vo
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
protected function _form_filter(&$vo)
|
||||
protected function _form_filter(array &$vo)
|
||||
{
|
||||
if ($this->request->isGet()) {
|
||||
// 清理权限节点
|
||||
|
@ -54,7 +54,7 @@ class Oplog extends Controller
|
||||
* @param array $data
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function _index_page_filter(&$data)
|
||||
protected function _index_page_filter(array &$data)
|
||||
{
|
||||
$ip = new \Ip2Region();
|
||||
foreach ($data as &$vo) {
|
||||
|
@ -97,7 +97,7 @@ class Queue extends Controller
|
||||
* 重启任务结果处理
|
||||
* @param boolean $state
|
||||
*/
|
||||
protected function _redo_save_result($state)
|
||||
protected function _redo_save_result(bool $state)
|
||||
{
|
||||
if ($state) {
|
||||
$this->success('重启任务成功!');
|
||||
|
@ -117,7 +117,7 @@ class User extends Controller
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
protected function _form_filter(&$data)
|
||||
protected function _form_filter(array &$data)
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
if (isset($data['id']) && $data['id'] > 0) {
|
||||
|
@ -52,7 +52,7 @@ class NewsItem extends Controller
|
||||
* 列表数据处理
|
||||
* @param array $data
|
||||
*/
|
||||
protected function _page_filter(&$data)
|
||||
protected function _page_filter(array &$data)
|
||||
{
|
||||
NewsService::instance()->buildListState($data);
|
||||
}
|
||||
@ -90,7 +90,7 @@ class NewsItem extends Controller
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
protected function _form_filter(&$data)
|
||||
protected function _form_filter(array &$data)
|
||||
{
|
||||
if ($this->request->isGet()) {
|
||||
$query = $this->app->db->name('DataNewsMark')->where(['deleted' => 0, 'status' => 1]);
|
||||
@ -105,7 +105,7 @@ class NewsItem extends Controller
|
||||
* 表单结果处理
|
||||
* @param boolean $state
|
||||
*/
|
||||
protected function _form_result($state)
|
||||
protected function _form_result(bool $state)
|
||||
{
|
||||
if ($state) {
|
||||
$this->success('文章内容保存成功!', 'javascript:history.back()');
|
||||
|
@ -76,7 +76,7 @@ class ShopGoods extends Controller
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
protected function _page_filter(&$data)
|
||||
protected function _page_filter(array &$data)
|
||||
{
|
||||
$this->marks = GoodsService::instance()->getMarkList();
|
||||
$this->clist = GoodsService::instance()->getCateList('arr2table');
|
||||
@ -133,7 +133,7 @@ class ShopGoods extends Controller
|
||||
* 表单数据处理
|
||||
* @param array $data
|
||||
*/
|
||||
protected function _copy_form_filter(&$data)
|
||||
protected function _copy_form_filter(array &$data)
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$data['code'] = CodeExtend::uniqidNumber(12, 'G');
|
||||
@ -147,7 +147,7 @@ class ShopGoods extends Controller
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
protected function _form_filter(&$data)
|
||||
protected function _form_filter(array &$data)
|
||||
{
|
||||
if (empty($data['code'])) {
|
||||
$data['code'] = CodeExtend::uniqidNumber(12, 'G');
|
||||
@ -191,7 +191,7 @@ class ShopGoods extends Controller
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
protected function _form_result($result)
|
||||
protected function _form_result(bool $result)
|
||||
{
|
||||
if ($result && $this->request->isPost()) {
|
||||
GoodsService::instance()->syncStock(input('code'));
|
||||
|
@ -53,7 +53,7 @@ class ShopGoodsCate extends Controller
|
||||
* 列表数据处理
|
||||
* @param array $data
|
||||
*/
|
||||
protected function _index_page_filter(&$data)
|
||||
protected function _index_page_filter(array &$data)
|
||||
{
|
||||
foreach ($data as &$vo) {
|
||||
$vo['ids'] = join(',', DataExtend::getArrSubIds($data, $vo['id']));
|
||||
@ -92,7 +92,7 @@ class ShopGoodsCate extends Controller
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
protected function _form_filter(&$data)
|
||||
protected function _form_filter(array &$data)
|
||||
{
|
||||
if ($this->request->isGet()) {
|
||||
$data['pid'] = intval($data['pid'] ?? input('pid', '0'));
|
||||
|
@ -98,7 +98,7 @@ class ShopOrder extends Controller
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
protected function _truck_form_filter(&$vo)
|
||||
protected function _truck_form_filter(array &$vo)
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$map = ['order_no' => $vo['order_no']];
|
||||
|
@ -99,7 +99,7 @@ class ShopTruckTemplate extends Controller
|
||||
* 表单结果处理
|
||||
* @param boolean $result
|
||||
*/
|
||||
protected function _form_result($result)
|
||||
protected function _form_result(bool $result)
|
||||
{
|
||||
if ($result && $this->request->isPost()) {
|
||||
$this->success('邮费模板保存成功!', 'javascript:history.back()');
|
||||
|
@ -21,7 +21,7 @@ class GoodsService extends Service
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function syncStock(string $code)
|
||||
public function syncStock(string $code): bool
|
||||
{
|
||||
// 商品入库统计
|
||||
$query = $this->app->db->name('ShopGoodsStock');
|
||||
@ -78,7 +78,7 @@ class GoodsService extends Service
|
||||
* 获取商品标签数据
|
||||
* @return array
|
||||
*/
|
||||
public function getMarkList()
|
||||
public function getMarkList(): array
|
||||
{
|
||||
$map = ['status' => 1];
|
||||
$query = $this->app->db->name('ShopGoodsMark');
|
||||
|
@ -16,7 +16,7 @@ class NewsService extends Service
|
||||
* @param integer $cid 文章ID
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function syncNewsTotal(int $cid)
|
||||
public function syncNewsTotal(int $cid): void
|
||||
{
|
||||
[$map, $total] = [['cid' => $cid], []];
|
||||
$query = $this->app->db->name('DataNewsXCollect')->field('count(1) count,type');
|
||||
|
@ -26,7 +26,7 @@ class OrderService extends Service
|
||||
* 获取随机减免金额
|
||||
* @return float
|
||||
*/
|
||||
public function getReduct()
|
||||
public function getReduct(): float
|
||||
{
|
||||
return rand(1, 100) / 100;
|
||||
}
|
||||
@ -34,12 +34,12 @@ class OrderService extends Service
|
||||
/**
|
||||
* 同步订单关联商品的库存
|
||||
* @param string $order_no 订单编号
|
||||
* @return bool
|
||||
* @return boolean
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function syncStock(string $order_no)
|
||||
public function syncStock(string $order_no): bool
|
||||
{
|
||||
$map = ['order_no' => $order_no];
|
||||
$codes = $this->app->db->name('ShopOrderItem')->where($map)->column('goods_code');
|
||||
|
@ -51,10 +51,10 @@ class TruckService extends Service
|
||||
/**
|
||||
* 配送区域树型数据
|
||||
* @param integer $level 最大级别
|
||||
* @param integer $status 状态筛选
|
||||
* @param null|integer $status 状态筛选
|
||||
* @return array
|
||||
*/
|
||||
public function region($level = 3, $status = null)
|
||||
public function region($level = 3, $status = null): array
|
||||
{
|
||||
$query = $this->app->db->name('ShopTruckRegion');
|
||||
if (is_numeric($level)) $query->where('level', '<=', $level);
|
||||
@ -77,7 +77,7 @@ class TruckService extends Service
|
||||
* @return array
|
||||
* @throws \think\admin\Exception
|
||||
*/
|
||||
public function query($code, $number)
|
||||
public function query(string $code, string $number): array
|
||||
{
|
||||
return $this->_getInterface()->doRequest('api.auth.express/query', [
|
||||
'type' => 'free', 'express' => $code, 'number' => $number,
|
||||
|
@ -71,11 +71,11 @@ class Keys extends Controller
|
||||
* 列表数据处理
|
||||
* @param array $data
|
||||
*/
|
||||
protected function _index_page_filter(&$data)
|
||||
protected function _index_page_filter(array &$data)
|
||||
{
|
||||
foreach ($data as &$vo) {
|
||||
$vo['type'] = $this->types[$vo['type']] ?? $vo['type'];
|
||||
$vo['qrc'] = url('wechat/keys/index') . "?action=qrc&keys={$vo['keys']}";
|
||||
$vo['qrc'] = sysuri('wechat/keys/index') . "?action=qrc&keys={$vo['keys']}";
|
||||
}
|
||||
}
|
||||
|
||||
@ -186,7 +186,7 @@ class Keys extends Controller
|
||||
* 表单结果处理
|
||||
* @param boolean $result
|
||||
*/
|
||||
protected function _form_result($result)
|
||||
protected function _form_result(bool $result)
|
||||
{
|
||||
if ($result !== false) {
|
||||
$iskeys = in_array(input('keys'), ['subscribe', 'default']);
|
||||
|
@ -44,7 +44,7 @@ class News extends Controller
|
||||
public function index()
|
||||
{
|
||||
$this->title = '微信图文列表';
|
||||
$this->_query($this->table)->where(['is_deleted' => '0'])->order('id desc')->page();
|
||||
$this->_query($this->table)->where(['is_deleted' => 0])->order('id desc')->page();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -54,7 +54,7 @@ class News extends Controller
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
protected function _index_page_filter(&$data)
|
||||
protected function _page_filter(array &$data)
|
||||
{
|
||||
foreach ($data as &$vo) {
|
||||
$vo = MediaService::instance()->news($vo['id']);
|
||||
@ -73,20 +73,6 @@ class News extends Controller
|
||||
$this->index();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表数据处理
|
||||
* @param array $data
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
protected function _select_page_filter(&$data)
|
||||
{
|
||||
foreach ($data as &$vo) {
|
||||
$vo = MediaService::instance()->news($vo['id']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加微信图文
|
||||
* @auth true
|
||||
@ -139,6 +125,16 @@ class News extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除微信图文
|
||||
* auth true
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function remove()
|
||||
{
|
||||
$this->_delete($this->table);
|
||||
}
|
||||
|
||||
/**
|
||||
* 图文更新操作
|
||||
* @param array $data
|
||||
@ -146,7 +142,7 @@ class News extends Controller
|
||||
* @return string
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
private function _buildArticle($data, $ids = [])
|
||||
private function _buildArticle(array $data, array $ids = []): string
|
||||
{
|
||||
foreach ($data as $vo) {
|
||||
if (empty($vo['digest'])) {
|
||||
@ -164,14 +160,4 @@ class News extends Controller
|
||||
return join(',', $ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除微信图文
|
||||
* auth true
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function remove()
|
||||
{
|
||||
$this->_delete($this->table);
|
||||
}
|
||||
|
||||
}
|
||||
|
12
vendor/composer/installed.json
vendored
12
vendor/composer/installed.json
vendored
@ -958,17 +958,17 @@
|
||||
},
|
||||
{
|
||||
"name": "zoujingli/think-library",
|
||||
"version": "v6.0.10",
|
||||
"version_normalized": "6.0.10.0",
|
||||
"version": "v6.0.11",
|
||||
"version_normalized": "6.0.11.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/zoujingli/ThinkLibrary.git",
|
||||
"reference": "9f778a0eaa1ae3c7dd15cd6f9812c94a29e438ae"
|
||||
"reference": "eab7b5fb89f2fa859c3943514fdc7af5a7a43ef0"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/9f778a0eaa1ae3c7dd15cd6f9812c94a29e438ae",
|
||||
"reference": "9f778a0eaa1ae3c7dd15cd6f9812c94a29e438ae",
|
||||
"url": "https://api.github.com/repos/zoujingli/ThinkLibrary/zipball/eab7b5fb89f2fa859c3943514fdc7af5a7a43ef0",
|
||||
"reference": "eab7b5fb89f2fa859c3943514fdc7af5a7a43ef0",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
@ -985,7 +985,7 @@
|
||||
"ext-mbstring": "*",
|
||||
"topthink/framework": "^6.0"
|
||||
},
|
||||
"time": "2020-09-23T02:52:29+00:00",
|
||||
"time": "2020-09-23T09:42:23+00:00",
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"think": {
|
||||
|
2
vendor/services.php
vendored
2
vendor/services.php
vendored
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
// This file is automatically generated at:2020-09-23 11:00:47
|
||||
// This file is automatically generated at:2020-09-23 18:02:05
|
||||
declare (strict_types = 1);
|
||||
return array (
|
||||
0 => 'think\\admin\\Library',
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 仓库地址 :https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin;
|
||||
|
||||
use think\admin\service\ProcessService;
|
||||
@ -50,7 +52,7 @@ abstract class Command extends ThinkCommand
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
protected function initialize(Input $input, Output $output)
|
||||
protected function initialize(Input $input, Output $output): Command
|
||||
{
|
||||
$this->queue = QueueService::instance();
|
||||
$this->process = ProcessService::instance();
|
||||
@ -87,7 +89,7 @@ abstract class Command extends ThinkCommand
|
||||
* @return static
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function setQueueError(string $message)
|
||||
protected function setQueueError(string $message): Command
|
||||
{
|
||||
if (defined('WorkQueueCode')) {
|
||||
throw new Exception($message, 4, WorkQueueCode);
|
||||
@ -103,7 +105,7 @@ abstract class Command extends ThinkCommand
|
||||
* @return static
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function setQueueSuccess(string $message)
|
||||
protected function setQueueSuccess(string $message): Command
|
||||
{
|
||||
if (defined('WorkQueueCode')) {
|
||||
throw new Exception($message, 3, WorkQueueCode);
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 仓库地址 :https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin;
|
||||
|
||||
use think\admin\helper\DeleteHelper;
|
||||
@ -98,7 +100,7 @@ abstract class Controller extends \stdClass
|
||||
* @param mixed $data 返回数据
|
||||
* @param integer $code 返回代码
|
||||
*/
|
||||
public function error($info, $data = '{-null-}', $code = 0)
|
||||
public function error($info, $data = '{-null-}', $code = 0): void
|
||||
{
|
||||
if ($data === '{-null-}') $data = new \stdClass();
|
||||
throw new HttpResponseException(json([
|
||||
@ -112,7 +114,7 @@ abstract class Controller extends \stdClass
|
||||
* @param mixed $data 返回数据
|
||||
* @param integer $code 返回代码
|
||||
*/
|
||||
public function success($info, $data = '{-null-}', $code = 1)
|
||||
public function success($info, $data = '{-null-}', $code = 1): void
|
||||
{
|
||||
if ($this->csrf_state) {
|
||||
TokenHelper::instance()->clear();
|
||||
@ -128,7 +130,7 @@ abstract class Controller extends \stdClass
|
||||
* @param string $url 跳转链接
|
||||
* @param integer $code 跳转代码
|
||||
*/
|
||||
public function redirect($url, $code = 301)
|
||||
public function redirect(string $url, $code = 301): void
|
||||
{
|
||||
throw new HttpResponseException(redirect($url, $code));
|
||||
}
|
||||
@ -137,9 +139,9 @@ abstract class Controller extends \stdClass
|
||||
* 返回视图内容
|
||||
* @param string $tpl 模板名称
|
||||
* @param array $vars 模板变量
|
||||
* @param string $node CSRF授权节点
|
||||
* @param mixed $node CSRF授权节点
|
||||
*/
|
||||
public function fetch($tpl = '', $vars = [], $node = null)
|
||||
public function fetch($tpl = '', $vars = [], $node = null): void
|
||||
{
|
||||
foreach ($this as $name => $value) $vars[$name] = $value;
|
||||
if ($this->csrf_state) {
|
||||
@ -174,7 +176,7 @@ abstract class Controller extends \stdClass
|
||||
* @param mixed $two 回调引用参数2
|
||||
* @return boolean
|
||||
*/
|
||||
public function callback($name, &$one = [], &$two = [])
|
||||
public function callback(string $name, &$one = [], &$two = []): bool
|
||||
{
|
||||
if (is_callable($name)) return call_user_func($name, $this, $one, $two);
|
||||
foreach (["_{$this->app->request->action()}{$name}", $name] as $method) {
|
||||
@ -209,7 +211,7 @@ abstract class Controller extends \stdClass
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
protected function _page($dbQuery, $page = true, $display = true, $total = false, $limit = 0, $template = '')
|
||||
protected function _page($dbQuery, bool $page = true, bool $display = true, $total = false, int $limit = 0, string $template = '')
|
||||
{
|
||||
return PageHelper::instance()->init($dbQuery, $page, $display, $total, $limit, $template);
|
||||
}
|
||||
@ -226,7 +228,7 @@ abstract class Controller extends \stdClass
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
protected function _form($dbQuery, $template = '', $field = '', $where = [], $data = [])
|
||||
protected function _form($dbQuery, string $template = '', string $field = '', array $where = [], array $data = [])
|
||||
{
|
||||
return FormHelper::instance()->init($dbQuery, $template, $field, $where, $data);
|
||||
}
|
||||
@ -237,7 +239,7 @@ abstract class Controller extends \stdClass
|
||||
* @param string $type 输入方式 ( post. 或 get. )
|
||||
* @return array
|
||||
*/
|
||||
protected function _vali(array $rules, $type = '')
|
||||
protected function _vali(array $rules, string $type = '')
|
||||
{
|
||||
return ValidateHelper::instance()->init($rules, $type);
|
||||
}
|
||||
@ -251,7 +253,7 @@ abstract class Controller extends \stdClass
|
||||
* @return boolean
|
||||
* @throws DbException
|
||||
*/
|
||||
protected function _save($dbQuery, $data = [], $field = '', $where = [])
|
||||
protected function _save($dbQuery, array $data = [], string $field = '', array $where = [])
|
||||
{
|
||||
return SaveHelper::instance()->init($dbQuery, $data, $field, $where);
|
||||
}
|
||||
@ -264,7 +266,7 @@ abstract class Controller extends \stdClass
|
||||
* @return boolean|null
|
||||
* @throws DbException
|
||||
*/
|
||||
protected function _delete($dbQuery, $field = '', $where = [])
|
||||
protected function _delete($dbQuery, string $field = '', array $where = [])
|
||||
{
|
||||
return DeleteHelper::instance()->init($dbQuery, $field, $where);
|
||||
}
|
||||
@ -274,7 +276,7 @@ abstract class Controller extends \stdClass
|
||||
* @param boolean $return 是否返回结果
|
||||
* @return boolean
|
||||
*/
|
||||
protected function _applyFormToken($return = false)
|
||||
protected function _applyFormToken(bool $return = false)
|
||||
{
|
||||
return TokenHelper::instance()->init($return);
|
||||
}
|
||||
@ -288,7 +290,7 @@ abstract class Controller extends \stdClass
|
||||
* @param integer $rscript 任务类型(0单例,1多例)
|
||||
* @param integer $loops 循环等待时间
|
||||
*/
|
||||
protected function _queue($title, $command, $later = 0, $data = [], $rscript = 0, $loops = 0)
|
||||
protected function _queue(string $title, string $command, int $later = 0, array $data = [], int $rscript = 0, int $loops = 0)
|
||||
{
|
||||
try {
|
||||
$queue = QueueService::instance()->register($title, $command, $later, $data, $rscript, $loops);
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 仓库地址 :https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin;
|
||||
|
||||
use think\App;
|
||||
|
@ -41,7 +41,7 @@ class Library extends Service
|
||||
/**
|
||||
* 扩展库版本号
|
||||
*/
|
||||
const VERSION = '6.0.10';
|
||||
const VERSION = '6.0.11';
|
||||
|
||||
/**
|
||||
* 启动服务
|
||||
|
10
vendor/zoujingli/think-library/src/Queue.php
vendored
10
vendor/zoujingli/think-library/src/Queue.php
vendored
@ -13,6 +13,8 @@
|
||||
// | github 代码仓库:https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin;
|
||||
|
||||
use think\admin\service\ProcessService;
|
||||
@ -60,7 +62,7 @@ abstract class Queue
|
||||
* @param QueueService $queue
|
||||
* @return $this
|
||||
*/
|
||||
public function initialize(QueueService $queue)
|
||||
public function initialize(QueueService $queue): Queue
|
||||
{
|
||||
$this->queue = $queue;
|
||||
return $this;
|
||||
@ -79,7 +81,7 @@ abstract class Queue
|
||||
* @param null|integer $progress 进度数值
|
||||
* @return Queue
|
||||
*/
|
||||
protected function setQueueProgress($message = null, $progress = null)
|
||||
protected function setQueueProgress($message = null, $progress = null): Queue
|
||||
{
|
||||
$this->queue->progress(2, $message, $progress);
|
||||
return $this;
|
||||
@ -90,7 +92,7 @@ abstract class Queue
|
||||
* @param string $message 消息内容
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function setQueueSuccess($message)
|
||||
protected function setQueueSuccess(string $message): void
|
||||
{
|
||||
throw new Exception($message, 3, $this->queue->code);
|
||||
}
|
||||
@ -100,7 +102,7 @@ abstract class Queue
|
||||
* @param string $message 消息内容
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function setQueueError($message)
|
||||
protected function setQueueError(string $message): void
|
||||
{
|
||||
throw new Exception($message, 4, $this->queue->code);
|
||||
}
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 代码仓库:https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin;
|
||||
|
||||
use think\App;
|
||||
@ -43,7 +45,7 @@ abstract class Service
|
||||
|
||||
/**
|
||||
* 初始化服务
|
||||
* @return $this
|
||||
* @return static
|
||||
*/
|
||||
protected function initialize()
|
||||
{
|
||||
|
16
vendor/zoujingli/think-library/src/Storage.php
vendored
16
vendor/zoujingli/think-library/src/Storage.php
vendored
@ -13,6 +13,8 @@
|
||||
// | github 仓库地址 :https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin;
|
||||
|
||||
use think\admin\storage\LocalStorage;
|
||||
@ -50,7 +52,7 @@ abstract class Storage
|
||||
* 链接类型
|
||||
* @var string
|
||||
*/
|
||||
protected $linkType;
|
||||
protected $type;
|
||||
|
||||
/**
|
||||
* Storage constructor.
|
||||
@ -62,7 +64,7 @@ abstract class Storage
|
||||
public function __construct(App $app)
|
||||
{
|
||||
$this->app = $app;
|
||||
$this->linkType = sysconf('storage.link_type');
|
||||
$this->type = sysconf('storage.link_type');
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
@ -81,7 +83,7 @@ abstract class Storage
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public static function __callStatic($method, $arguments)
|
||||
public static function __callStatic(string $method, array $arguments)
|
||||
{
|
||||
if (method_exists($class = static::instance(), $method)) {
|
||||
return call_user_func_array([$class, $method], $arguments);
|
||||
@ -92,7 +94,7 @@ abstract class Storage
|
||||
|
||||
/**
|
||||
* 设置文件驱动名称
|
||||
* @param string $name 驱动名称
|
||||
* @param null|string $name 驱动名称
|
||||
* @return static
|
||||
* @throws Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
@ -175,7 +177,7 @@ abstract class Storage
|
||||
|
||||
/**
|
||||
* 使用CURL读取网络资源
|
||||
* @param string $url
|
||||
* @param string $url 资源地址
|
||||
* @return string
|
||||
*/
|
||||
public static function curlGet(string $url)
|
||||
@ -193,12 +195,12 @@ abstract class Storage
|
||||
|
||||
/**
|
||||
* 获取下载链接后缀
|
||||
* @param string $attname 下载名称
|
||||
* @param null|string $attname 下载名称
|
||||
* @return string
|
||||
*/
|
||||
protected function getSuffix(string $attname = null): string
|
||||
{
|
||||
if ($this->linkType === 'full') {
|
||||
if ($this->type === 'full') {
|
||||
if (is_string($attname) && strlen($attname) > 0) {
|
||||
return "?attname=" . urlencode($attname);
|
||||
}
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 仓库地址 :https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\command;
|
||||
|
||||
use think\admin\Command;
|
||||
@ -39,11 +41,14 @@ class Database extends Command
|
||||
* @param Output $output
|
||||
* @return mixed
|
||||
*/
|
||||
public function execute(Input $input, Output $output)
|
||||
public function execute(Input $input, Output $output): void
|
||||
{
|
||||
$do = $input->getArgument('action');
|
||||
if (in_array($do, ['repair', 'optimize'])) return $this->{"_{$do}"}();
|
||||
$this->output->error("Wrong operation, currently allow repair|optimize");
|
||||
$method = $input->getArgument('action');
|
||||
if (in_array($method, ['repair', 'optimize'])) {
|
||||
$this->{"_{$method}"}();
|
||||
} else {
|
||||
$this->output->error("Wrong operation, currently allow repair|optimize");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -53,7 +58,7 @@ class Database extends Command
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
protected function _repair()
|
||||
protected function _repair(): void
|
||||
{
|
||||
$this->setQueueProgress("正在获取需要修复的数据表", 0);
|
||||
[$total, $used] = [count($tables = $this->getTables()), 0];
|
||||
@ -72,7 +77,7 @@ class Database extends Command
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
protected function _optimize()
|
||||
protected function _optimize(): void
|
||||
{
|
||||
$this->setQueueProgress("正在获取需要优化的数据表", 0);
|
||||
[$total, $used] = [count($tables = $this->getTables()), 0];
|
||||
@ -88,7 +93,7 @@ class Database extends Command
|
||||
* 获取数据库的数据表
|
||||
* @return array
|
||||
*/
|
||||
protected function getTables()
|
||||
protected function getTables(): array
|
||||
{
|
||||
$tables = [];
|
||||
foreach ($this->app->db->query("show tables") as $item) {
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 仓库地址 :https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\command;
|
||||
|
||||
use think\admin\Command;
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 仓库地址 :https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\command;
|
||||
|
||||
use Psr\Log\NullLogger;
|
||||
@ -310,7 +312,7 @@ class Queue extends Command
|
||||
* @param boolean $isSplit 是否分隔
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
protected function updateQueue($status, $message, $isSplit = true)
|
||||
protected function updateQueue(int $status, string $message, bool $isSplit = true)
|
||||
{
|
||||
// 更新当前任务
|
||||
$info = trim(is_string($message) ? $message : '');
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 仓库地址 :https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\command;
|
||||
|
||||
use think\admin\Command;
|
||||
|
32
vendor/zoujingli/think-library/src/common.php
vendored
32
vendor/zoujingli/think-library/src/common.php
vendored
@ -26,7 +26,7 @@ if (!function_exists('p')) {
|
||||
* 打印输出数据到文件
|
||||
* @param mixed $data 输出的数据
|
||||
* @param boolean $new 强制替换文件
|
||||
* @param string $file 保存文件名称
|
||||
* @param null|string $file 保存文件名称
|
||||
*/
|
||||
function p($data, $new = false, $file = null)
|
||||
{
|
||||
@ -112,7 +112,7 @@ if (!function_exists('sysqueue')) {
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
function sysqueue($title, $command, $later = 0, $data = [], $rscript = 1, $loops = 0)
|
||||
function sysqueue(string $title, string $command, int $later = 0, array $data = [], int $rscript = 1, int $loops = 0): string
|
||||
{
|
||||
return QueueService::instance()->register($title, $command, $later, $data, $rscript, $loops)->code;
|
||||
}
|
||||
@ -120,10 +120,10 @@ if (!function_exists('sysqueue')) {
|
||||
if (!function_exists('systoken')) {
|
||||
/**
|
||||
* 生成 CSRF-TOKEN 参数
|
||||
* @param string $node
|
||||
* @param null|string $node
|
||||
* @return string
|
||||
*/
|
||||
function systoken($node = null)
|
||||
function systoken($node = null): string
|
||||
{
|
||||
$result = TokenService::instance()->buildFormToken($node);
|
||||
return $result['token'] ?? '';
|
||||
@ -136,7 +136,7 @@ if (!function_exists('sysoplog')) {
|
||||
* @param string $content 日志内容
|
||||
* @return boolean
|
||||
*/
|
||||
function sysoplog($action, $content)
|
||||
function sysoplog(string $action, string $content)
|
||||
{
|
||||
return SystemService::instance()->setOplog($action, $content);
|
||||
}
|
||||
@ -147,7 +147,7 @@ if (!function_exists('encode')) {
|
||||
* @param string $content
|
||||
* @return string
|
||||
*/
|
||||
function encode($content)
|
||||
function encode(string $content): string
|
||||
{
|
||||
[$chars, $length] = ['', strlen($string = iconv('UTF-8', 'GBK//TRANSLIT', $content))];
|
||||
for ($i = 0; $i < $length; $i++) $chars .= str_pad(base_convert(ord($string[$i]), 10, 36), 2, 0, 0);
|
||||
@ -160,7 +160,7 @@ if (!function_exists('decode')) {
|
||||
* @param string $content
|
||||
* @return string
|
||||
*/
|
||||
function decode($content)
|
||||
function decode(string $content): string
|
||||
{
|
||||
$chars = '';
|
||||
foreach (str_split($content, 2) as $char) {
|
||||
@ -177,7 +177,7 @@ if (!function_exists('http_get')) {
|
||||
* @param array $options CURL参数
|
||||
* @return boolean|string
|
||||
*/
|
||||
function http_get($url, $query = [], $options = [])
|
||||
function http_get(string $url, $query = [], array $options = [])
|
||||
{
|
||||
return HttpExtend::get($url, $query, $options);
|
||||
}
|
||||
@ -190,7 +190,7 @@ if (!function_exists('http_post')) {
|
||||
* @param array $options CURL参数
|
||||
* @return boolean|string
|
||||
*/
|
||||
function http_post($url, $data, $options = [])
|
||||
function http_post(string $url, $data, array $options = [])
|
||||
{
|
||||
return HttpExtend::post($url, $data, $options);
|
||||
}
|
||||
@ -207,7 +207,7 @@ if (!function_exists('data_save')) {
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
function data_save($dbQuery, $data, $key = 'id', $where = [])
|
||||
function data_save($dbQuery, array $data, string $key = 'id', array $where = [])
|
||||
{
|
||||
return SystemService::instance()->save($dbQuery, $data, $key, $where);
|
||||
}
|
||||
@ -215,10 +215,10 @@ if (!function_exists('data_save')) {
|
||||
if (!function_exists('format_bytes')) {
|
||||
/**
|
||||
* 文件字节单位转换
|
||||
* @param integer $size
|
||||
* @param string|integer $size
|
||||
* @return string
|
||||
*/
|
||||
function format_bytes($size)
|
||||
function format_bytes($size): string
|
||||
{
|
||||
if (is_numeric($size)) {
|
||||
$units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
||||
@ -232,7 +232,7 @@ if (!function_exists('format_bytes')) {
|
||||
if (!function_exists('format_datetime')) {
|
||||
/**
|
||||
* 日期格式标准输出
|
||||
* @param string $datetime 输入日期
|
||||
* @param int|string $datetime 输入日期
|
||||
* @param string $format 输出格式
|
||||
* @return false|string
|
||||
*/
|
||||
@ -252,7 +252,7 @@ if (!function_exists('enbase64url')) {
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
function enbase64url(string $string)
|
||||
function enbase64url(string $string): string
|
||||
{
|
||||
return rtrim(strtr(base64_encode($string), '+/', '-_'), '=');
|
||||
}
|
||||
@ -263,7 +263,7 @@ if (!function_exists('debase64url')) {
|
||||
* @param string $string
|
||||
* @return string
|
||||
*/
|
||||
function debase64url(string $string)
|
||||
function debase64url(string $string): string
|
||||
{
|
||||
return base64_decode(str_pad(strtr($string, '-_', '+/'), strlen($string) % 4, '=', STR_PAD_RIGHT));
|
||||
}
|
||||
@ -276,7 +276,7 @@ if (!function_exists('down_file')) {
|
||||
* @param integer $expire 强制本地存储时间
|
||||
* @return string
|
||||
*/
|
||||
function down_file($source, $force = false, $expire = 0)
|
||||
function down_file(string $source, bool $force = false, int $expire = 0)
|
||||
{
|
||||
$result = Storage::down($source, $force, $expire);
|
||||
return $result['url'] ?? $source;
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 代码仓库:https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\extend;
|
||||
|
||||
/**
|
||||
@ -24,8 +26,8 @@ class CodeExtend
|
||||
{
|
||||
/**
|
||||
* 获取随机字符串编码
|
||||
* @param integer $size 字符串长度
|
||||
* @param integer $type 字符串类型(1纯数字,2纯字母,3数字字母)
|
||||
* @param integer $size 编码长度
|
||||
* @param integer $type 编码类型(1纯数字,2纯字母,3数字字母)
|
||||
* @param string $prefix 编码前缀
|
||||
* @return string
|
||||
*/
|
||||
@ -35,39 +37,37 @@ class CodeExtend
|
||||
$chars = 'abcdefghijklmnopqrstuvwxyz';
|
||||
if (intval($type) === 1) $chars = $numbs;
|
||||
if (intval($type) === 3) $chars = "{$numbs}{$chars}";
|
||||
$string = $prefix . $chars[rand(1, strlen($chars) - 1)];
|
||||
if (isset($chars)) while (strlen($string) < $size) {
|
||||
$string .= $chars[rand(0, strlen($chars) - 1)];
|
||||
}
|
||||
return $string;
|
||||
$code = $prefix . $chars[rand(1, strlen($chars) - 1)];
|
||||
while (strlen($code) < $size) $code .= $chars[rand(0, strlen($chars) - 1)];
|
||||
return $code;
|
||||
}
|
||||
|
||||
/**
|
||||
* 唯一日期编码
|
||||
* @param integer $size
|
||||
* @param string $prefix
|
||||
* @param integer $size 编码长度
|
||||
* @param string $prefix 编码前缀
|
||||
* @return string
|
||||
*/
|
||||
public static function uniqidDate(int $size = 16, string $prefix = ''): string
|
||||
{
|
||||
if ($size < 14) $size = 14;
|
||||
$string = $prefix . date('Ymd') . (date('H') + date('i')) . date('s');
|
||||
while (strlen($string) < $size) $string .= rand(0, 9);
|
||||
return $string;
|
||||
$code = $prefix . date('Ymd') . (date('H') + date('i')) . date('s');
|
||||
while (strlen($code) < $size) $code .= rand(0, 9);
|
||||
return $code;
|
||||
}
|
||||
|
||||
/**
|
||||
* 唯一数字编码
|
||||
* @param integer $size
|
||||
* @param string $prefix
|
||||
* @param integer $size 编码长度
|
||||
* @param string $prefix 编码前缀
|
||||
* @return string
|
||||
*/
|
||||
public static function uniqidNumber(int $size = 12, string $prefix = ''): string
|
||||
{
|
||||
$time = time() . '';
|
||||
if ($size < 10) $size = 10;
|
||||
$string = $prefix . (intval($time[0]) + intval($time[1])) . substr($time, 2) . rand(0, 9);
|
||||
while (strlen($string) < $size) $string .= rand(0, 9);
|
||||
return $string;
|
||||
$code = $prefix . (intval($time[0]) + intval($time[1])) . substr($time, 2) . rand(0, 9);
|
||||
while (strlen($code) < $size) $code .= rand(0, 9);
|
||||
return $code;
|
||||
}
|
||||
}
|
@ -13,6 +13,8 @@
|
||||
// | github 代码仓库:https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\extend;
|
||||
|
||||
/**
|
||||
@ -66,17 +68,17 @@ class DataExtend
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据树子ID
|
||||
* 获取数据树子ID集合
|
||||
* @param array $list 数据列表
|
||||
* @param mixed $id 起始ID
|
||||
* @param string $ckey ID_KEY
|
||||
* @param string $pkey PID_KEY
|
||||
* @param mixed $value 起始有效ID值
|
||||
* @param string $ckey 当前主键ID名称
|
||||
* @param string $pkey 上级主键ID名称
|
||||
* @return array
|
||||
*/
|
||||
public static function getArrSubIds(array $list, $id = 0, string $ckey = 'id', string $pkey = 'pid'): array
|
||||
public static function getArrSubIds(array $list, $value = 0, string $ckey = 'id', string $pkey = 'pid'): array
|
||||
{
|
||||
$ids = [intval($id)];
|
||||
foreach ($list as $vo) if (intval($vo[$pkey]) > 0 && intval($vo[$pkey]) === intval($id)) {
|
||||
$ids = [intval($value)];
|
||||
foreach ($list as $vo) if (intval($vo[$pkey]) > 0 && intval($vo[$pkey]) === intval($value)) {
|
||||
$ids = array_merge($ids, static::getArrSubIds($list, intval($vo[$ckey]), $ckey, $pkey));
|
||||
}
|
||||
return $ids;
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 代码仓库:https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\extend;
|
||||
|
||||
/**
|
||||
@ -28,14 +30,16 @@ class ExcelExtend
|
||||
* @param string $name 导出文件名称
|
||||
* @param array $headers 表格头部(一维数组)
|
||||
*/
|
||||
public static function header($name, array $headers)
|
||||
public static function header(string $name, array $headers)
|
||||
{
|
||||
header('Content-Type: application/octet-stream');
|
||||
header("Content-Disposition: attachment; filename=" . iconv('utf-8', 'gbk//TRANSLIT', $name));
|
||||
$handle = fopen('php://output', 'w');
|
||||
foreach ($headers as $key => $value) $headers[$key] = iconv("utf-8", "gbk//TRANSLIT", $value);
|
||||
fputcsv($handle, $headers);
|
||||
if (is_resource($handle)) fclose($handle);
|
||||
if (is_resource($handle)) {
|
||||
fclose($handle);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -43,7 +47,7 @@ class ExcelExtend
|
||||
* @param array $list 数据列表(二维数组)
|
||||
* @param array $rules 数据规则(一维数组)
|
||||
*/
|
||||
public static function body(array $list, array $rules)
|
||||
public static function body(array $list, array $rules): void
|
||||
{
|
||||
$handle = fopen('php://output', 'w');
|
||||
foreach ($list as $data) {
|
||||
@ -53,16 +57,18 @@ class ExcelExtend
|
||||
}
|
||||
fputcsv($handle, $rows);
|
||||
}
|
||||
if (is_resource($handle)) fclose($handle);
|
||||
if (is_resource($handle)) {
|
||||
fclose($handle);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据数组key查询(可带点规则)
|
||||
* @param array $data 数据
|
||||
* @param string $rule 规则,如: order.order_no
|
||||
* @return mixed
|
||||
* @return string
|
||||
*/
|
||||
public static function parseKeyDotValue(array $data, $rule)
|
||||
public static function parseKeyDotValue(array $data, string $rule): string
|
||||
{
|
||||
[$temp, $attr] = [$data, explode('.', trim($rule, '.'))];
|
||||
while ($key = array_shift($attr)) $temp = $temp[$key] ?? $temp;
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 仓库地址 :https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\extend;
|
||||
|
||||
/**
|
||||
@ -25,13 +27,13 @@ class HttpExtend
|
||||
/**
|
||||
* 以 GET 模拟网络请求
|
||||
* @param string $location HTTP请求地址
|
||||
* @param array|string $query GET请求参数
|
||||
* @param array|string $data GET请求参数
|
||||
* @param array $options CURL请求参数
|
||||
* @return boolean|string
|
||||
*/
|
||||
public static function get(string $location, $query = [], array $options = [])
|
||||
public static function get(string $location, $data = [], array $options = [])
|
||||
{
|
||||
$options['query'] = $query;
|
||||
$options['query'] = $data;
|
||||
return static::request('get', $location, $options);
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 仓库地址 :https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\extend;
|
||||
|
||||
/**
|
||||
@ -55,6 +57,10 @@ class JsonRpcClient
|
||||
{
|
||||
// Performs the HTTP POST
|
||||
$options = [
|
||||
'ssl' => [
|
||||
'verify_peer' => false,
|
||||
'verify_peer_name' => false,
|
||||
],
|
||||
'http' => [
|
||||
'method' => 'POST',
|
||||
'header' => 'Content-type: application/json',
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 仓库地址 :https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\extend;
|
||||
|
||||
use think\App;
|
||||
|
@ -16,6 +16,8 @@
|
||||
// | 为减少 Composer 组件数量优化加载速度,直接将源码复制于此,在此表示感谢原作者 !
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\extend;
|
||||
|
||||
/**
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 仓库地址 :https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\helper;
|
||||
|
||||
use think\admin\Helper;
|
||||
@ -59,7 +61,7 @@ class DeleteHelper extends Helper
|
||||
if (in_array('is_deleted', $fields)) $data['is_deleted'] = 1;
|
||||
}
|
||||
// 执行删除操作
|
||||
$result = empty($data) ? $query->delete() : $query->update($data);
|
||||
$result = (empty($data) ? $query->delete() : $query->update($data)) !== false;
|
||||
// 结果回调处理
|
||||
if (false === $this->class->callback('_delete_result', $result)) {
|
||||
return $result;
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 仓库地址 :https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\helper;
|
||||
|
||||
use think\admin\Helper;
|
||||
@ -43,22 +45,20 @@ class FormHelper extends Helper
|
||||
$query = $this->buildQuery($dbQuery);
|
||||
$field = $field ?: ($query->getPk() ?: 'id');
|
||||
$value = input($field, $data[$field] ?? null);
|
||||
// GET请求, 获取数据并显示表单页面
|
||||
if ($this->app->request->isGet()) {
|
||||
if ($value !== null) {
|
||||
$find = $query->where([$field => $value])->where($where)->find();
|
||||
if (!empty($find) && is_array($find)) $data = array_merge($data, $find);
|
||||
}
|
||||
if (false !== $this->class->callback('_form_filter', $data)) {
|
||||
return $this->class->fetch($template, ['vo' => $data]);
|
||||
$this->class->fetch($template, ['vo' => $data]);
|
||||
} else {
|
||||
return $data;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
// POST请求, 数据自动存库处理
|
||||
if ($this->app->request->isPost()) {
|
||||
} elseif ($this->app->request->isPost()) {
|
||||
$data = array_merge($this->app->request->post(), $data);
|
||||
if (false !== $this->class->callback('_form_filter', $data, $where)) {
|
||||
$result = data_save($query, $data, $field, $where);
|
||||
$result = data_save($query, $data, $field, $where) !== false;
|
||||
if (false !== $this->class->callback('_form_result', $result, $data)) {
|
||||
if ($result !== false) {
|
||||
$this->class->success(lang('think_library_form_success'));
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 仓库地址 :https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\helper;
|
||||
|
||||
use think\admin\Helper;
|
||||
@ -39,7 +41,7 @@ class PageHelper extends Helper
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function init($dbQuery, $page = true, $display = true, $total = false, $limit = 0, $template = '')
|
||||
public function init($dbQuery, bool $page = true, bool $display = true, $total = false, int $limit = 0, string $template = '')
|
||||
{
|
||||
$this->query = $this->buildQuery($dbQuery);
|
||||
// 数据列表排序自动处理
|
||||
@ -52,7 +54,7 @@ class PageHelper extends Helper
|
||||
$limit = intval($limit);
|
||||
} else {
|
||||
$limit = $this->app->request->get('limit', $this->app->cookie->get('limit'));
|
||||
$this->app->cookie->set('limit', $limit = intval($limit >= 10 ? $limit : 20));
|
||||
$this->app->cookie->set('limit', ($limit = intval($limit >= 10 ? $limit : 20)) . '');
|
||||
}
|
||||
[$options, $query] = ['', $this->app->request->get()];
|
||||
$pager = $this->query->paginate(['list_rows' => $limit, 'query' => $query], $total);
|
||||
@ -78,7 +80,7 @@ class PageHelper extends Helper
|
||||
$result = ['list' => $this->query->select()->toArray()];
|
||||
}
|
||||
if (false !== $this->class->callback('_page_filter', $result['list']) && $display) {
|
||||
return $this->class->fetch($template, $result);
|
||||
$this->class->fetch($template, $result);
|
||||
} else {
|
||||
return $result;
|
||||
}
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 仓库地址 :https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\helper;
|
||||
|
||||
use think\admin\Helper;
|
||||
@ -48,7 +50,7 @@ class QueryHelper extends Helper
|
||||
* @param array|string|null $input 输入数据
|
||||
* @return $this
|
||||
*/
|
||||
public function init($dbQuery, $input = null)
|
||||
public function init($dbQuery, $input = null): QueryHelper
|
||||
{
|
||||
$this->query = $this->buildQuery($dbQuery);
|
||||
$this->input = $this->_getInputData($input);
|
||||
@ -56,13 +58,13 @@ class QueryHelper extends Helper
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置Like查询条件
|
||||
* 设置 Like 查询条件
|
||||
* @param string|array $fields 查询字段
|
||||
* @param array|string|null $input 输入数据
|
||||
* @param string $alias 别名分割符
|
||||
* @return $this
|
||||
*/
|
||||
public function like($fields, $input = null, $alias = '#')
|
||||
public function like($fields, $input = null, string $alias = '#'): QueryHelper
|
||||
{
|
||||
$data = $this->_getInputData($input ?: $this->input);
|
||||
foreach (is_array($fields) ? $fields : explode(',', $fields) as $field) {
|
||||
@ -84,7 +86,7 @@ class QueryHelper extends Helper
|
||||
* @param string $alias 别名分割符
|
||||
* @return $this
|
||||
*/
|
||||
public function equal($fields, $input = null, $alias = '#')
|
||||
public function equal($fields, $input = null, string $alias = '#'): QueryHelper
|
||||
{
|
||||
$data = $this->_getInputData($input ?: $this->input);
|
||||
foreach (is_array($fields) ? $fields : explode(',', $fields) as $field) {
|
||||
@ -100,14 +102,14 @@ class QueryHelper extends Helper
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置IN区间查询
|
||||
* @param string $fields 查询字段
|
||||
* 设置 IN 区间查询
|
||||
* @param string|array $fields 查询字段
|
||||
* @param string $split 输入分隔符
|
||||
* @param array|string|null $input 输入数据
|
||||
* @param string $alias 别名分割符
|
||||
* @return $this
|
||||
*/
|
||||
public function in($fields, $split = ',', $input = null, $alias = '#')
|
||||
public function in($fields, string $split = ',', $input = null, string $alias = '#'): QueryHelper
|
||||
{
|
||||
$data = $this->_getInputData($input ?: $this->input);
|
||||
foreach (is_array($fields) ? $fields : explode(',', $fields) as $field) {
|
||||
@ -130,7 +132,7 @@ class QueryHelper extends Helper
|
||||
* @param string $alias 别名分割符
|
||||
* @return $this
|
||||
*/
|
||||
public function valueBetween($fields, $split = ' ', $input = null, $alias = '#')
|
||||
public function valueBetween($fields, string $split = ' ', $input = null, string $alias = '#'): QueryHelper
|
||||
{
|
||||
return $this->_setBetweenWhere($fields, $split, $input, $alias);
|
||||
}
|
||||
@ -143,7 +145,7 @@ class QueryHelper extends Helper
|
||||
* @param string $alias 别名分割符
|
||||
* @return $this
|
||||
*/
|
||||
public function dateBetween($fields, $split = ' - ', $input = null, $alias = '#')
|
||||
public function dateBetween($fields, string $split = ' - ', $input = null, string $alias = '#'): QueryHelper
|
||||
{
|
||||
return $this->_setBetweenWhere($fields, $split, $input, $alias, function ($value, $type) {
|
||||
return $type === 'after' ? "{$value} 23:59:59" : "{$value} 00:00:00";
|
||||
@ -158,7 +160,7 @@ class QueryHelper extends Helper
|
||||
* @param string $alias 别名分割符
|
||||
* @return $this
|
||||
*/
|
||||
public function timeBetween($fields, $split = ' - ', $input = null, $alias = '#')
|
||||
public function timeBetween($fields, string $split = ' - ', $input = null, string $alias = '#'): QueryHelper
|
||||
{
|
||||
return $this->_setBetweenWhere($fields, $split, $input, $alias, function ($value, $type) {
|
||||
return $type === 'after' ? strtotime("{$value} 23:59:59") : strtotime("{$value} 00:00:00");
|
||||
@ -177,7 +179,7 @@ class QueryHelper extends Helper
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function page($page = true, $display = true, $total = false, $limit = 0, $template = '')
|
||||
public function page(bool $page = true, bool $display = true, $total = false, int $limit = 0, string $template = '')
|
||||
{
|
||||
return PageHelper::instance()->init($this->query, $page, $display, $total, $limit, $template);
|
||||
}
|
||||
@ -188,7 +190,7 @@ class QueryHelper extends Helper
|
||||
* @param array $args 调用参数内容
|
||||
* @return $this
|
||||
*/
|
||||
public function __call($name, $args)
|
||||
public function __call(string $name, array $args): QueryHelper
|
||||
{
|
||||
if (is_callable($callable = [$this->query, $name])) {
|
||||
call_user_func_array($callable, $args);
|
||||
@ -202,10 +204,10 @@ class QueryHelper extends Helper
|
||||
* @param string $split 输入分隔符
|
||||
* @param array|string|null $input 输入数据
|
||||
* @param string $alias 别名分割符
|
||||
* @param callable $callback
|
||||
* @param callable|null $callback 回调函数
|
||||
* @return $this
|
||||
*/
|
||||
private function _setBetweenWhere($fields, $split = ' ', $input = null, $alias = '#', $callback = null)
|
||||
private function _setBetweenWhere($fields, string $split = ' ', $input = null, string $alias = '#', $callback = null): QueryHelper
|
||||
{
|
||||
$data = $this->_getInputData($input ?: $this->input);
|
||||
foreach (is_array($fields) ? $fields : explode(',', $fields) as $field) {
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 仓库地址 :https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\helper;
|
||||
|
||||
use think\admin\Helper;
|
||||
@ -35,7 +37,7 @@ class SaveHelper extends Helper
|
||||
* @return boolean
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function init($dbQuery, $data = [], $field = '', $where = [])
|
||||
public function init($dbQuery, array $data = [], string $field = '', array $where = [])
|
||||
{
|
||||
$query = $this->buildQuery($dbQuery);
|
||||
$data = $data ?: $this->app->request->post();
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 仓库地址 :https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\helper;
|
||||
|
||||
use think\admin\Helper;
|
||||
@ -55,7 +57,7 @@ class TokenHelper extends Helper
|
||||
* 返回视图内容
|
||||
* @param string $tpl 模板名称
|
||||
* @param array $vars 模板变量
|
||||
* @param string $node CSRF授权节点
|
||||
* @param string|null $node 授权节点
|
||||
*/
|
||||
public function fetchTemplate($tpl = '', $vars = [], $node = null)
|
||||
{
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 仓库地址 :https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\helper;
|
||||
|
||||
use think\admin\Helper;
|
||||
@ -29,7 +31,7 @@ class ValidateHelper extends Helper
|
||||
* 快捷输入并验证( 支持 规则 # 别名 )
|
||||
* @param array $rules 验证规则( 验证信息数组 )
|
||||
* @param string|array $input 输入内容 ( post. 或 get. )
|
||||
* @param boolean $callable 异常处理操作
|
||||
* @param callable|null $callable 异常处理操作
|
||||
* @return array|void
|
||||
* age.require => message // 最大值限定
|
||||
* age.between:1,120 => message // 范围限定
|
||||
@ -38,7 +40,7 @@ class ValidateHelper extends Helper
|
||||
* region.value => value // 固定字段数值内容
|
||||
* 更多规则参照 ThinkPHP 官方的验证类
|
||||
*/
|
||||
public function init(array $rules, $input = '', $callable = null): array
|
||||
public function init(array $rules, string $input = '', $callable = null): array
|
||||
{
|
||||
if (is_string($input)) {
|
||||
$type = trim($input, '.') ?: 'request';
|
||||
@ -67,7 +69,7 @@ class ValidateHelper extends Helper
|
||||
} elseif (is_callable($callable)) {
|
||||
return call_user_func($callable, $validate->getError());
|
||||
} else {
|
||||
return $this->class->error($validate->getError());
|
||||
$this->class->error($validate->getError());
|
||||
}
|
||||
}
|
||||
}
|
@ -12,6 +12,8 @@
|
||||
// 以下代码来自 topthink/think-multi-app,有部分修改以兼容 ThinkAdmin 的需求
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\multiple;
|
||||
|
||||
use Closure;
|
||||
|
@ -12,6 +12,8 @@
|
||||
// 以下代码来自 topthink/think-multi-app,有部分修改以兼容 ThinkAdmin 的需求
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\multiple;
|
||||
|
||||
use think\helper\Str;
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
// 以下代码来自 topthink/think-multi-app,有部分修改以兼容 ThinkAdmin 的需求
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
@ -10,6 +11,8 @@
|
||||
// | Author: yunwuxin <448901948@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\multiple\command;
|
||||
|
||||
use think\console\Command;
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
// 以下代码来自 topthink/think-multi-app,有部分修改以兼容 ThinkAdmin 的需求
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
|
||||
@ -10,6 +11,8 @@
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\multiple\command;
|
||||
|
||||
use think\console\Command;
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 代码仓库:https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\service;
|
||||
|
||||
use think\admin\extend\DataExtend;
|
||||
@ -123,7 +125,7 @@ class AdminService extends Service
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function apply($force = false)
|
||||
public function apply(bool $force = false)
|
||||
{
|
||||
if ($force) $this->clearCache();
|
||||
if (($uid = $this->app->session->get('user.id'))) {
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 代码仓库:https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\service;
|
||||
|
||||
use think\admin\Service;
|
||||
@ -34,11 +36,11 @@ class CaptchaService extends Service
|
||||
private $fontsize = 20; // 指定字体大小
|
||||
|
||||
/**
|
||||
* 服务初始化
|
||||
* 验证码服务初始化
|
||||
* @param array $config
|
||||
* @return static
|
||||
*/
|
||||
public function initialize($config = [])
|
||||
public function initialize(array $config = [])
|
||||
{
|
||||
// 动态配置属性
|
||||
foreach ($config as $k => $v) if (isset($this->$k)) $this->$k = $v;
|
||||
@ -62,7 +64,7 @@ class CaptchaService extends Service
|
||||
* @param array $config
|
||||
* @return $this
|
||||
*/
|
||||
public function config($config = [])
|
||||
public function config(array $config = [])
|
||||
{
|
||||
return $this->initialize($config);
|
||||
}
|
||||
@ -110,7 +112,7 @@ class CaptchaService extends Service
|
||||
/**
|
||||
* 检查验证码是否正确
|
||||
* @param string $code 需要验证的值
|
||||
* @param string $uniqid 验证码编号
|
||||
* @param string|null $uniqid 验证码编号
|
||||
* @return boolean
|
||||
*/
|
||||
public function check(string $code, $uniqid = null): bool
|
||||
@ -159,7 +161,7 @@ class CaptchaService extends Service
|
||||
for ($i = 0; $i < $this->length; $i++) {
|
||||
$fontcolor = imagecolorallocate($img, mt_rand(0, 156), mt_rand(0, 156), mt_rand(0, 156));
|
||||
if (function_exists('imagettftext')) {
|
||||
imagettftext($img, $this->fontsize, mt_rand(-30, 30), $_x * $i + mt_rand(1, 5), $this->height / 1.4, $fontcolor, $this->fontfile, $this->code[$i]);
|
||||
imagettftext($img, $this->fontsize, mt_rand(-30, 30), intval($_x * $i + mt_rand(1, 5)), intval($this->height / 1.4), $fontcolor, $this->fontfile, $this->code[$i]);
|
||||
} else {
|
||||
imagestring($img, 15, $_x * $i + mt_rand(10, 15), mt_rand(10, 30), $this->code[$i], $fontcolor);
|
||||
}
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 代码仓库:https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\service;
|
||||
|
||||
use think\admin\extend\CodeExtend;
|
||||
@ -109,7 +111,7 @@ class ExpressService extends Service
|
||||
* @param string $number 快递单单号
|
||||
* @return mixed
|
||||
*/
|
||||
private function doExpress($code, $number)
|
||||
private function doExpress(string $code, string $number)
|
||||
{
|
||||
$qid = CodeExtend::uniqidNumber(19, '7740');
|
||||
$url = "{$this->getExpressQueryApi()}&appid=4001&nu={$number}&com={$code}&qid={$qid}&new_need_di=1&source_xcx=0&vcode=&token=&sourceId=4155&cb=callback";
|
||||
@ -120,7 +122,7 @@ class ExpressService extends Service
|
||||
* 获取快递查询接口
|
||||
* @return string
|
||||
*/
|
||||
private function getExpressQueryApi()
|
||||
private function getExpressQueryApi(): string
|
||||
{
|
||||
if (preg_match('/"expSearchApi":.*?"(.*?)",/', $this->getWapBaiduHtml(), $matches)) {
|
||||
return str_replace('\\', '', $matches[1]);
|
||||
@ -135,7 +137,7 @@ class ExpressService extends Service
|
||||
* 获取百度WAP快递HTML(用于后面的抓取关键值)
|
||||
* @return string
|
||||
*/
|
||||
private function getWapBaiduHtml()
|
||||
private function getWapBaiduHtml(): string
|
||||
{
|
||||
$content = $this->app->cache->get('express_kuaidi_html', '');
|
||||
while (empty($content) || stripos($content, '"expSearchApi":') === -1) {
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 代码仓库:https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\service;
|
||||
|
||||
use think\admin\extend\HttpExtend;
|
||||
@ -79,7 +81,7 @@ class InterfaceService extends Service
|
||||
* @param boolean $debug
|
||||
* @return $this
|
||||
*/
|
||||
public function debug($debug)
|
||||
public function debug(bool $debug): InterfaceService
|
||||
{
|
||||
$this->debug = boolval($debug);
|
||||
return $this;
|
||||
@ -89,7 +91,7 @@ class InterfaceService extends Service
|
||||
* 获取接口账号
|
||||
* @return string
|
||||
*/
|
||||
public function getAppid()
|
||||
public function getAppid(): string
|
||||
{
|
||||
return $this->appid;
|
||||
}
|
||||
@ -98,7 +100,7 @@ class InterfaceService extends Service
|
||||
* 获取接口地址
|
||||
* @return string
|
||||
*/
|
||||
public function getBaseUrl()
|
||||
public function getBaseUrl(): string
|
||||
{
|
||||
return $this->baseurl;
|
||||
}
|
||||
@ -109,7 +111,7 @@ class InterfaceService extends Service
|
||||
* @param string $appkey 接口密钥
|
||||
* @return $this
|
||||
*/
|
||||
public function setAuth($appid, $appkey)
|
||||
public function setAuth(string $appid, string $appkey): InterfaceService
|
||||
{
|
||||
$this->appid = $appid;
|
||||
$this->appkey = $appkey;
|
||||
@ -121,7 +123,7 @@ class InterfaceService extends Service
|
||||
* @param string $getway
|
||||
* @return $this
|
||||
*/
|
||||
public function getway(string $getway)
|
||||
public function getway(string $getway): InterfaceService
|
||||
{
|
||||
$this->baseurl = $getway;
|
||||
return $this;
|
||||
@ -165,7 +167,7 @@ class InterfaceService extends Service
|
||||
* 显示检查结果
|
||||
* @return $this
|
||||
*/
|
||||
public function showCheck()
|
||||
public function showCheck(): InterfaceService
|
||||
{
|
||||
if ($this->debug) return $this;
|
||||
if (is_null($check = $this->checkInput())) {
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 代码仓库:https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\service;
|
||||
|
||||
use think\admin\extend\DataExtend;
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 代码仓库:https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\service;
|
||||
|
||||
use think\admin\extend\HttpExtend;
|
||||
@ -66,7 +68,7 @@ class MessageService extends Service
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
protected function initialize()
|
||||
protected function initialize(): MessageService
|
||||
{
|
||||
$this->table = 'SystemMessageHistory';
|
||||
$this->chinaUsername = sysconf('sms_zt.china_username');
|
||||
@ -82,7 +84,7 @@ class MessageService extends Service
|
||||
* @param string $password 账号密码
|
||||
* @return $this
|
||||
*/
|
||||
public function configChina($username, $password): MessageService
|
||||
public function configChina(string $username, string $password): MessageService
|
||||
{
|
||||
$this->chinaUsername = $username;
|
||||
$this->chinaPassword = $password;
|
||||
@ -95,7 +97,7 @@ class MessageService extends Service
|
||||
* @param string $password 账号密码
|
||||
* @return $this
|
||||
*/
|
||||
public function configGlobe($username, $password): MessageService
|
||||
public function configGlobe(string $username, string $password): MessageService
|
||||
{
|
||||
$this->globeUsername = $username;
|
||||
$this->globePassword = $password;
|
||||
@ -107,7 +109,7 @@ class MessageService extends Service
|
||||
* @param string $table
|
||||
* @return $this
|
||||
*/
|
||||
public function setSaveTable($table): MessageService
|
||||
public function setSaveTable(string $table): MessageService
|
||||
{
|
||||
$this->table = $table;
|
||||
return $this;
|
||||
@ -119,7 +121,7 @@ class MessageService extends Service
|
||||
* @param array $params
|
||||
* @return string
|
||||
*/
|
||||
public function buildContent($content, array $params = [])
|
||||
public function buildContent(string $content, array $params = []): string
|
||||
{
|
||||
foreach ($params as $key => $value) {
|
||||
$content = str_replace("{{$key}}", $value, $content);
|
||||
@ -154,7 +156,7 @@ class MessageService extends Service
|
||||
|
||||
/**
|
||||
* 发送国内短信验证码
|
||||
* @param string $phone 目标手机
|
||||
* @param mixed $phone 目标手机
|
||||
* @param integer $wait 等待时间
|
||||
* @param string $type 短信模板
|
||||
* @return array
|
||||
@ -189,7 +191,7 @@ class MessageService extends Service
|
||||
* @param string $type 短信模板
|
||||
* @return boolean
|
||||
*/
|
||||
public function check($phone, $code, $type = 'sms_reg_template')
|
||||
public function check($phone, $code, string $type = 'sms_reg_template'): bool
|
||||
{
|
||||
$cache = $this->app->cache->get($cachekey = "{$type}_{$phone}", []);
|
||||
return is_array($cache) && isset($cache['code']) && $cache['code'] == $code;
|
||||
@ -243,7 +245,7 @@ class MessageService extends Service
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function sendGlobeSms($code, $mobile, $content)
|
||||
public function sendGlobeSms($code, $mobile, string $content): bool
|
||||
{
|
||||
$tkey = date("YmdHis");
|
||||
$result = HttpExtend::get('http://intl.zthysms.com/intSendSms.do', [
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 仓库地址 :https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\service;
|
||||
|
||||
use think\admin\extend\HttpExtend;
|
||||
@ -52,8 +54,8 @@ class ModuleService extends Service
|
||||
{
|
||||
$this->root = $this->app->getRootPath();
|
||||
$this->version = trim(Library::VERSION, 'v');
|
||||
$maxver = strstr($this->version, '.', true);
|
||||
$this->server = "https://v{$maxver}.thinkadmin.top";
|
||||
$maxVersion = strstr($this->version, '.', true);
|
||||
$this->server = "https://v{$maxVersion}.thinkadmin.top";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -120,7 +122,7 @@ class ModuleService extends Service
|
||||
* @param string $name 模块名称
|
||||
* @return array
|
||||
*/
|
||||
public function install($name): array
|
||||
public function install(string $name): array
|
||||
{
|
||||
$this->app->cache->set('moduleOnlineData', []);
|
||||
$data = $this->grenerateDifference(['app' . '/' . $name]);
|
||||
@ -194,10 +196,6 @@ class ModuleService extends Service
|
||||
if (stripos($name, '..') !== false) {
|
||||
return false;
|
||||
}
|
||||
// 禁止非官方演示项目下载,不支持通过指令更新
|
||||
// if (!SystemService::instance()->checkRunMode('dev')) {
|
||||
// return false;
|
||||
// }
|
||||
// 禁止下载数据库配置文件
|
||||
if (stripos(strtr($name, '\\', '/'), 'config/database') !== false) {
|
||||
return false;
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 代码仓库:https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\service;
|
||||
|
||||
use think\admin\Service;
|
||||
@ -108,7 +110,7 @@ class NodeService extends Service
|
||||
$data[$prefix] = $this->_parseComment($class->getDocComment(), $classname);
|
||||
foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
|
||||
if (in_array($metname = $method->getName(), $ignores)) continue;
|
||||
$data[strtolower("{$prefix}/{$metname}")] = $this->_parseComment($method->getDocComment(), $metname);
|
||||
$data[strtolower("{$prefix}/{$metname}")] = $this->_parseComment($method->getDocComment() ?: '', $metname);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 代码仓库:https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\service;
|
||||
|
||||
use think\admin\Service;
|
||||
@ -50,7 +52,7 @@ class ProcessService extends Service
|
||||
* @param string $command 任务指令
|
||||
* @return $this
|
||||
*/
|
||||
public function create($command)
|
||||
public function create(string $command): ProcessService
|
||||
{
|
||||
if ($this->iswin()) {
|
||||
$this->exec(__DIR__ . "/bin/console.exe {$command}");
|
||||
@ -90,7 +92,7 @@ class ProcessService extends Service
|
||||
* @param integer $pid 进程号
|
||||
* @return boolean
|
||||
*/
|
||||
public function close($pid): bool
|
||||
public function close(int $pid): bool
|
||||
{
|
||||
if ($this->iswin()) {
|
||||
$this->exec("wmic process {$pid} call terminate");
|
||||
@ -106,7 +108,7 @@ class ProcessService extends Service
|
||||
* @param boolean $outarr 返回类型
|
||||
* @return string|array
|
||||
*/
|
||||
public function exec($command, $outarr = false)
|
||||
public function exec(string $command, $outarr = false)
|
||||
{
|
||||
exec($command, $output);
|
||||
return $outarr ? $output : join("\n", $output);
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 代码仓库:https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\service;
|
||||
|
||||
use think\admin\extend\CodeExtend;
|
||||
@ -59,7 +61,7 @@ class QueueService extends Service
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function initialize($code = 0)
|
||||
public function initialize($code = 0): QueueService
|
||||
{
|
||||
if (!empty($code)) {
|
||||
$this->code = $code;
|
||||
@ -83,7 +85,7 @@ class QueueService extends Service
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function reset($wait = 0)
|
||||
public function reset($wait = 0): QueueService
|
||||
{
|
||||
if (empty($this->record)) {
|
||||
$this->app->log->error("Qeueu reset failed, Queue {$this->code} data cannot be empty!");
|
||||
@ -103,7 +105,7 @@ class QueueService extends Service
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function addCleanQueue()
|
||||
public function addCleanQueue(): QueueService
|
||||
{
|
||||
return $this->register('定时清理系统任务数据', "xadmin:queue clean", 0, [], 0, 3600);
|
||||
}
|
||||
@ -122,7 +124,7 @@ class QueueService extends Service
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function register($title, $command, $later = 0, $data = [], $rscript = 0, $loops = 0)
|
||||
public function register(string $title, string $command, int $later = 0, array $data = [], int $rscript = 0, int $loops = 0): QueueService
|
||||
{
|
||||
$map = [['title', '=', $title], ['status', 'in', [1, 2]]];
|
||||
if (empty($rscript) && ($queue = $this->app->db->name('SystemQueue')->where($map)->find())) {
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 代码仓库:https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\service;
|
||||
|
||||
use think\admin\Service;
|
||||
@ -47,7 +49,7 @@ class SystemService extends Service
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function set($name, $value = '')
|
||||
public function set(string $name, $value = '')
|
||||
{
|
||||
$this->data = [];
|
||||
[$type, $field] = $this->_parse($name, 'base');
|
||||
@ -75,7 +77,7 @@ class SystemService extends Service
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function get($name = '', $default = '')
|
||||
public function get(string $name = '', string $default = '')
|
||||
{
|
||||
if (empty($this->data)) {
|
||||
$this->app->db->name($this->table)->cache($this->table)->select()->map(function ($item) {
|
||||
@ -107,7 +109,7 @@ class SystemService extends Service
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function save($dbQuery, $data, $key = 'id', array $where = [])
|
||||
public function save($dbQuery, array $data, string $key = 'id', array $where = [])
|
||||
{
|
||||
$val = $data[$key] ?? null;
|
||||
$query = (is_string($dbQuery) ? $this->app->db->name($dbQuery) : $dbQuery)->master()->strict(false)->where($where);
|
||||
@ -121,7 +123,7 @@ class SystemService extends Service
|
||||
* @param string $type 配置类型
|
||||
* @return array
|
||||
*/
|
||||
private function _parse($rule, $type = 'base')
|
||||
private function _parse(string $rule, string $type = 'base'): array
|
||||
{
|
||||
if (stripos($rule, '.') !== false) {
|
||||
[$type, $rule] = explode('.', $rule, 2);
|
||||
@ -138,7 +140,7 @@ class SystemService extends Service
|
||||
* @param boolean|string $domain 域名
|
||||
* @return string
|
||||
*/
|
||||
public function sysuri($url = '', array $vars = [], $suffix = true, $domain = false)
|
||||
public function sysuri(string $url = '', array $vars = [], $suffix = true, $domain = false): string
|
||||
{
|
||||
$location = $this->app->route->buildUrl($url, $vars)->suffix($suffix)->domain($domain)->build();
|
||||
[$d1, $d2, $d3] = [$this->app->config->get('app.default_app'), $this->app->config->get('route.default_controller'), $this->app->config->get('route.default_action')];
|
||||
@ -154,7 +156,7 @@ class SystemService extends Service
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function setData($name, $value)
|
||||
public function setData(string $name, $value)
|
||||
{
|
||||
return $this->save('SystemData', ['name' => $name, 'value' => serialize($value)], 'name');
|
||||
}
|
||||
@ -165,7 +167,7 @@ class SystemService extends Service
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public function getData($name, $default = [])
|
||||
public function getData(string $name, $default = [])
|
||||
{
|
||||
try {
|
||||
$value = $this->app->db->name('SystemData')->where(['name' => $name])->value('value', null);
|
||||
@ -179,12 +181,12 @@ class SystemService extends Service
|
||||
* 写入系统日志内容
|
||||
* @param string $action
|
||||
* @param string $content
|
||||
* @return integer
|
||||
* @return boolean
|
||||
*/
|
||||
public function setOplog($action, $content)
|
||||
public function setOplog(string $action, string $content): bool
|
||||
{
|
||||
$oplog = $this->getOplog($action, $content);
|
||||
return $this->app->db->name('SystemOplog')->insert($oplog);
|
||||
return $this->app->db->name('SystemOplog')->insert($oplog) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -193,7 +195,7 @@ class SystemService extends Service
|
||||
* @param string $content
|
||||
* @return array
|
||||
*/
|
||||
public function getOplog($action, $content)
|
||||
public function getOplog(string $action, string $content): array
|
||||
{
|
||||
return [
|
||||
'node' => NodeService::instance()->getCurrent(),
|
||||
@ -222,7 +224,7 @@ class SystemService extends Service
|
||||
* @param string $type 运行模式(dev|demo|local)
|
||||
* @return boolean
|
||||
*/
|
||||
public function checkRunMode($type = 'dev'): bool
|
||||
public function checkRunMode(string $type = 'dev'): bool
|
||||
{
|
||||
$domain = $this->app->request->host(true);
|
||||
$isDemo = is_numeric(stripos($domain, 'thinkadmin.top'));
|
||||
@ -317,7 +319,6 @@ class SystemService extends Service
|
||||
private function uniqueArray(...$args): array
|
||||
{
|
||||
return array_unique(array_reverse(array_merge(...$args)));
|
||||
// foreach ($unique as $kk => $vv) if ($kk == $vv) unset($unique[$kk]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 代码仓库:https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\service;
|
||||
|
||||
use think\admin\Service;
|
||||
@ -84,8 +86,8 @@ class TokenService extends Service
|
||||
|
||||
/**
|
||||
* 验证 CSRF 是否有效
|
||||
* @param string $token 表单令牌
|
||||
* @param string $node 授权节点
|
||||
* @param null|string $token 表单令牌
|
||||
* @param null|string $node 授权节点
|
||||
* @return boolean
|
||||
*/
|
||||
public function checkFormToken($token = null, $node = null): bool
|
||||
@ -99,7 +101,7 @@ class TokenService extends Service
|
||||
|
||||
/**
|
||||
* 清理表单 CSRF 数据
|
||||
* @param string $token
|
||||
* @param null|string $token
|
||||
* @return $this
|
||||
*/
|
||||
public function clearFormToken($token = null)
|
||||
@ -110,7 +112,7 @@ class TokenService extends Service
|
||||
|
||||
/**
|
||||
* 生成表单 CSRF 数据
|
||||
* @param string $node
|
||||
* @param null|string $node
|
||||
* @return array
|
||||
*/
|
||||
public function buildFormToken($node = null): array
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 代码仓库:https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\service;
|
||||
|
||||
use think\admin\extend\HttpExtend;
|
||||
@ -55,7 +57,7 @@ class ZtSmsService extends Service
|
||||
* @param string $password 账号密码
|
||||
* @return static
|
||||
*/
|
||||
public function setAuth(string $username, string $password)
|
||||
public function setAuth(string $username, string $password): ZtSmsService
|
||||
{
|
||||
$this->username = $username;
|
||||
$this->password = $password;
|
||||
@ -188,10 +190,10 @@ class ZtSmsService extends Service
|
||||
* 发送定时短信
|
||||
* @param string $mobile 发送手机号码
|
||||
* @param string $content 发送短信内容
|
||||
* @param string $time 定时发送时间(为 null 立即发送)
|
||||
* @param integer $time 定时发送时间(为 0 立即发送)
|
||||
* @return array
|
||||
*/
|
||||
public function timeSend(string $mobile, string $content, $time = null): array
|
||||
public function timeSend(string $mobile, string $content, int $time = 0): array
|
||||
{
|
||||
$data = ['mobile' => $mobile, 'content' => $content];
|
||||
if ($time > 0) $data['time'] = $time;
|
||||
@ -280,6 +282,6 @@ class ZtSmsService extends Service
|
||||
9998 => 'JSON解析错误',
|
||||
9999 => '非法请求',
|
||||
];
|
||||
return $arrs[$code] ?? $code;
|
||||
return $arrs[$code] ?? "{$code}";
|
||||
}
|
||||
}
|
@ -13,6 +13,8 @@
|
||||
// | github 仓库地址 :https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\storage;
|
||||
|
||||
use think\admin\extend\HttpExtend;
|
||||
@ -91,10 +93,10 @@ class AliossStorage extends Storage
|
||||
* @param string $name 文件名称
|
||||
* @param string $file 文件内容
|
||||
* @param boolean $safe 安全模式
|
||||
* @param string $attname 下载名称
|
||||
* @param null|string $attname 下载名称
|
||||
* @return array
|
||||
*/
|
||||
public function set($name, $file, $safe = false, $attname = null)
|
||||
public function set(string $name, string $file, $safe = false, $attname = null)
|
||||
{
|
||||
$token = $this->buildUploadToken($name);
|
||||
$data = ['key' => $name];
|
||||
@ -120,7 +122,7 @@ class AliossStorage extends Storage
|
||||
* @param boolean $safe 安全模式
|
||||
* @return false|string
|
||||
*/
|
||||
public function get($name, $safe = false)
|
||||
public function get(string $name, $safe = false)
|
||||
{
|
||||
return static::curlGet($this->url($name, $safe));
|
||||
}
|
||||
@ -131,7 +133,7 @@ class AliossStorage extends Storage
|
||||
* @param boolean $safe 安全模式
|
||||
* @return boolean
|
||||
*/
|
||||
public function del($name, $safe = false)
|
||||
public function del(string $name, $safe = false)
|
||||
{
|
||||
[$file] = explode('?', $name);
|
||||
$result = HttpExtend::request('DELETE', "http://{$this->bucket}.{$this->point}/{$file}", [
|
||||
@ -146,7 +148,7 @@ class AliossStorage extends Storage
|
||||
* @param boolean $safe 安全模式
|
||||
* @return boolean
|
||||
*/
|
||||
public function has($name, $safe = false)
|
||||
public function has(string $name, $safe = false)
|
||||
{
|
||||
$file = $this->delSuffix($name);
|
||||
$result = HttpExtend::request('HEAD', "http://{$this->bucket}.{$this->point}/{$file}", [
|
||||
@ -159,10 +161,10 @@ class AliossStorage extends Storage
|
||||
* 获取文件当前URL地址
|
||||
* @param string $name 文件名称
|
||||
* @param boolean $safe 安全模式
|
||||
* @param string $attname 下载名称
|
||||
* @param null|string $attname 下载名称
|
||||
* @return string
|
||||
*/
|
||||
public function url($name, $safe = false, $attname = null)
|
||||
public function url(string $name, $safe = false, $attname = null): string
|
||||
{
|
||||
return "{$this->prefix}/{$this->delSuffix($name)}{$this->getSuffix($attname)}";
|
||||
}
|
||||
@ -173,7 +175,7 @@ class AliossStorage extends Storage
|
||||
* @param boolean $safe 安全模式
|
||||
* @return string
|
||||
*/
|
||||
public function path($name, $safe = false)
|
||||
public function path(string $name, $safe = false): string
|
||||
{
|
||||
return $this->url($name, $safe);
|
||||
}
|
||||
@ -182,10 +184,10 @@ class AliossStorage extends Storage
|
||||
* 获取文件存储信息
|
||||
* @param string $name 文件名称
|
||||
* @param boolean $safe 安全模式
|
||||
* @param string $attname 下载名称
|
||||
* @param null|string $attname 下载名称
|
||||
* @return array
|
||||
*/
|
||||
public function info($name, $safe = false, $attname = null)
|
||||
public function info(string $name, $safe = false, $attname = null): array
|
||||
{
|
||||
return $this->has($name, $safe) ? [
|
||||
'url' => $this->url($name, $safe, $attname),
|
||||
@ -197,7 +199,7 @@ class AliossStorage extends Storage
|
||||
* 获取文件上传地址
|
||||
* @return string
|
||||
*/
|
||||
public function upload()
|
||||
public function upload(): string
|
||||
{
|
||||
$http = $this->app->request->isSsl() ? 'https' : 'http';
|
||||
return "{$http}://{$this->bucket}.{$this->point}";
|
||||
@ -205,12 +207,12 @@ class AliossStorage extends Storage
|
||||
|
||||
/**
|
||||
* 获取文件上传令牌
|
||||
* @param string $name 文件名称
|
||||
* @param null|string $name 文件名称
|
||||
* @param integer $expires 有效时间
|
||||
* @param string $attname 下载名称
|
||||
* @param null|string $attname 下载名称
|
||||
* @return array
|
||||
*/
|
||||
public function buildUploadToken($name = null, $expires = 3600, $attname = null)
|
||||
public function buildUploadToken($name = null, $expires = 3600, $attname = null): array
|
||||
{
|
||||
$data = [
|
||||
'policy' => base64_encode(json_encode([
|
||||
@ -231,7 +233,7 @@ class AliossStorage extends Storage
|
||||
* @param array $header 请求头信息
|
||||
* @return array
|
||||
*/
|
||||
private function headerSign($method, $soruce, $header = [])
|
||||
private function headerSign(string $method, string $soruce, array $header = []): array
|
||||
{
|
||||
if (empty($header['Date'])) $header['Date'] = gmdate('D, d M Y H:i:s \G\M\T');
|
||||
if (empty($header['Content-Type'])) $header['Content-Type'] = 'application/xml';
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 仓库地址 :https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\storage;
|
||||
|
||||
use think\admin\Storage;
|
||||
@ -53,7 +55,7 @@ class LocalStorage extends Storage
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public static function instance($name = null)
|
||||
public static function instance($name = null): LocalStorage
|
||||
{
|
||||
return parent::instance('local');
|
||||
}
|
||||
@ -63,10 +65,10 @@ class LocalStorage extends Storage
|
||||
* @param string $name 文件名称
|
||||
* @param string $file 文件内容
|
||||
* @param boolean $safe 安全模式
|
||||
* @param string $attname 下载名称
|
||||
* @param null|string $attname 下载名称
|
||||
* @return array
|
||||
*/
|
||||
public function set($name, $file, $safe = false, $attname = null)
|
||||
public function set(string $name, string $file, bool $safe = false, $attname = null)
|
||||
{
|
||||
try {
|
||||
$path = $this->path($name, $safe);
|
||||
@ -74,7 +76,7 @@ class LocalStorage extends Storage
|
||||
if (file_put_contents($path, $file)) {
|
||||
return $this->info($name, $safe, $attname);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Exception $exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@ -85,7 +87,7 @@ class LocalStorage extends Storage
|
||||
* @param boolean $safe 安全模式
|
||||
* @return string
|
||||
*/
|
||||
public function get($name, $safe = false)
|
||||
public function get(string $name, bool $safe = false)
|
||||
{
|
||||
if (!$this->has($name, $safe)) return '';
|
||||
return static::curlGet($this->path($name, $safe));
|
||||
@ -97,7 +99,7 @@ class LocalStorage extends Storage
|
||||
* @param boolean $safe 安全模式
|
||||
* @return boolean
|
||||
*/
|
||||
public function del($name, $safe = false)
|
||||
public function del(string $name, bool $safe = false)
|
||||
{
|
||||
if ($this->has($name, $safe)) {
|
||||
return @unlink($this->path($name, $safe));
|
||||
@ -112,7 +114,7 @@ class LocalStorage extends Storage
|
||||
* @param boolean $safe 安全模式
|
||||
* @return boolean
|
||||
*/
|
||||
public function has($name, $safe = false)
|
||||
public function has(string $name, bool $safe = false): bool
|
||||
{
|
||||
return file_exists($this->path($name, $safe));
|
||||
}
|
||||
@ -121,10 +123,10 @@ class LocalStorage extends Storage
|
||||
* 获取文件当前URL地址
|
||||
* @param string $name 文件名称
|
||||
* @param boolean $safe 安全模式
|
||||
* @param string $attname 下载名称
|
||||
* @return string|null
|
||||
* @param null|string $attname 下载名称
|
||||
* @return string
|
||||
*/
|
||||
public function url($name, $safe = false, $attname = null)
|
||||
public function url(string $name, bool $safe = false, $attname = null): string
|
||||
{
|
||||
return $safe ? $name : "{$this->prefix}/upload/{$this->delSuffix($name)}{$this->getSuffix($attname)}";
|
||||
}
|
||||
@ -135,7 +137,7 @@ class LocalStorage extends Storage
|
||||
* @param boolean $safe 安全模式
|
||||
* @return string
|
||||
*/
|
||||
public function path($name, $safe = false)
|
||||
public function path(string $name, bool $safe = false): string
|
||||
{
|
||||
$root = $this->app->getRootPath();
|
||||
$path = $safe ? 'safefile' : 'public/upload';
|
||||
@ -146,10 +148,10 @@ class LocalStorage extends Storage
|
||||
* 获取文件存储信息
|
||||
* @param string $name 文件名称
|
||||
* @param boolean $safe 安全模式
|
||||
* @param string $attname 下载名称
|
||||
* @param null|string $attname 下载名称
|
||||
* @return array
|
||||
*/
|
||||
public function info($name, $safe = false, $attname = null)
|
||||
public function info(string $name, bool $safe = false, $attname = null): array
|
||||
{
|
||||
return $this->has($name, $safe) ? [
|
||||
'url' => $this->url($name, $safe, $attname),
|
||||
@ -161,7 +163,7 @@ class LocalStorage extends Storage
|
||||
* 获取文件上传地址
|
||||
* @return string
|
||||
*/
|
||||
public function upload()
|
||||
public function upload(): string
|
||||
{
|
||||
return url('admin/api.upload/file')->build();
|
||||
}
|
||||
|
@ -13,6 +13,8 @@
|
||||
// | github 仓库地址 :https://github.com/zoujingli/ThinkLibrary
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace think\admin\storage;
|
||||
|
||||
use think\admin\extend\HttpExtend;
|
||||
@ -70,14 +72,14 @@ class QiniuStorage extends Storage
|
||||
* @param string $name 文件名称
|
||||
* @param string $file 文件内容
|
||||
* @param boolean $safe 安全模式
|
||||
* @param string $attname 下载名称
|
||||
* @param null|string $attname 下载名称
|
||||
* @return array
|
||||
* @throws \think\Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function set($name, $file, $safe = false, $attname = null)
|
||||
public function set(string $name, string $file, bool $safe = false, $attname = null)
|
||||
{
|
||||
$token = $this->buildUploadToken($name, 3600, $attname);
|
||||
$data = ['key' => $name, 'token' => $token, 'fileName' => $name];
|
||||
@ -93,7 +95,7 @@ class QiniuStorage extends Storage
|
||||
* @param boolean $safe 安全模式
|
||||
* @return string
|
||||
*/
|
||||
public function get($name, $safe = false)
|
||||
public function get(string $name, bool $safe = false)
|
||||
{
|
||||
$url = $this->url($name, $safe) . "?e=" . time();
|
||||
$token = "{$this->accessKey}:{$this->safeBase64(hash_hmac('sha1', $url, $this->secretKey, true))}";
|
||||
@ -106,7 +108,7 @@ class QiniuStorage extends Storage
|
||||
* @param boolean $safe 安全模式
|
||||
* @return boolean|null
|
||||
*/
|
||||
public function del($name, $safe = false)
|
||||
public function del(string $name, bool $safe = false)
|
||||
{
|
||||
[$EncodedEntryURI, $AccessToken] = $this->getAccessToken($name, 'delete');
|
||||
$data = json_decode(HttpExtend::post("http://rs.qiniu.com/delete/{$EncodedEntryURI}", [], [
|
||||
@ -121,7 +123,7 @@ class QiniuStorage extends Storage
|
||||
* @param boolean $safe 安全模式
|
||||
* @return boolean
|
||||
*/
|
||||
public function has($name, $safe = false)
|
||||
public function has(string $name, bool $safe = false): bool
|
||||
{
|
||||
return is_array($this->info($name, $safe));
|
||||
}
|
||||
@ -130,10 +132,10 @@ class QiniuStorage extends Storage
|
||||
* 获取文件当前URL地址
|
||||
* @param string $name 文件名称
|
||||
* @param boolean $safe 安全模式
|
||||
* @param string $attname 下载名称
|
||||
* @param null|string $attname 下载名称
|
||||
* @return string
|
||||
*/
|
||||
public function url($name, $safe = false, $attname = null)
|
||||
public function url(string $name, bool $safe = false, $attname = null): string
|
||||
{
|
||||
return "{$this->prefix}/{$this->delSuffix($name)}{$this->getSuffix($attname)}";
|
||||
}
|
||||
@ -144,7 +146,7 @@ class QiniuStorage extends Storage
|
||||
* @param boolean $safe 安全模式
|
||||
* @return string
|
||||
*/
|
||||
public function path($name, $safe = false)
|
||||
public function path(string $name, bool $safe = false): string
|
||||
{
|
||||
return $this->url($name, $safe);
|
||||
}
|
||||
@ -153,10 +155,10 @@ class QiniuStorage extends Storage
|
||||
* 获取文件存储信息
|
||||
* @param string $name 文件名称
|
||||
* @param boolean $safe 安全模式
|
||||
* @param string $attname 下载名称
|
||||
* @param null|string $attname 下载名称
|
||||
* @return array
|
||||
*/
|
||||
public function info($name, $safe = false, $attname = null)
|
||||
public function info(string $name, bool $safe = false, $attname = null): array
|
||||
{
|
||||
[$entry, $token] = $this->getAccessToken($name);
|
||||
$data = json_decode(HttpExtend::get("http://rs.qiniu.com/stat/{$entry}", [], ['headers' => ["Authorization: QBox {$token}"]]), true);
|
||||
@ -192,12 +194,12 @@ class QiniuStorage extends Storage
|
||||
|
||||
/**
|
||||
* 获取文件上传令牌
|
||||
* @param string $name 文件名称
|
||||
* @param null|string $name 文件名称
|
||||
* @param integer $expires 有效时间
|
||||
* @param string $attname 下载名称
|
||||
* @param null|string $attname 下载名称
|
||||
* @return string
|
||||
*/
|
||||
public function buildUploadToken($name = null, $expires = 3600, $attname = null)
|
||||
public function buildUploadToken($name = null, int $expires = 3600, $attname = null)
|
||||
{
|
||||
$policy = $this->safeBase64(json_encode([
|
||||
"deadline" => time() + $expires, "scope" => is_null($name) ? $this->bucket : "{$this->bucket}:{$name}",
|
||||
@ -213,7 +215,7 @@ class QiniuStorage extends Storage
|
||||
* @param string $content
|
||||
* @return string
|
||||
*/
|
||||
private function safeBase64($content)
|
||||
private function safeBase64(string $content): string
|
||||
{
|
||||
return str_replace(['+', '/'], ['-', '_'], base64_encode($content));
|
||||
}
|
||||
@ -224,7 +226,7 @@ class QiniuStorage extends Storage
|
||||
* @param string $type 操作类型
|
||||
* @return array
|
||||
*/
|
||||
private function getAccessToken($name, $type = 'stat')
|
||||
private function getAccessToken(string $name, $type = 'stat'): array
|
||||
{
|
||||
$entry = $this->safeBase64("{$this->bucket}:{$name}");
|
||||
$sign = hash_hmac('sha1', "/{$type}/{$entry}\n", $this->secretKey, true);
|
||||
|
Loading…
x
Reference in New Issue
Block a user