InlineAction.php 1.21 KB
Newer Older
Qiang Xue committed
1 2
<?php
/**
Qiang Xue committed
3
 * InlineAction class file.
Qiang Xue committed
4 5
 *
 * @link http://www.yiiframework.com/
Qiang Xue committed
6
 * @copyright Copyright &copy; 2008 Yii Software LLC
Qiang Xue committed
7 8 9
 * @license http://www.yiiframework.com/license/
 */

Qiang Xue committed
10
namespace yii\base;
Qiang Xue committed
11

Qiang Xue committed
12 13
use yii\util\ReflectionHelper;

Qiang Xue committed
14
/**
Qiang Xue committed
15
 * InlineAction represents an action that is defined as a controller method.
Qiang Xue committed
16
 *
Qiang Xue committed
17 18
 * The name of the controller method should be in the format of `actionXyz`
 * where `Xyz` stands for the action ID (e.g. `actionIndex`).
Qiang Xue committed
19 20
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
Qiang Xue committed
21
 * @since 2.0
Qiang Xue committed
22
 */
Qiang Xue committed
23
class InlineAction extends Action
Qiang Xue committed
24 25
{
	/**
Qiang Xue committed
26 27 28 29
	 * Runs this action with the specified parameters.
	 * This method is mainly invoked by the controller.
	 * @param array $params action parameters
	 * @return integer the exit status (0 means normal, non-zero means abnormal).
Qiang Xue committed
30
	 */
Qiang Xue committed
31
	public function runWithParams($params)
Qiang Xue committed
32
	{
Qiang Xue committed
33 34
		try {
			$method = 'action' . $this->id;
Qiang Xue committed
35
			$ps = ReflectionHelper::extractMethodParams($this->controller, $method, $params);
Qiang Xue committed
36 37
		} catch (Exception $e) {
			$this->controller->invalidActionParams($this, $e);
Qiang Xue committed
38
			return 1;
Qiang Xue committed
39
		}
Qiang Xue committed
40 41 42 43
		if ($params !== $ps) {
			$this->controller->extraActionParams($this, $ps, $params);
		}
		return (int)call_user_func_array(array($this->controller, $method), $ps);
Qiang Xue committed
44 45
	}
}