Skip to content

Commit

Permalink
添加更多扩展函数
Browse files Browse the repository at this point in the history
  • Loading branch information
deatil committed Jul 8, 2024
1 parent 1be717b commit d5804ab
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 51 deletions.
110 changes: 61 additions & 49 deletions src/larke/admin/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,13 @@

if (! function_exists('Larke\\Admin\\success')) {
/**
* 返回成功JSON
* 返回成功 JSON
*
* @param string $message 信息
* @param array $data 数据
* @param array $header 响应头
* @param int $code 状态码
* @return mixed
*
* @create 2020-10-19
* @author deatil
*/
function success(?string $message = null, ?array $data = null, array $header = [], int $code = 0)
{
Expand All @@ -43,16 +40,13 @@ public function json($message = null, $data = null, $header = [], $code = 0)

if (! function_exists('Larke\\Admin\\error')) {
/**
* 返回失败JSON
* 返回失败 JSON
*
* @param string $message 信息
* @param int $code 状态码
* @param array $data 数据
* @param array $header 响应头
* @return mixed
*
* @create 2020-10-19
* @author deatil
*/
function error(?string $message = null, int $code = 1, array $data = [], array $header = [])
{
Expand All @@ -75,9 +69,6 @@ public function json($message = null, $code = 1, $data = [], $header = [])
* @param mixed $params 请求参数
* @param bool $absolute
* @return mixed
*
* @create 2021-2-27
* @author deatil
*/
function route(string $route, mixed $params = [], bool $absolute = true)
{
Expand All @@ -91,9 +82,6 @@ function route(string $route, mixed $params = [], bool $absolute = true)
*
* @param string $route 路由名称
* @return mixed
*
* @create 2021-2-27
* @author deatil
*/
function route_name(string $route)
{
Expand All @@ -107,12 +95,9 @@ function route_name(string $route)
*
* @param string $slug 路由名称
* @param string $method 请求方式,大写字母
* @return mixed
*
* @create 2021-5-6
* @author deatil
* @return bool
*/
function can(string $slug, string $method = 'GET')
function can(string $slug, string $method = 'GET'): bool
{
return app('larke-admin.auth-admin')->hasAccess($slug, $method);
}
Expand All @@ -123,14 +108,11 @@ function can(string $slug, string $method = 'GET')
* 登陆过滤
*
* @param array $excepts 权限列表
* @return mixed
*
* @create 2021-3-3
* @author deatil
* @return void
*/
function authenticate_excepts(array $excepts)
{
return Extension::authenticateExcepts($excepts);
Extension::authenticateExcepts($excepts);
}
}

Expand All @@ -139,14 +121,11 @@ function authenticate_excepts(array $excepts)
* 权限过滤
*
* @param array $excepts 权限列表
* @return mixed
*
* @create 2021-3-3
* @author deatil
* @return void
*/
function permission_excepts(array $excepts)
{
return Extension::permissionExcepts($excepts);
Extension::permissionExcepts($excepts);
}
}

Expand All @@ -156,12 +135,9 @@ function permission_excepts(array $excepts)
*
* @param string $slug 路由name
* @param string $method 请求方式
* @return mixed
*
* @create 2021-3-22
* @author deatil
* @return bool
*/
function check_permission(string $slug, string $method = 'GET')
function check_permission(string $slug, string $method = 'GET'): bool
{
return AuthAdmin::hasAccess($slug, $method);
}
Expand All @@ -174,9 +150,6 @@ function check_permission(string $slug, string $method = 'GET')
* @param string $name 配置关键字
* @param mixed $default 默认值
* @return mixed
*
* @create 2020-12-17
* @author deatil
*/
function config(string $name, mixed $default = null)
{
Expand All @@ -192,9 +165,6 @@ function config(string $name, mixed $default = null)
* @param string $id 序列号
* @param mixed $default 默认
* @return mixed
*
* @create 2020-12-17
* @author deatil
*/
function attachment_url(string $id, mixed $default = null)
{
Expand All @@ -210,9 +180,6 @@ function attachment_url(string $id, mixed $default = null)
* @param string $key 配置关键字
* @param mixed $default 默认值
* @return mixed
*
* @create 2021-3-24
* @author deatil
*/
function extension_config(string $name, string $key = null, mixed $default = null)
{
Expand All @@ -229,14 +196,59 @@ function extension_config(string $name, string $key = null, mixed $default = nul
}
}

if (! function_exists('Larke\\Admin\\extension_installed')) {
/**
* 扩展是否安装
*
* @param string $name 扩展包名
* @return bool
*/
function extension_installed(string $name): bool
{
$extensions = ExtensionModel::getExtensions();

$info = Arr::get($extensions, $name, []);
if (empty($info)) {
return false;
}

return true;
}
}

if (! function_exists('Larke\\Admin\\extension_enabled')) {
/**
* 扩展是否启用
*
* @param string $name 扩展包名
* @return bool
*/
function extension_enabled(string $name): bool
{
$extensions = ExtensionModel::getExtensions();

$info = Arr::get($extensions, $name, []);
if (empty($info)) {
return false;
}

$status = Arr::get($info, 'status', 0);
if ($status != 1) {
return false;
}

return true;
}
}

if (! function_exists('Larke\\Admin\\add_action')) {
/**
* 注册操作
*
* @param string $event 事件名称
* @param mixed $listener 监听操作
* @param bool $sort 排序
* @return $this
* @return void
*/
function add_action(string $event, $listener, int $sort = 1): void
{
Expand Down Expand Up @@ -264,7 +276,7 @@ function do_action($event, ...$var): void
*
* @param string $event 事件名称
* @param mixed $listener 监听操作
* @return $this
* @return bool
*/
function remove_action(string $event, $listener, int $sort = 1): bool
{
Expand All @@ -278,7 +290,7 @@ function remove_action(string $event, $listener, int $sort = 1): bool
*
* @param string $event 事件名称
* @param mixed $listener 监听操作
* @return $this
* @return bool
*/
function has_action(string $event, $listener): bool
{
Expand All @@ -293,7 +305,7 @@ function has_action(string $event, $listener): bool
* @param string $event 事件名称
* @param mixed $listener 监听操作
* @param bool $sort 排序
* @return $this
* @return void
*/
function add_filter(string $event, $listener, int $sort = 1): void
{
Expand Down Expand Up @@ -322,7 +334,7 @@ function apply_filters($event, $params = null, ...$var)
*
* @param string $event 事件名称
* @param mixed $listener 监听操作
* @return $this
* @return bool
*/
function remove_filter(string $event, $listener, int $sort = 1): bool
{
Expand All @@ -336,7 +348,7 @@ function remove_filter(string $event, $listener, int $sort = 1): bool
*
* @param string $event 事件名称
* @param mixed $listener 监听操作
* @return $this
* @return bool
*/
function has_filter(string $event, $listener): bool
{
Expand Down
4 changes: 2 additions & 2 deletions src/larke/resources/config/larkeadmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
'name' => "LarkeAdmin",
'name_mini' => "Larke",
'logo' => "<b>Larke</b> admin",
'release' => "20240707",
'version' => "1.9.8",
'release' => "20240708",
'version' => "1.9.9",
],

// 是否使用 https 方式
Expand Down

0 comments on commit d5804ab

Please sign in to comment.