From 58ca27a473c39349e78ba5fc5a213bdbf22f496a Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Thu, 23 May 2013 09:49:01 -0400 Subject: [PATCH] Refactored console Request. --- framework/yii/console/Request.php | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/framework/yii/console/Request.php b/framework/yii/console/Request.php index d1a6aa6..a9a4b03 100644 --- a/framework/yii/console/Request.php +++ b/framework/yii/console/Request.php @@ -15,9 +15,32 @@ class Request extends \yii\base\Request { 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 */ public function resolve() { - $rawParams = $this->getRawParams(); - array_shift($rawParams); // the 1st argument is the yii script name - + $rawParams = $this->getParams(); if (isset($rawParams[0])) { $route = $rawParams[0]; array_shift($rawParams);