diff --git a/framework/base/Action.php b/framework/base/Action.php index a87d519..8830033 100644 --- a/framework/base/Action.php +++ b/framework/base/Action.php @@ -55,11 +55,14 @@ class Action extends Component public function runWithParams($params) { try { - $params = ReflectionHelper::extractMethodParams($this, 'run', $params); - return (int)call_user_func_array(array($this, 'run'), $params); + $ps = ReflectionHelper::extractMethodParams($this, 'run', $params); } catch (Exception $e) { $this->controller->invalidActionParams($this, $e); return 1; } + if ($params !== $ps) { + $this->controller->extraActionParams($this, $ps, $params); + } + return (int)call_user_func_array(array($this, 'run'), $ps); } } diff --git a/framework/base/Controller.php b/framework/base/Controller.php index f78cfa9..e3df100 100644 --- a/framework/base/Controller.php +++ b/framework/base/Controller.php @@ -175,6 +175,17 @@ class Controller extends Component implements Initable } /** + * This method is invoked when extra parameters are provided to an action when it is executed. + * The default implementation does nothing. + * @param Action $action the action being executed + * @param array $expected the expected action parameters (name => value) + * @param array $actual the actual action parameters (name => value) + */ + public function extraActionParams($action, $expected, $actual) + { + } + + /** * Handles the request whose action is not recognized. * This method is invoked when the controller cannot find the requested action. * The default implementation simply throws an exception. diff --git a/framework/base/InlineAction.php b/framework/base/InlineAction.php index 2bd5582..eb98f96 100644 --- a/framework/base/InlineAction.php +++ b/framework/base/InlineAction.php @@ -32,11 +32,14 @@ class InlineAction extends Action { try { $method = 'action' . $this->id; - $params = ReflectionHelper::extractMethodParams($this->controller, $method, $params); - return (int)call_user_func_array(array($this->controller, $method), $params); + $ps = ReflectionHelper::extractMethodParams($this->controller, $method, $params); } catch (Exception $e) { $this->controller->invalidActionParams($this, $e); return 1; } + if ($params !== $ps) { + $this->controller->extraActionParams($this, $ps, $params); + } + return (int)call_user_func_array(array($this->controller, $method), $ps); } } diff --git a/framework/console/Controller.php b/framework/console/Controller.php index 1cca900..b1d949a 100644 --- a/framework/console/Controller.php +++ b/framework/console/Controller.php @@ -9,9 +9,8 @@ namespace yii\console; -use yii\base\InlineAction; +use yii\base\Action; use yii\base\Exception; -use yii\util\ReflectionHelper; /** * Command represents an executable console command. @@ -51,6 +50,28 @@ use yii\util\ReflectionHelper; class Controller extends \yii\base\Controller { /** + * This method is invoked when the request parameters do not satisfy the requirement of the specified action. + * The default implementation will throw an exception. + * @param Action $action the action being executed + * @param Exception $exception the exception about the invalid parameters + * @throws Exception whenever this method is invoked + */ + public function invalidActionParams($action, $exception) + { + } + + /** + * This method is invoked when extra parameters are provided to an action when it is executed. + * The default implementation does nothing. + * @param Action $action the action being executed + * @param array $expected the expected action parameters (name => value) + * @param array $actual the actual action parameters (name => value) + */ + public function extraActionParams($action, $expected, $actual) + { + } + + /** * Provides the command description. * This method may be overridden to return the actual command description. * @return string the command description. Defaults to 'Usage: php entry-script.php command-name'.