| 1 | <?php |
||
| 20 | class Request extends \yii\console\Request |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @var name of script called, like $0 in sh/perl |
||
| 24 | */ |
||
| 25 | protected $_self; |
||
| 26 | |||
| 27 | protected $_args; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Returns the command line arguments. |
||
| 31 | * |
||
| 32 | * @return array the command line arguments. It does not include the entry script name. |
||
| 33 | */ |
||
| 34 | 5 | public function getParams() |
|
|
|
|||
| 35 | { |
||
| 36 | 5 | if (!isset($this->_args)) { |
|
| 37 | if (isset($_SERVER['argv'])) { |
||
| 38 | $args = $_SERVER['argv']; |
||
| 39 | $this->_self = array_shift($args); |
||
| 40 | $command = $args[0]; |
||
| 41 | $alias = Yii::$app->config->aliases->get($command); |
||
| 42 | if ($alias) { |
||
| 43 | array_shift($args); |
||
| 44 | $args = array_merge($alias, $args); |
||
| 45 | } |
||
| 46 | $this->_args = $args; |
||
| 47 | } else { |
||
| 48 | $this->_args = []; |
||
| 49 | } |
||
| 50 | $this->setParams($this->_args); |
||
| 51 | } |
||
| 52 | |||
| 53 | 5 | return $this->_args; |
|
| 54 | } |
||
| 55 | |||
| 56 | 5 | public function setParams($params) |
|
| 61 | } |
||
| 62 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: