123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
- /*
- |--------------------------------------------------------------------------
- | menu.php 后台管理 左侧菜单管理
- |--------------------------------------------------------------------------
- */
- namespace MazeApp\Manage;
- use Maze;
- use MazeApp\Manage\Lib\Input as Html;
- use Maze\Security\Api as Base;
- Maze::load('manage/auth.init');
- class Api
- {
- /**
- * fast
- *
- * @var array
- */
- private $fast = array();
-
- /**
- * data
- *
- * @var array
- */
- private $data = array();
-
- /**
- * 从数据库中得到所有接口,如果为空,则从项目中读取一次
- *
- * @return array
- */
- private function get($auth = '')
- {
- $data = Maze::load('manage/api-all');
-
- if($data)
- {
- foreach($data as $k => $v)
- {
-
- }
- }
- else
- {
- # 数据为空,读取一次,后续就得手动读取了
- $this->load();
-
- $data = $this->get();
- }
- return $data;
- }
-
- /**
- * 更新接口
- *
- * @return array
- */
- public function update()
- {
- $this->load();
-
- Maze::out('yes');
- }
-
- /**
- * 载入从项目中定义好的接口
- *
- * @return array
- */
- public function load()
- {
- $project = Maze::load('manage/project.get');
-
- foreach($project as $k => $v)
- {
- $data = Base::init($v['path']);
- if($data)
- {
- foreach($data as $i => $j)
- {
- $j['order'] = isset($j['order']) ? $j['order'] : 1;
- $this->updateApi($v['url'] . $i, $j['name'], $j['type'], $k, $j['request'], $j['response'], $j['order']);
- }
- }
- }
- }
-
- private function updateApi($site, $name, $type, $project, $request, $response, $reorder)
- {
- $request = Maze::table($request);
- $response = Maze::table($response);
- $info = Maze::load('manage/api-site', array('where_site' => $site));
- if(!$info)
- {
- $update['add_site'] = $site;
- $update['add_name'] = $name;
- $update['add_type'] = $type;
- $update['add_project'] = $project;
- $update['add_reorder'] = $reorder;
- $update['add_request'] = $request;
- $update['add_response'] = $response;
- $info['id'] = Maze::load('manage/api-insert', $update);
- }
- else
- {
- $update['set_interface'] = $site;
- $update['set_name'] = $name;
- $update['set_type'] = $type;
- $update['set_project'] = $project;
- $update['set_reorder'] = $reorder;
- $update['set_request'] = $request;
- $update['set_response'] = $response;
- $update['where_id'] = $info['id'];
- Maze::load('manage/api-update', $update);
- }
-
- return $info['id'];
- }
- }
|