124 lines
2.7 KiB
PHP
124 lines
2.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
// +----------------------------------------------------------------------
|
|
// | swiftAdmin 极速开发框架 [基于WebMan开发]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2020-2030 http://www.swiftadmin.net
|
|
// +----------------------------------------------------------------------
|
|
// | swiftAdmin.NET High Speed Development Framework
|
|
// +----------------------------------------------------------------------
|
|
// | Author: meystack <coolsec@foxmail.com> Apache 2.0 License
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app;
|
|
|
|
use app\common\library\ResultCode;
|
|
use think\App;
|
|
use think\helper\Str;
|
|
use think\Validate;
|
|
use think\Response;
|
|
use think\exception\HttpResponseException;
|
|
|
|
|
|
/**
|
|
* 插件控制器基类
|
|
* Class PluginController
|
|
* @package app
|
|
* @author meystack <
|
|
*/
|
|
abstract class PluginController
|
|
{
|
|
|
|
/**
|
|
* Request实例
|
|
* @var \think\Request
|
|
*/
|
|
protected mixed $request;
|
|
|
|
/**
|
|
* 应用实例
|
|
* @var mixed
|
|
*/
|
|
protected mixed $app;
|
|
|
|
/**
|
|
* 获取访问来源
|
|
* @var mixed
|
|
*/
|
|
public mixed $referer;
|
|
|
|
|
|
/**
|
|
* 视图实例对象
|
|
* @var mixed
|
|
*/
|
|
public mixed $view;
|
|
|
|
/**
|
|
* 构造方法
|
|
*/
|
|
public function __construct() //App $app
|
|
{
|
|
// $this->app = $app;
|
|
// $this->request = $this->app->request;
|
|
// $this->referer = $this->request->header('referer');
|
|
|
|
// 控制器初始化
|
|
$this->initialize();
|
|
}
|
|
|
|
/**
|
|
* 初始化
|
|
*/
|
|
protected function initialize()
|
|
{
|
|
// 获取站点配置
|
|
// $configList = saenv('site', true);
|
|
// if ($configList && is_array($configList)) {
|
|
// foreach ($configList as $key => $value) {
|
|
// $this->app->view->assign($key,$value);
|
|
// }
|
|
// }
|
|
}
|
|
|
|
|
|
/**
|
|
* 获取当前插件名
|
|
* @return string
|
|
*/
|
|
final public function getPluginName(): string
|
|
{
|
|
$data = explode('\\', get_class($this));
|
|
return strtolower(array_pop($data));
|
|
}
|
|
|
|
/**
|
|
* 抛出404异常
|
|
* @access public retResponseError
|
|
*/
|
|
public function retResponseError(string $msg = 'not found!', int $code = 404)
|
|
{
|
|
if(request()->isAjax()) {
|
|
return json(ResultCode::AUTH_ERROR);
|
|
}
|
|
else {
|
|
abort($code,$msg);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 空方法
|
|
*/
|
|
public function __call($method, $args)
|
|
{
|
|
$this->retResponseError();
|
|
}
|
|
|
|
|
|
// 必须实现以下方法
|
|
abstract public function install();
|
|
abstract public function uninstall();
|
|
abstract public function enabled();
|
|
abstract public function disabled();
|
|
} |