Browse Source

...

tags/2.0.0-beta
Qiang Xue 13 years ago
parent
commit
769c1dee92
  1. 7
      framework/base/Action.php
  2. 11
      framework/base/Controller.php
  3. 7
      framework/base/InlineAction.php
  4. 25
      framework/console/Controller.php

7
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);
}
}

11
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.

7
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);
}
}

25
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'.

Loading…
Cancel
Save