优化扩展功能

This commit is contained in:
2020-04-04 21:53:38 +08:00
parent 98419ca360
commit a8619c61fb
11 changed files with 214 additions and 28 deletions

View File

@@ -17,6 +17,11 @@ use app\model\Hooks;
*/
class Addons extends Base {
public function initialize() {
parent::initialize();
$this->getAddonsMenu();
}
/**
* @title 插件列表
*/

View File

@@ -11,6 +11,7 @@ namespace app\controller\admin;
use app\model\Menu;
use app\model\Model;
use app\model\AuthGroup;
use app\model\Addons;
use think\facade\View;
use \app\model\Form;
use \app\controller\Base as BaseC;
@@ -217,25 +218,22 @@ class Base extends BaseC {
}
protected function getAddonsMenu() {
$model = db('Addons');
$list = array();
$map = array(
'isinstall' => array('gt', 0),
'status' => array('gt', 0),
);
$list = $model->field("name,id,title,'' as 'style'")->where($map)->select();
$map[] = ['isinstall', '>', 0];
$map[] = ['status', '>', 0];
$list = Addons::where($map)->field("name,id,title,'' as 'style'")->select();
$menu = array();
foreach ($list as $key => $value) {
$class = "\\addons\\" . strtolower($value['name']) . "\\controller\\Admin";
if (is_file(ROOT_PATH . '/addons/' . strtolower($value['name']) . "/controller/Admin.php")) {
if (is_file($this->app->getRootPath() . '/addons/' . strtolower($value['name']) . "/controller/Admin.php")) {
$action = get_class_methods($class);
$value['url'] = "admin/addons/execute?mc=" . strtolower($value['name']) . "&ac=" . $action[0];
$value['url'] = "/addons/".$value['name']."/admin/" . $action[0];
$menu[$key] = $value;
}
}
if (!empty($menu)) {
$this->assign('extend_menu', array('管理插件' => $menu));
View::assign('extend_menu', array('管理插件' => $menu));
}
}

View File

@@ -101,4 +101,63 @@ class Client extends Base {
return $this->error('删除失败!');
}
}
public function api(){
$list = [];
$path = app()->getAppPath() . 'controller/api';
$classname = $this->scanFile($path);
foreach ($classname as $value) {
if($value == 'Base'){
continue;
}
$class = "app\\controller\\api\\" . $value;
if (class_exists($class)) {
$reflection = new \ReflectionClass($class);
$group_doc = $this->Parser($reflection->getDocComment());
$method = $reflection->getMethods(\ReflectionMethod::IS_FINAL | \ReflectionMethod::IS_PUBLIC);
$group_doc['name'] = $value;
foreach ($method as $key => $v) {
if (!in_array($v->name, ['__construct'])) {
$title_doc = $this->Parser($v->getDocComment());
if (isset($title_doc['title']) && $title_doc['title']) {
$list[] = array(
'url' => 'api/' . strtolower($value) . '/' . strtolower($v->name),
'name' => 'api/' . strtolower($value) . '/' . strtolower($v->name),
'method' => isset($title_doc['method']) ? strtoupper($title_doc['method']) : 'GET',
'title' => trim($title_doc['title']),
'group' => $group_doc['title'],
'status' => 1,
);
}
}
}
}
}
$this->data = [
'list' => $list
];
return $this->fetch();
}
protected function scanFile($path) {
$result = array();
$files = scandir($path);
foreach ($files as $file) {
if ($file != '.' && $file != '..') {
if (is_dir($path . '/' . $file)) {
$this->scanFile($path . '/' . $file);
} else {
$result[] = substr(basename($file), 0, -4);
}
}
}
return $result;
}
protected function Parser($text) {
$doc = new \doc\Doc();
return $doc->parse($text);
}
}

View File

@@ -0,0 +1,63 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\api;
use app\model\Category;
/**
* @title 内容管理
*/
class Content extends Base {
/**
* @title 内容列表
* @method GET
* @param Category $category [description]
* @return [json]
*/
public function lists(Category $category){
}
/**
* @title 内容详情
* @method GET
* @return [json]
*/
public function detail(){
}
/**
* @title 添加内容
* @method POST
* @return [json]
*/
public function add(){
}
/**
* @title 修改内容
* @method POST
* @return [json]
*/
public function edit(){
}
/**
* @title 删除内容
* @method POST
* @return [json]
*/
public function delete(){
}
}