mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 07:12:47 +08:00
改进Rest控制器
This commit is contained in:
@@ -338,8 +338,7 @@ class App
|
|||||||
// 操作不存在
|
// 操作不存在
|
||||||
if (method_exists($instance, '_empty')) {
|
if (method_exists($instance, '_empty')) {
|
||||||
$reflect = new \ReflectionMethod($instance, '_empty');
|
$reflect = new \ReflectionMethod($instance, '_empty');
|
||||||
$args = self::bindParams($reflect, Request::instance()->param());
|
$data = $reflect->invokeArgs($instance, [$action]);
|
||||||
$data = $reflect->invokeArgs($instance, [$action, $args]);
|
|
||||||
self::$debug && Log::record('[ RUN ] ' . $reflect->__toString(), 'info');
|
self::$debug && Log::record('[ RUN ] ' . $reflect->__toString(), 'info');
|
||||||
} else {
|
} else {
|
||||||
throw new HttpException(404, 'method not exists:' . (new \ReflectionClass($instance))->getName() . '->' . $action);
|
throw new HttpException(404, 'method not exists:' . (new \ReflectionClass($instance))->getName() . '->' . $action);
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace think\controller;
|
namespace think\controller;
|
||||||
|
|
||||||
|
use think\App;
|
||||||
use think\Request;
|
use think\Request;
|
||||||
use think\Response;
|
use think\Response;
|
||||||
|
|
||||||
@@ -61,11 +62,10 @@ abstract class Rest
|
|||||||
* REST 调用
|
* REST 调用
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $method 方法名
|
* @param string $method 方法名
|
||||||
* @param array $args 参数
|
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function _empty($method, $args)
|
public function _empty($method)
|
||||||
{
|
{
|
||||||
if (method_exists($this, $method . '_' . $this->method . '_' . $this->type)) {
|
if (method_exists($this, $method . '_' . $this->method . '_' . $this->type)) {
|
||||||
// RESTFul方法支持
|
// RESTFul方法支持
|
||||||
@@ -76,7 +76,7 @@ abstract class Rest
|
|||||||
$fun = $method . '_' . $this->method;
|
$fun = $method . '_' . $this->method;
|
||||||
}
|
}
|
||||||
if (isset($fun)) {
|
if (isset($fun)) {
|
||||||
return call_user_func_array([$this, $fun], $args);
|
return App::invokeMethod([$this, $fun]);
|
||||||
} else {
|
} else {
|
||||||
// 抛出异常
|
// 抛出异常
|
||||||
throw new \Exception('error action :' . $method);
|
throw new \Exception('error action :' . $method);
|
||||||
|
|||||||
Reference in New Issue
Block a user