1 | <?php |
||
19 | class Request extends \yii\console\Request |
||
20 | { |
||
21 | /** |
||
22 | * @var name of script called, like $0 in sh/perl |
||
23 | */ |
||
24 | protected $_self; |
||
25 | |||
26 | protected $_args; |
||
27 | |||
28 | /** |
||
29 | * Returns the command line arguments. |
||
30 | * |
||
31 | * @return array the command line arguments. It does not include the entry script name |
||
32 | */ |
||
33 | 5 | public function getParams() |
|
|
|||
34 | { |
||
35 | 5 | if (!isset($this->_args)) { |
|
36 | if (isset($_SERVER['argv'])) { |
||
37 | $args = $_SERVER['argv']; |
||
38 | $this->_self = array_shift($args); |
||
39 | $command = $args[0]; |
||
40 | $alias = Yii::$app->config->aliases->get($command); |
||
41 | if ($alias) { |
||
42 | array_shift($args); |
||
43 | $args = array_merge($alias, $args); |
||
44 | } |
||
45 | $this->_args = $args; |
||
46 | } else { |
||
47 | $this->_args = []; |
||
48 | } |
||
49 | $this->setParams($this->_args); |
||
50 | } |
||
51 | |||
52 | 5 | return $this->_args; |
|
53 | } |
||
54 | |||
55 | 5 | public function setParams($params) |
|
60 | } |
||
61 |
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: