Commit 58ca27a4 by Qiang Xue

Refactored console Request.

parent ef192eb4
...@@ -15,9 +15,32 @@ class Request extends \yii\base\Request ...@@ -15,9 +15,32 @@ class Request extends \yii\base\Request
{ {
const ANONYMOUS_PARAMS = '-args'; const ANONYMOUS_PARAMS = '-args';
public function getRawParams() private $_params;
/**
* Returns the command line arguments.
* @return array the command line arguments. It does not include the entry script name.
*/
public function getParams()
{
if (!isset($this->_params)) {
if (isset($_SERVER['argv'])) {
$this->_params = $_SERVER['argv'];
array_shift($this->_params);
} else {
$this->_params = array();
}
}
return $this->_params;
}
/**
* Sets the command line arguments.
* @param array $params the command line arguments
*/
public function setParams($params)
{ {
return isset($_SERVER['argv']) ? $_SERVER['argv'] : array(); $this->_params = $params;
} }
/** /**
...@@ -26,9 +49,7 @@ class Request extends \yii\base\Request ...@@ -26,9 +49,7 @@ class Request extends \yii\base\Request
*/ */
public function resolve() public function resolve()
{ {
$rawParams = $this->getRawParams(); $rawParams = $this->getParams();
array_shift($rawParams); // the 1st argument is the yii script name
if (isset($rawParams[0])) { if (isset($rawParams[0])) {
$route = $rawParams[0]; $route = $rawParams[0];
array_shift($rawParams); array_shift($rawParams);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment