|
@@ -8,6 +8,10 @@ class Dispatcher
|
|
{
|
|
{
|
|
public $request;
|
|
public $request;
|
|
|
|
|
|
|
|
+ public $controllerCls = null;
|
|
|
|
+
|
|
|
|
+ public $actionCls = null;
|
|
|
|
+
|
|
public function __construct()
|
|
public function __construct()
|
|
{
|
|
{
|
|
|
|
|
|
@@ -41,36 +45,36 @@ class Dispatcher
|
|
}
|
|
}
|
|
array_unshift($funcArgs, $controllerName);
|
|
array_unshift($funcArgs, $controllerName);
|
|
$psr4 = \Qii\Autoloader\Psr4::getInstance();
|
|
$psr4 = \Qii\Autoloader\Psr4::getInstance();
|
|
- $controllerCls = call_user_func_array(array($psr4, 'loadClass'), $funcArgs);
|
|
|
|
- $controllerCls->setRequest($this->request);
|
|
|
|
- $controllerCls->controller = $controllerCls;
|
|
|
|
- $controllerCls->controllerId = $controller;
|
|
|
|
- $controllerCls->actionId = $action;
|
|
|
|
|
|
+ $this->controllerCls = call_user_func_array(array($psr4, 'loadClass'), $funcArgs);
|
|
|
|
+ $this->controllerCls->setRequest($this->request);
|
|
|
|
+ $this->controllerCls->controller = $this->controllerCls;
|
|
|
|
+ $this->controllerCls->controllerId = $controller;
|
|
|
|
+ $this->controllerCls->actionId = $action;
|
|
$response = null;
|
|
$response = null;
|
|
//查看是否设置了当前action的对应关系,如果设置了就走对应关系里边的,否则走当前类中的
|
|
//查看是否设置了当前action的对应关系,如果设置了就走对应关系里边的,否则走当前类中的
|
|
- if ($controllerCls->actions && isset($controllerCls->actions[$action]) && $controllerCls->actions[$action]) {
|
|
|
|
|
|
+ if ($this->controllerCls->actions && isset($this->controllerCls->actions[$action]) && $this->controllerCls->actions[$action]) {
|
|
$actionArgs = array();
|
|
$actionArgs = array();
|
|
- $actionArgs[] = $controllerCls->actions[$action];
|
|
|
|
- $actionCls = call_user_func_array(array($psr4, 'loadClass'), $actionArgs);
|
|
|
|
- $actionCls->setRequest($this->request);
|
|
|
|
- $actionCls->controller = $controllerCls;
|
|
|
|
- $actionCls->actionId = $action;
|
|
|
|
- $actionCls->controllerId = $controllerCls->controllerId;
|
|
|
|
|
|
+ $actionArgs[] = $this->controllerCls->actions[$action];
|
|
|
|
+ $this->actionCls = call_user_func_array(array($psr4, 'loadClass'), $actionArgs);
|
|
|
|
+ $this->actionCls->setRequest($this->request);
|
|
|
|
+ $this->actionCls->controller = $this->controllerCls;
|
|
|
|
+ $this->actionCls->actionId = $action;
|
|
|
|
+ $this->actionCls->controllerId = $this->controllerCls->controllerId;
|
|
//支持多个action对应到同一个文件,如果对应的文件中存在指定的方法就直接调用
|
|
//支持多个action对应到同一个文件,如果对应的文件中存在指定的方法就直接调用
|
|
- if (method_exists($actionCls, $action . Register::get(Consts::APP_DEFAULT_ACTION_SUFFIX))) {
|
|
|
|
- $actionCls->response = $response = call_user_func_array(array($actionCls, $action. Register::get(Consts::APP_DEFAULT_ACTION_SUFFIX)), $funcArgs);
|
|
|
|
|
|
+ if (method_exists($this->actionCls, $action . Register::get(Consts::APP_DEFAULT_ACTION_SUFFIX))) {
|
|
|
|
+ $this->actionCls->response = $response = call_user_func_array(array($this->actionCls, $action. Register::get(Consts::APP_DEFAULT_ACTION_SUFFIX)), $funcArgs);
|
|
}
|
|
}
|
|
- if (!method_exists($actionCls, 'run')) {
|
|
|
|
- throw new \Qii\Exceptions\MethodNotFound(\Qii::i(1101, $controllerCls->actions[$action] . '->run'), __LINE__);
|
|
|
|
|
|
+ if (!method_exists($this->actionCls, 'run')) {
|
|
|
|
+ throw new \Qii\Exceptions\MethodNotFound(\Qii::i(1101, $this->controllerCls->actions[$action] . '->run'), __LINE__);
|
|
}
|
|
}
|
|
- $response = call_user_func_array(array($actionCls, 'run'), $funcArgs);
|
|
|
|
|
|
+ $response = call_user_func_array(array($this->actionCls, 'run'), $funcArgs);
|
|
} else {
|
|
} else {
|
|
array_shift($funcArgs);
|
|
array_shift($funcArgs);
|
|
$actionName = $action . Register::get(Consts::APP_DEFAULT_ACTION_SUFFIX);
|
|
$actionName = $action . Register::get(Consts::APP_DEFAULT_ACTION_SUFFIX);
|
|
- if (!method_exists($controllerCls, $actionName) && !method_exists($controllerCls, '__call')) {
|
|
|
|
|
|
+ if (!method_exists($this->controllerCls, $actionName) && !method_exists($this->controllerCls, '__call')) {
|
|
throw new \Qii\Exceptions\MethodNotFound(\Qii::i(1101, $controller . '->' . $actionName), __LINE__);
|
|
throw new \Qii\Exceptions\MethodNotFound(\Qii::i(1101, $controller . '->' . $actionName), __LINE__);
|
|
}
|
|
}
|
|
- $controllerCls->response = $response = call_user_func_array(array($controllerCls, $actionName), $funcArgs);
|
|
|
|
|
|
+ $this->controllerCls->response = $response = call_user_func_array(array($this->controllerCls, $actionName), $funcArgs);
|
|
}
|
|
}
|
|
return $response;
|
|
return $response;
|
|
}
|
|
}
|