From dbb03f678689c33586ccbccb5c0dd02ef101e36b Mon Sep 17 00:00:00 2001 From: wangyuting Date: Mon, 4 Dec 2023 16:10:31 +0800 Subject: [PATCH] * Optimize buildSearchForm function. --- module/api/control.php | 2 +- module/api/model.php | 34 ------------------------ module/api/zen.php | 60 +++++++++++++++++++++++++++++++++--------- 3 files changed, 49 insertions(+), 47 deletions(-) diff --git a/module/api/control.php b/module/api/control.php index 2005ad6a89..e4a38f050e 100755 --- a/module/api/control.php +++ b/module/api/control.php @@ -72,7 +72,7 @@ class api extends control $param = $release ? $release : $param; $queryID = $browseType == 'bySearch' ? (int)$param : 0; $actionURL = $this->createLink('api', 'index', "libID=$libID&moduleID=0&apiID=0&version=0&release=0&browseType=bySearch¶m=myQueryID"); - $this->api->buildSearchForm($lib, $queryID, $actionURL, $libs); + $this->apiZen->buildSearchForm($lib, $queryID, $actionURL, $libs); $this->view->title = $this->lang->api->pageTitle; $this->view->lib = $lib; diff --git a/module/api/model.php b/module/api/model.php index 99936fa4ff..ab09cb5aa9 100644 --- a/module/api/model.php +++ b/module/api/model.php @@ -806,40 +806,6 @@ class apiModel extends model return unserialize(preg_replace_callback('#s:(\d+):"(.*?)";#s', function($match){return 's:'.strlen($match[2]).':"'.$match[2].'";';}, file_get_contents($file))); } - /** - * Build search form. - * - * @param object $lib - * @param string $queryID - * @param string $actionURL - * @param array $libs - * @param string $type product|project - * @access public - * @return void - */ - public function buildSearchForm($lib, $queryID, $actionURL, $libs = array(), $type = '') - { - if(empty($lib)) return; - $libPairs = array('' => '', $lib->id => $lib->name); - $this->config->api->search['module'] = 'api'; - if(!empty($libs)) - { - foreach($libs as $lib) - { - if(empty($lib)) continue; - if($lib->type != 'api') continue; - $libPairs[$lib->id] = $lib->name; - } - $this->config->api->search['module'] = !empty($type) ? $type . 'apiDoc' : 'api'; - } - - $this->config->api->search['queryID'] = $queryID; - $this->config->api->search['actionURL'] = $actionURL; - $this->config->api->search['params']['lib']['values'] = $libPairs + array('all' => $this->lang->api->allLibs); - - $this->loadModel('search')->setSearchParams($this->config->api->search); - } - /** * Get api by search. * diff --git a/module/api/zen.php b/module/api/zen.php index 43051d7a78..fc42ea8dfa 100644 --- a/module/api/zen.php +++ b/module/api/zen.php @@ -118,12 +118,12 @@ class apiZen extends api * 解析请求地获得请求的详细信息。 * Get the details of the method by file path. * - * @param string $filePath - * @param string $ext - * @access public + * @param string $filePath + * @param string $ext + * @access protected * @return object */ - public function getMethod(string $filePath, string $ext = ''): object + protected function getMethod(string $filePath, string $ext = ''): object { $fileName = dirname($filePath); $className = basename(dirname(dirname($filePath))); @@ -157,13 +157,13 @@ class apiZen extends api * 对指定模块下的指定方法进行调用并返回请求结果。 * Request the api. * - * @param string $moduleName - * @param string $methodName - * @param string $action extendModel | extendControl - * @access public + * @param string $moduleName + * @param string $methodName + * @param string $action extendModel | extendControl + * @access protected * @return array */ - public function request(string $moduleName, string $methodName, string $action): array + protected function request(string $moduleName, string $methodName, string $action): array { $host = common::getSysURL(); $param = ''; @@ -204,11 +204,11 @@ class apiZen extends api * 获取接口类型数据。 * Get Type list. * - * @param int $libID - * @access public + * @param int $libID + * @access protected * @return array */ - public function getTypeList(int $libID): array + protected function getTypeList(int $libID): array { $typeList = array(); foreach($this->lang->api->paramsTypeOptions as $key => $item) @@ -225,4 +225,40 @@ class apiZen extends api return $typeList; } + + /** + * 初始化搜索表单。 + * Build search form. + * + * @param object $lib + * @param int $queryID + * @param string $actionURL + * @param array $libs + * @param string $type product|project + * @access protected + * @return void + */ + protected function buildSearchForm(object $lib, int $queryID, string $actionURL, array $libs = array(), string $type = '') + { + if(empty($lib)) return; + + $libPairs = array('' => '', $lib->id => $lib->name); + $this->config->api->search['module'] = 'api'; + if(!empty($libs)) + { + foreach($libs as $lib) + { + if(empty($lib)) continue; + if($lib->type != 'api') continue; + $libPairs[$lib->id] = $lib->name; + } + $this->config->api->search['module'] = !empty($type) ? $type . 'apiDoc' : 'api'; + } + + $this->config->api->search['queryID'] = $queryID; + $this->config->api->search['actionURL'] = $actionURL; + $this->config->api->search['params']['lib']['values'] = $libPairs + array('all' => $this->lang->api->allLibs); + + $this->loadModel('search')->setSearchParams($this->config->api->search); + } }