* code for task#1541.
This commit is contained in:
+34
-7
@@ -48,11 +48,19 @@ class api extends control
|
||||
die($this->output);
|
||||
}
|
||||
|
||||
/**
|
||||
* The interface of api.
|
||||
*
|
||||
* @param int $filePath
|
||||
* @param int $action
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function view($filePath, $action)
|
||||
{
|
||||
if($filePath)
|
||||
{
|
||||
$host = common::getSysURL() . $this->config->webRoot;
|
||||
$host = common::getSysURL() . $this->config->webRoot;
|
||||
$filePath = helper::safe64Decode($filePath);
|
||||
if($action == 'extendModel')
|
||||
{
|
||||
@@ -66,21 +74,40 @@ class api extends control
|
||||
if(!empty($_POST))
|
||||
{
|
||||
$param = '';
|
||||
foreach($_POST as $key => $value) $param .= '&' . $key . '=' . $value;
|
||||
$param = trim($param, '&') . "&{$this->config->sessionVar}=" . session_id();
|
||||
$url = rtrim($host, '/') . $this->createLink($method->className, $method->methodName, $param, 'json');
|
||||
if($action == 'extendModel')
|
||||
{
|
||||
foreach($_POST as $key => $value) $param .= ',' . $key . '=' . $value;
|
||||
$param = ltrim($param, ',');
|
||||
$url = rtrim($host, '/') . inlink('getModel', "moduleName={$method->className}&methodName={$method->methodName}¶ms=$param", 'json');
|
||||
$url .= $this->config->requestType == "PATH_INFO" ? '?' : '&';
|
||||
$url .= $this->config->sessionVar . '=' . session_id();
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach($_POST as $key => $value) $param .= '&' . $key . '=' . $value;
|
||||
$param = ltrim($param, '&');
|
||||
$url = rtrim($host, '/') . $this->createLink($method->className, $method->methodName, $param, 'json');
|
||||
$url .= $this->config->requestType == "PATH_INFO" ? '?' : '&';
|
||||
$url .= $this->config->sessionVar . '=' . session_id();
|
||||
}
|
||||
|
||||
/* Unlock session. After new request, restart session. */
|
||||
session_write_close();
|
||||
$content = file_get_contents($url);
|
||||
session_start();
|
||||
|
||||
$result = json_decode($content);
|
||||
$status = $result->status;
|
||||
$data = json_decode($result->data);
|
||||
$data = '<xmp>' . print_r($data, true) . '</xmp>';
|
||||
|
||||
$response['result'] = 'success';
|
||||
$response['status'] = $status;
|
||||
$response['url'] = $url;
|
||||
$response['data'] = $data;
|
||||
$response['status'] = $status;
|
||||
$response['url'] = $url;
|
||||
$response['data'] = $data;
|
||||
$this->send($response);
|
||||
}
|
||||
|
||||
$this->view->method = $method;
|
||||
$this->view->filePath = $filePath;
|
||||
$this->display();
|
||||
|
||||
@@ -16,7 +16,7 @@ $lang->api->getModel = 'Super Model API';
|
||||
$lang->api->position = 'Position';
|
||||
$lang->api->startLine = "%s, line %s";
|
||||
$lang->api->desc = 'Desc';
|
||||
$lang->api->test = 'Test';
|
||||
$lang->api->debug = 'Debug';
|
||||
$lang->api->noParam = 'No params in this method';
|
||||
$lang->api->submit = 'submit';
|
||||
$lang->api->url = 'Request url';
|
||||
|
||||
@@ -16,7 +16,7 @@ $lang->api->getModel = '超级model调用接口';
|
||||
$lang->api->position = '位置';
|
||||
$lang->api->startLine = "%s,%s行";
|
||||
$lang->api->desc = '描述';
|
||||
$lang->api->test = '测试';
|
||||
$lang->api->debug = '调试';
|
||||
$lang->api->noParam = '该方法没有参数';
|
||||
$lang->api->submit = '提交';
|
||||
$lang->api->url = '请求地址';
|
||||
|
||||
@@ -21,11 +21,22 @@ class apiModel extends model
|
||||
$method = new ReflectionMethod($className . $ext, $methodName);
|
||||
$data = new stdClass();
|
||||
$data->startLine = $method->getStartLine();
|
||||
$data->endLine = $method->getEndLine();
|
||||
$data->comment = $method->getDocComment();
|
||||
$data->parameters = $method->getParameters();
|
||||
$data->className = $className;
|
||||
$data->methodName = $methodName;
|
||||
$data->fileName = $fileName;
|
||||
$data->post = false;
|
||||
|
||||
$file = file($fileName);
|
||||
for($i = $data->startLine - 1; $i <= $data->endLine; $i++)
|
||||
{
|
||||
if(strpos($file[$i], '$this->post') or strpos($file[$i], 'fixer::input') or strpos($file[$i], '$_POST'))
|
||||
{
|
||||
$data->post = true;
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<?php include '../../common/view/form.html.php';?>
|
||||
<table class='table-1'>
|
||||
<caption>
|
||||
<?php echo 'GET ' . $filePath?>
|
||||
<?php echo $method->post ? 'GET/POST ' . $filePath : 'GET ' . $filePath?>
|
||||
</caption>
|
||||
<tr>
|
||||
<td>
|
||||
@@ -18,7 +18,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<?php echo "<p class='strong'>{$lang->api->test}</p>"?>
|
||||
<?php echo "<p class='strong'>{$lang->api->debug}</p>"?>
|
||||
<?php if($method->parameters):?>
|
||||
<form method='post' id='apiForm'>
|
||||
<table>
|
||||
|
||||
Reference in New Issue
Block a user