|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
-
-
- namespace yii\base;
-
- use Yii;
-
-
- class Action extends Component
- {
-
-
- public $id;
-
-
- public $controller;
-
-
-
-
- public function __construct($id, $controller, $config = [])
- {
- $this->id = $id;
- $this->controller = $controller;
- parent::__construct($config);
- }
-
-
-
- public function getUniqueId()
- {
- return $this->controller->getUniqueId() . '/' . $this->id;
- }
-
-
-
- public function runWithParams($params)
- {
- if (!method_exists($this, 'run')) {
- throw new InvalidConfigException(get_class($this) . ' must define a "run()" method.');
- }
- $args = $this->controller->bindActionParams($this, $params);
- Yii::trace('Running action: ' . get_class($this) . '::run()', __METHOD__);
- if (Yii::$app->requestedParams === null) {
- Yii::$app->requestedParams = $args;
- }
- if ($this->beforeRun()) {
- $result = call_user_func_array([$this, 'run'], $args);
- $this->afterRun();
-
- return $result;
- } else {
- return null;
- }
- }
-
-
-
- protected function beforeRun()
- {
- return true;
- }
-
-
-
- protected function afterRun()
- {
- }
- }
|