| Total Complexity | 10 |
| Total Lines | 46 |
| Duplicated Lines | 0 % |
| Coverage | 0% |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 19 | class Command extends \hidev\base\Component |
||
| 20 | { |
||
| 21 | public $path; |
||
| 22 | public $sudo; |
||
| 23 | public $comment; |
||
| 24 | public $commands; |
||
| 25 | |||
| 26 | protected $_cwd; |
||
| 27 | |||
| 28 | public function setCommand($value) |
||
| 29 | { |
||
| 30 | $this->commands = $value; |
||
| 31 | } |
||
| 32 | |||
| 33 | public function getCommands() |
||
| 34 | { |
||
| 35 | if (!is_array($this->commands)) { |
||
| 36 | $this->commands = explode("\n", $this->commands); |
||
| 37 | } |
||
| 38 | |||
| 39 | return $this->commands; |
||
| 40 | } |
||
| 41 | |||
| 42 | public function save() |
||
| 43 | { |
||
| 44 | $this->before(); |
||
| 45 | foreach ($this->getCommands() as $command) { |
||
| 46 | $command = trim($command); |
||
| 47 | if ($command) { |
||
| 48 | passthru(($this->sudo ? 'sudo ' : '') . $command); |
||
| 49 | } |
||
| 50 | } |
||
| 51 | $this->after(); |
||
| 52 | } |
||
| 53 | |||
| 54 | public function before() |
||
| 55 | { |
||
| 56 | $this->_cwd = getcwd(); |
||
| 57 | if ($this->path) { |
||
| 58 | chdir(Yii::getAlias($this->path)); |
||
| 59 | } |
||
| 60 | } |
||
| 61 | |||
| 62 | public function after() |
||
| 65 | } |
||
| 66 | } |
||
| 67 |