mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
改进
This commit is contained in:
@@ -141,13 +141,13 @@ class App
|
|||||||
break;
|
break;
|
||||||
case 'controller':
|
case 'controller':
|
||||||
// 执行控制器操作
|
// 执行控制器操作
|
||||||
$vars = Request::instance()->param();
|
$vars = array_merge(Request::instance()->param(), $dispatch['var']);
|
||||||
$data = Loader::action($dispatch['controller'], array_merge($vars, $dispatch['var']), $config['url_controller_layer'], $config['controller_suffix'], true);
|
$data = Loader::action($dispatch['controller'], $vars, $config['url_controller_layer'], $config['controller_suffix']);
|
||||||
break;
|
break;
|
||||||
case 'method':
|
case 'method':
|
||||||
// 执行回调方法
|
// 执行回调方法
|
||||||
$vars = Request::instance()->param();
|
$vars = array_merge(Request::instance()->param(), $dispatch['var']);
|
||||||
$data = self::invokeMethod($dispatch['method'], array_merge($vars, $dispatch['var']));
|
$data = self::invokeMethod($dispatch['method'], $vars);
|
||||||
break;
|
break;
|
||||||
case 'function':
|
case 'function':
|
||||||
// 执行闭包
|
// 执行闭包
|
||||||
@@ -217,10 +217,9 @@ class App
|
|||||||
* @access public
|
* @access public
|
||||||
* @param string|array $method 方法
|
* @param string|array $method 方法
|
||||||
* @param array $vars 变量
|
* @param array $vars 变量
|
||||||
* @param bool $filter 是否全局过滤
|
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public static function invokeMethod($method, $vars = [], $filter = true)
|
public static function invokeMethod($method, $vars = [])
|
||||||
{
|
{
|
||||||
if (is_array($method)) {
|
if (is_array($method)) {
|
||||||
$class = is_object($method[0]) ? $method[0] : self::invokeClass($method[0]);
|
$class = is_object($method[0]) ? $method[0] : self::invokeClass($method[0]);
|
||||||
@@ -229,7 +228,7 @@ class App
|
|||||||
// 静态方法
|
// 静态方法
|
||||||
$reflect = new \ReflectionMethod($method);
|
$reflect = new \ReflectionMethod($method);
|
||||||
}
|
}
|
||||||
$args = self::bindParams($reflect, $vars, $filter);
|
$args = self::bindParams($reflect, $vars);
|
||||||
|
|
||||||
self::$debug && Log::record('[ RUN ] ' . $reflect->class . '->' . $reflect->name . '[ ' . $reflect->getFileName() . ' ]', 'info');
|
self::$debug && Log::record('[ RUN ] ' . $reflect->class . '->' . $reflect->name . '[ ' . $reflect->getFileName() . ' ]', 'info');
|
||||||
return $reflect->invokeArgs(isset($class) ? $class : null, $args);
|
return $reflect->invokeArgs(isset($class) ? $class : null, $args);
|
||||||
@@ -240,15 +239,14 @@ class App
|
|||||||
* @access public
|
* @access public
|
||||||
* @param string $class 类名
|
* @param string $class 类名
|
||||||
* @param array $vars 变量
|
* @param array $vars 变量
|
||||||
* @param bool $filter 是否全局过滤
|
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public static function invokeClass($class, $vars = [], $filter = true)
|
public static function invokeClass($class, $vars = [])
|
||||||
{
|
{
|
||||||
$reflect = new \ReflectionClass($class);
|
$reflect = new \ReflectionClass($class);
|
||||||
$constructor = $reflect->getConstructor();
|
$constructor = $reflect->getConstructor();
|
||||||
if ($constructor) {
|
if ($constructor) {
|
||||||
$args = self::bindParams($constructor, $vars, $filter);
|
$args = self::bindParams($constructor, $vars);
|
||||||
} else {
|
} else {
|
||||||
$args = [];
|
$args = [];
|
||||||
}
|
}
|
||||||
@@ -260,10 +258,9 @@ class App
|
|||||||
* @access public
|
* @access public
|
||||||
* @param \ReflectionMethod|\ReflectionFunction $reflect 反射类
|
* @param \ReflectionMethod|\ReflectionFunction $reflect 反射类
|
||||||
* @param array $vars 变量
|
* @param array $vars 变量
|
||||||
* @param bool $filter 是否全局过滤
|
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private static function bindParams($reflect, $vars = [], $filter = true)
|
private static function bindParams($reflect, $vars = [])
|
||||||
{
|
{
|
||||||
if (empty($vars)) {
|
if (empty($vars)) {
|
||||||
// 自动获取请求变量
|
// 自动获取请求变量
|
||||||
@@ -307,10 +304,6 @@ class App
|
|||||||
throw new \InvalidArgumentException('method param miss:' . $name);
|
throw new \InvalidArgumentException('method param miss:' . $name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 全局过滤
|
|
||||||
if ($filter) {
|
|
||||||
array_walk_recursive($args, [Request::instance(), 'filterExp']);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return $args;
|
return $args;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -481,10 +481,9 @@ class Loader
|
|||||||
* @param string|array $vars 调用参数 支持字符串和数组
|
* @param string|array $vars 调用参数 支持字符串和数组
|
||||||
* @param string $layer 要调用的控制层名称
|
* @param string $layer 要调用的控制层名称
|
||||||
* @param bool $appendSuffix 是否添加类名后缀
|
* @param bool $appendSuffix 是否添加类名后缀
|
||||||
* @param bool $filter 是否全局过滤
|
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public static function action($url, $vars = [], $layer = 'controller', $appendSuffix = false, $filter = false)
|
public static function action($url, $vars = [], $layer = 'controller', $appendSuffix = false)
|
||||||
{
|
{
|
||||||
$info = pathinfo($url);
|
$info = pathinfo($url);
|
||||||
$action = $info['basename'];
|
$action = $info['basename'];
|
||||||
@@ -498,7 +497,7 @@ class Loader
|
|||||||
$vars = [$vars];
|
$vars = [$vars];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return App::invokeMethod([$class, $action . Config::get('action_suffix')], $vars, $filter);
|
return App::invokeMethod([$class, $action . Config::get('action_suffix')], $vars);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user