1 | <?php |
||
18 | abstract class Controller extends \yii\console\Controller |
||
19 | { |
||
20 | use GettersTrait; |
||
21 | |||
22 | public $layout = false; |
||
23 | |||
24 | protected $_before = []; |
||
25 | protected $_after = []; |
||
26 | |||
27 | 1 | public function behaviors() |
|
28 | { |
||
29 | return [ |
||
30 | 1 | CommonBehavior::class, |
|
31 | 1 | ]; |
|
32 | } |
||
33 | |||
34 | 1 | public function setBefore($requests) |
|
38 | |||
39 | 1 | public function getBefore() |
|
43 | |||
44 | public function setAfter($requests) |
||
48 | |||
49 | public function getAfter() |
||
53 | |||
54 | public function readline($prompt) |
||
58 | |||
59 | public function readpassword($prompt) |
||
69 | |||
70 | /** |
||
71 | * Runs list of actions. |
||
72 | * @param null|string|array $actions |
||
73 | * @return int|Response exit code |
||
74 | */ |
||
75 | public function runActions($actions) |
||
76 | { |
||
77 | foreach ($this->normalizeTasks($actions) as $action => $enabled) { |
||
78 | if ($enabled) { |
||
79 | $res = $this->runAction($action); |
||
80 | if (!static::isResponseOk($res)) { |
||
81 | return $res; |
||
82 | } |
||
83 | } |
||
84 | } |
||
85 | |||
86 | return 0; |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * Is response Ok. |
||
91 | * @param Response|int $response |
||
92 | * @return bool |
||
93 | */ |
||
94 | public static function isResponseOk($response) |
||
98 | } |
||
99 |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: