Extracted inline action object creation, implemented it in console controller in order to use console inline action instead of base one

This commit is contained in:
Alexander Makarov
2014-09-04 01:26:42 +04:00
parent c43b7ee8b5
commit d74e89a1ca
2 changed files with 22 additions and 2 deletions

View File

@@ -220,7 +220,7 @@ class Controller extends Component implements ViewContextInterface
if (method_exists($this, $methodName)) {
$method = new \ReflectionMethod($this, $methodName);
if ($method->isPublic() && $method->getName() === $methodName) {
return new InlineAction($id, $this, $methodName);
return $this->createActionObject($id, $methodName);
}
}
}
@@ -228,6 +228,18 @@ class Controller extends Component implements ViewContextInterface
return null;
}
/**
* Creates action object instance
*
* @param string $id the ID of this action
* @param string $methodName the controller method that action is associated with
* @return \yii\base\InlineAction
*/
protected function createActionObject($id, $methodName)
{
return new InlineAction($id, $this, $methodName);
}
/**
* This method is invoked right before an action is executed.
*

View File

@@ -9,7 +9,6 @@ namespace yii\console;
use Yii;
use yii\base\Action;
use yii\base\InlineAction;
use yii\base\InvalidRouteException;
use yii\helpers\Console;
@@ -60,6 +59,15 @@ class Controller extends \yii\base\Controller
return $this->color === null ? Console::streamSupportsAnsiColors($stream) : $this->color;
}
/**
* @inheritdoc
* @return \yii\console\InlineAction
*/
protected function createActionObject($id, $methodName)
{
return new InlineAction($id, $this, $methodName);
}
/**
* Runs an action with the specified action ID and parameters.
* If the action ID is empty, the method will use [[defaultAction]].